Package org.apache.commons.digester

Examples of org.apache.commons.digester.Digester


                + "</digester-rules>";
               
        String xml = "<?xml version='1.0' ?><root><foo><bar>short</bar></foo></root>";
       
        ArrayList list = new ArrayList();
        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml)));
        digester.push(list);
        digester.parse(new StringReader(xml));       
                                                                       
        assertEquals("Number of entries", 1, list.size());
        assertEquals("Entry value", "short", list.get(0));
    }
View Full Code Here


        {
        TestObject testObject = new TestObject();
        FromXmlRuleSet ruleset =
            new FromXmlRuleSet(
                new InputSource(new StringReader(xmlRules)));
        Digester digester = new Digester();
        ruleset.addRuleInstances(digester);
       
        digester.push(testObject);   
        digester.parse(new InputSource(new StringReader(xml)));
       
        assertEquals("", testObject.getProperty());
        }
       
        // Now try with a base path. The rule should now match.
        {
        TestObject testObject = new TestObject();
        FromXmlRuleSet ruleset =
            new FromXmlRuleSet(
                new InputSource(new StringReader(xmlRules)));
        Digester digester = new Digester();
        ruleset.addRuleInstances(digester, "root");

        digester.push(testObject);   
        digester.parse(new InputSource(new StringReader(xml)));
       
        assertEquals("success", testObject.getProperty());
        }
    }
View Full Code Here

            "    <rab/>" +
            "  </foo>" +
            "</root>";
           
        CallParamTestObject testObject = new CallParamTestObject();
        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules)));
        digester.push(testObject);   
        digester.parse(new InputSource(new StringReader(xml)));
        assertEquals("First param", "", testObject.getLeft());
        assertEquals("Param with default set", "tester.test", testObject.getRight());
    }
View Full Code Here

            "</root>";
           
        CallParamTestObject testObjectA = new CallParamTestObject();
        CallParamTestObject testObjectB = new CallParamTestObject();
        CallParamTestObject testObjectC = new CallParamTestObject();
        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules)));
        digester.push( testObjectA );
        digester.push( testObjectB );
        digester.push( testObjectC );
        digester.parse(new InputSource(new StringReader(xml)));
       
        assertEquals("Top object invoked", "DataForTheTopObject", testObjectC.getMiddle());
        assertEquals("Parent object invoked", "DataForTheParentObject", testObjectB.getLeft());
        assertEquals("Root object invoked", "DataForTheRootObject", testObjectA.getRight());
View Full Code Here

    public void testCreateDigester() throws Exception {
        URL rules = ClassLoader.getSystemResource("org/apache/commons/digester/xmlrules/testrules.xml");
        URL input = ClassLoader.getSystemResource("org/apache/commons/digester/xmlrules/test.xml");
        assertNotNull("The test could not locate testrules.xml", rules);
        assertNotNull("The test could not locate test.xml", input);
        Digester digester = DigesterLoader.createDigester(rules);
        digester.push(new ArrayList());
        Object root = digester.parse(input.openStream());
        assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]");
        //System.out.println(root);
    }
View Full Code Here

     * Validates that circular includes are detected and result in an exception
     */
    public void testCircularInclude1() {
        URL rules = ClassLoader.getSystemResource("org/apache/commons/digester/xmlrules/testCircularRules.xml");
        try {
            Digester digester = DigesterLoader.createDigester(rules);
        } catch (Exception ex) {
            return;
        }
        fail("Creating a digester with circular rules should have thrown CircularIncludeException.");
    }
View Full Code Here

    // --------------------------------------------------------------- Test cases
   
    public void testLocalRules() throws Exception {
        // * tests that the plugin class can define an addRules method,
        //   which gets detected and executed.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr2 = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr2);
        digester.addSetNext("root/widget", "addChild");

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

        //   be used)
        // * tests that if a rule method is defined, then a SetProperties
        //   rule is not automatically added.
        // * tests that a SetProperties rule applying to one class doesn't
        //   apply to different plugin classes mounted at the same rule.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule("root/plugin", pdr);
       
        PluginCreateRule pcr2 = new PluginCreateRule(Widget.class);
        digester.addRule("root/widget", pcr2);
        digester.addSetNext("root/widget", "addChild");

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

   
    public void testDefaultPlugins1() throws Exception {
        // * tests that when a PluginCreateRule is defined with a default
        //   class, that the default class is instantiated when no class
        //   or id is specified in the xml file.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class, TextLabel.class);
        digester.addRule("root/widget", pcr);
        digester.addSetNext("root/widget", "addChild");

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

    }

    public void testDefaultPlugins2() throws Exception {
        // * tests that when there is no default plugin, it is an error
        //   not to have one of plugin-class or plugin-id specified
        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);
       
        Exception exception = null;
        Log oldLog = digester.getLogger();
        try {
            digester.setLogger(new NoOpLog());
            digester.parse(
                TestAll.getInputStream(this, "test2.xml"));
        }
        catch(Exception e) {
            exception = e;
        }
        finally {
            digester.setLogger(oldLog);
        }
       
        assertTrue(exception != null);
        assertEquals(SAXParseException.class, exception.getClass());
        assertEquals(
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.