Package freenet.crypt

Examples of freenet.crypt.MultiHashInputStream$Digester


  /**
   * {@inheritDoc}
   */
  @Override
  protected void initializeDigester() {
    digester = new Digester();
    digester.setNamespaceAware(true);
    digester.addObjectCreate("schema/fields", ArrayList.class);
    digester.addObjectCreate("schema/fields/dynamicField", SolrFieldAttributes.class);
    digester.addSetProperties("schema/fields/dynamicField/");
    digester.addSetNext("schema/fields/dynamicField", "add");
View Full Code Here


        throws Exception
    {
        // tests that by default the attributes used are
        // named "plugin-class" and "plugin-id"

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

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

        PluginCreateRule widgetPluginRule = new PluginCreateRule( Widget.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( Utils.getInputStream( this, "test7.xml" ) );

        }
        catch ( Exception e )
        {
            throw e;
View Full Code Here

     */
    @Before
    public void setUp()
    {

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

    }
View Full Code Here

                this.body = text;
            }
        }

        TestSubRule tsr = new TestSubRule();
        Digester digester = new Digester();
        digester.addRule( "alpha/beta", tsr );

        // it's not easy to transform dirty harry into the mighty circus - but let's give it a try
        String xml =
            "<?xml version='1.0'?><alpha><beta forname='Dirty' surname='Harry'>Do you feel luck punk?</beta></alpha>";
        InputSource in = new InputSource( new StringReader( xml ) );

        digester.parse( in );

        assertEquals( "Unsubstituted body text", "Do you feel luck punk?", tsr.body );
        assertEquals( "Unsubstituted number of attributes", 2, tsr.attributes.getLength() );
        assertEquals( "Unsubstituted forname attribute value", "Dirty", tsr.attributes.getValue( "forname" ) );
        assertEquals( "Unsubstituted surname attribute value", "Harry", tsr.attributes.getValue( "surname" ) );

        digester.setSubstitutor( new Substitutor()
        {
            @Override
            public Attributes substitute( Attributes attributes )
            {
                AttributesImpl results = new AttributesImpl();
                results.addAttribute( "", "python", "python", "CDATA", "Cleese" );
                return results;
            }

            @Override
            public String substitute( String bodyText )
            {
                return "And now for something completely different...";
            }
        } );

        // now transform into the full monty
        in = new InputSource( new StringReader( xml ) );
        digester.parse( in );

        assertEquals( "Substituted body text", "And now for something completely different...", tsr.body );
        assertEquals( "Substituted number of attributes", 1, tsr.attributes.getLength() );
        assertEquals( "Substituted python attribute value", "Cleese", tsr.attributes.getValue( "", "python" ) );
    }
View Full Code Here

    public void testNamedStackPushPeekPop()
        throws Exception
    {
        BigDecimal archimedesAveragePi = new BigDecimal( "3.1418" );
        String testStackName = "org.apache.commons.digester3.tests.testNamedStackPushPeekPop";
        Digester digester = new Digester();
        assertTrue( "Stack starts empty:", digester.isEmpty( testStackName ) );
        digester.push( testStackName, archimedesAveragePi );
        assertEquals( "Peeked value:", archimedesAveragePi, digester.peek( testStackName ) );
        assertEquals( "Popped value:", archimedesAveragePi, digester.pop( testStackName ) );
        assertTrue( "Stack ends empty:", digester.isEmpty( testStackName ) );

        digester.push( testStackName, "1" );
        digester.push( testStackName, "2" );
        digester.push( testStackName, "3" );

        assertEquals( "Peek#1", "1", digester.peek( testStackName, 2 ) );
        assertEquals( "Peek#2", "2", digester.peek( testStackName, 1 ) );
        assertEquals( "Peek#3", "3", digester.peek( testStackName, 0 ) );
        assertEquals( "Peek#3a", "3", digester.peek( testStackName ) );

        try
        {
            // peek beyond stack
            digester.peek( testStackName, 3 );
            fail( "Peek#4 failed to throw an exception." );
        }
        catch ( EmptyStackException ex )
        {
            // ok, expected
        }

        try
        {
            // peek a nonexistent named stack
            digester.peek( "no.such.stack", 0 );
            fail( "Peeking a non-existent stack failed to throw an exception." );
        }
        catch ( EmptyStackException ex )
        {
            // ok, expected
View Full Code Here

        // with "null" for namespace (ie attributes not in any namespace).
        //
        // note that in order not to screw up all other tests, we need
        // to reset the global names after we finish here!

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

        rc.setPluginIdAttribute( null, "id" );
        rc.setPluginClassAttribute( null, "class" );

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

        PluginCreateRule widgetPluginRule = new PluginCreateRule( Widget.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( Utils.getInputStream( this, "test7.xml" ) );

        }
        catch ( Exception e )
        {
            throw e;
View Full Code Here

    {
        // 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://commons.apache.org/digester/plugins", "id" );
        widgetPluginRule.setPluginClassAttribute( "http://commons.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( Utils.getInputStream( this, "test7.xml" ) );
        }
        catch ( Exception e )
        {
            throw e;
        }
View Full Code Here

    @Test
    public void testNamedIndependence()
    {
        String testStackOneName = "org.apache.commons.digester3.tests.testNamedIndependenceOne";
        String testStackTwoName = "org.apache.commons.digester3.tests.testNamedIndependenceTwo";
        Digester digester = new Digester();
        digester.push( testStackOneName, "Tweedledum" );
        digester.push( testStackTwoName, "Tweedledee" );
        assertEquals( "Popped value one:", "Tweedledum", digester.pop( testStackOneName ) );
        assertEquals( "Popped value two:", "Tweedledee", digester.pop( testStackTwoName ) );
    }
View Full Code Here

    /** Tests popping named stack not yet pushed */
    @Test
    public void testPopNamedStackNotPushed()
    {
        String testStackName = "org.apache.commons.digester3.tests.testPopNamedStackNotPushed";
        Digester digester = new Digester();
        try
        {

            digester.pop( testStackName );
            fail( "Expected an EmptyStackException" );

        }
        catch ( EmptyStackException e )
        {
            // expected
        }

        try
        {

            digester.peek( testStackName );
            fail( "Expected an EmptyStackException" );

        }
        catch ( EmptyStackException e )
        {
View Full Code Here

    /** Tests for isEmpty */
    @Test
    public void testNamedStackIsEmpty()
    {
        String testStackName = "org.apache.commons.digester3.tests.testNamedStackIsEmpty";
        Digester digester = new Digester();
        assertTrue( "A named stack that has no object pushed onto it yet should be empty",
                    digester.isEmpty( testStackName ) );

        digester.push( testStackName, "Some test value" );
        assertFalse( "A named stack that has an object pushed onto it should be not empty",
                     digester.isEmpty( testStackName ) );

        digester.peek( testStackName );
        assertFalse( "Peek should not effect whether the stack is empty", digester.isEmpty( testStackName ) );

        digester.pop( testStackName );
        assertTrue( "A named stack that has it's last object popped is empty", digester.isEmpty( testStackName ) );
    }
View Full Code Here

TOP

Related Classes of freenet.crypt.MultiHashInputStream$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.