Package org.apache.commons.digester

Examples of org.apache.commons.digester.Digester


    public void testInstanceOverride() throws Exception {
        // Tests that using setPluginXXXX overrides behaviour for only
        // that particular PluginCreateRule instance. Also tests that
        // attributes can be in namespaces.

        Digester digester = new Digester();
        digester.setNamespaceAware(true);
        PluginRules rc = new PluginRules();
        digester.setRules(rc);

        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);

        // for plugins at pattern "root/widget", use xml attributes "id" and
        // "class" in the custom namespace as the values for plugin id and
        // class, not the default (and non-namespaced) values of
        // "plugin-id" and "plugin-class".
        PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class);
        widgetPluginRule.setPluginIdAttribute(
            "http://jakarta.apache.org/digester/plugins", "id");
        widgetPluginRule.setPluginClassAttribute(
            "http://jakarta.apache.org/digester/plugins", "class");
        digester.addRule("root/widget", widgetPluginRule);
        digester.addSetNext("root/widget", "addWidget");

        PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class);
        digester.addRule("root/gadget", gadgetPluginRule);
        digester.addSetNext("root/gadget", "addGadget");

        MultiContainer root = new MultiContainer();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test7.xml"));
        } catch(Exception e) {
            throw e;
        }
View Full Code Here


    public void testRuleInfoExplicitClass() throws Exception {
        // * tests that custom rules can be declared on a
        //   separate class by explicitly declaring the rule class.

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test5a.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

    public void testRuleInfoExplicitMethod() throws Exception {
        // * tests that custom rules can be declared on a
        //   separate class by explicitly declaring the rule class.
        //   and explicitly declaring the rule method name.

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test5b.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

    public void testRuleInfoAutoDetect() throws Exception {
        // * tests that custom rules can be declared on a
        //   separate class with name {plugin-class}RuleInfo,
        //   and they are automatically detected and loaded.

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test5c.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

    public void ignoretestDelegate() throws Exception {
        // this method tests the Delegate functionality by capturing all
        // data below the specified pattern, and printing it to stdout.
        // I can't for the moment think how to turn this into a unit test,
        // so this test is disabled.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        DumperRule dr = new DumperRule();
        digester.addRule("root", dr);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test1.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

        input.append("  file='src/test/org/apache/commons/digester/plugins/xmlrules1.xml'");
        input.append("  />");
        input.append("  <object plugin-id='testobject'/>");
        input.append("</root>");

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(TestObject.class);
        digester.addRule("root/object", pcr);
       
        try {
            digester.parse(new StringReader(input.toString()));
        }
        catch(Exception e) {
            throw e;
        }

        Object root = digester.getRoot();
        assertEquals(TestObject.class, root.getClass());
        TestObject testObject = (TestObject) root;
        assertEquals("xmlrules1", testObject.getValue());
    }
View Full Code Here

        input.append("  resource='org/apache/commons/digester/plugins/xmlrules2.xml'");
        input.append("  />");
        input.append("  <object plugin-id='testobject'/>");
        input.append("</root>");

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(TestObject.class);
        digester.addRule("root/object", pcr);

        try {
            digester.parse(new StringReader(input.toString()));
        }
        catch(Exception e) {
            throw e;
        }

        Object root = digester.getRoot();
        assertEquals(TestObject.class, root.getClass());
        TestObject testObject = (TestObject) root;
        assertEquals("xmlrules2", testObject.getValue());
    }
View Full Code Here

        input.append("  class='org.apache.commons.digester.plugins.TestObject'");
        input.append("  />");
        input.append("  <object plugin-id='testobject'/>");
        input.append("</root>");

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(TestObject.class);
        digester.addRule("root/object", pcr);

        try {
            digester.parse(new StringReader(input.toString()));
        }
        catch(Exception e) {
            throw e;
        }

        Object root = digester.getRoot();
        assertEquals(TestObject.class, root.getClass());
        TestObject testObject = (TestObject) root;
        assertEquals("xmlrules-ruleinfo", testObject.getValue());
    }
View Full Code Here

    // --------------------------------------------------------------- Test cases
   
    public void testPredeclaration() throws Exception {
        // * tests that rules can be declared via a PluginDeclarationRule

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test3.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

        // * tests that plugins can be specified by class, and that the
        //   correct class gets loaded.
        // * tests that autosetproperties works
        // * tests that multiple different classes can be loaded via the
        //   same plugin rule (ie at the same pattern).
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test1.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Digester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.