Package org.apache.commons.digester3

Examples of org.apache.commons.digester3.Digester


    {
        // 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( Utils.getInputStream( this, "test1.xml" ) );
        }
        catch ( Exception e )
        {
            throw e;
        }
View Full Code Here


     */
    @Before
    public void setUp()
    {

        digester = new Digester();
        digester.setRules( createMatchingRulesForTest() );

    }
View Full Code Here

            "<?xml version='1.0'?>\n" + "<box id='root'>\n" + "  <subBox id='box1'/>\n" + "  <ignoreme/>\n"
                + "  <subBox id='box2'/> <subBox id='box3'/>\n" + "</box>";

        LocationTracker locnTracker = new LocationTracker();

        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
                forPattern( "box" ).createObject().ofType( Box.class )
                    .then()
                    .setProperties();
                forPattern( "box/subBox" ).createObject().ofType( Box.class )
                    .then()
                    .setProperties()
                    .then()
                    .setNext( "addChild" );
            }

        })
        .setStackAction( locnTracker )
        .newDigester();

        Box root = digester.parse( new StringReader( TEST_XML ) );
        assertNotNull( root );
        List<Box> children = root.getChildren();
        assertEquals( 3, children.size() );
        Box box1 = children.get( 0 );
        Box box2 = children.get( 1 );
View Full Code Here

    @Test
    public void testDigesterResolveRelative()
        throws Exception
    {
        Digester digester = new Digester();
        digester.setValidating( true );
        digester.parse( new File( "src/test/resources/org/apache/commons/digester3/document-with-relative-dtd.xml" ) );
    }
View Full Code Here

        // now for the tests
        String xml = "<?xml version='1.0' ?><root><element/></root>";

        // test default - which is to propagate the exception
        Digester digester = new Digester();
        digester.addFactoryCreate( "root", new ThrowExceptionCreateRule(), ignoreCreateExceptions );
        try
        {

            digester.parse( new StringReader( xml ) );
            if ( !ignoreCreateExceptions )
            {
                fail( "Exception should be propagated from create rule" );
            }
View Full Code Here

    public void testFactoryCreateRule()
        throws Exception
    {

        // test passing object create
        Digester digester = new Digester();
        ObjectCreationFactoryTestImpl factory = new ObjectCreationFactoryTestImpl();
        digester.addFactoryCreate( "root", factory, ignoreCreateExceptions );
        String xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        digester.parse( new StringReader( xml ) );

        assertEquals( "Object create not called(1)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (1)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (2)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (3)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        List<ObjectCreationFactoryTestImpl> list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(2)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (4)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (5)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (6)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(3)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (7)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml =
            new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
                + " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Attribute Override Failed (1)", factory.getClass().getName(),
                      "org.apache.commons.digester3.OtherTestObjectCreationFactory" );
        assertEquals( "Object create not called(4)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (10)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (11)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (12)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(5)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (13)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (14)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (15)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml =
            new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
                + " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Attribute Override Failed (2)", factory.getClass().getName(),
                      "org.apache.commons.digester3.OtherTestObjectCreationFactory" );
View Full Code Here

                bindRulesFrom( clazz );
            }

        });

        Digester digester = newLoader(modules).newDigester();
        Object actual = digester.parse(input);

        if (input != null) {
            input.close();
        }
View Full Code Here

     */
    @Before
    public void setUp()
    {

        digester = new Digester();

    }
View Full Code Here

    {
        // * tests that a rule can declare custom PluginCreateRules
        // that allow it to plug in instances of itself below
        // itself.

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

        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule( "*/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( Utils.getInputStream( this, "test6.xml" ) );
        }
        catch ( Exception e )
        {
            throw e;
        }
View Full Code Here

            System.err.println( "usage: pipeline config-file" );
            System.exit( -1 );
        }
        String configFile = args[0];

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

        digester.addObjectCreate( "pipeline", Pipeline.class );

        digester.addCallMethod( "pipeline/source", "setSource", 1 );
        digester.addCallParam( "pipeline/source", 0, "file" );

        PluginCreateRule pcr = new PluginCreateRule( Transform.class );
        digester.addRule( "pipeline/transform", pcr );
        digester.addSetNext( "pipeline/transform", "setTransform" );

        digester.addCallMethod( "pipeline/destination", "setDest", 1 );
        digester.addCallParam( "pipeline/destination", 0, "file" );

        Pipeline pipeline = null;
        try
        {
            pipeline = digester.parse( configFile );
        }
        catch ( Exception e )
        {
            System.err.println( "oops exception occurred during parse." );
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.commons.digester3.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.