cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <>
Subject [C3] new pipeline component: variabelExpander
Date Thu, 15 Dec 2011 16:25:10 GMT
Hi all guys,
I just committed r1214835 a new component I need for work, so I
thought it would have been a good idea contributing back to OSS since
C3 is the foundation of the XML processor I am writing.

Basically, I needed to put variables inside our XML document that can
be replaced depending by the context the pipeline works, so the idea
came from Ant/Maven and some code I already did in Commons-Digester,
using the ${} marker for variables have to be expanded.

Using that new component is very simple: given the XML

    <delete dir="${build.home}" />
    <delete dir="${dist.home}" />
    <echo>A property '${}' inside the text</echo>

users can define their variables (in form of Properties/Map<String,String>):

        Properties variables = new Properties();
        variables.setProperty( "build.base", "/Users/cocoon" );
        variables.setProperty( "build.home", "${build.base}/workspace" );
        variables.setProperty( "dist.home", "${build.base}/downloads" );
        variables.setProperty( "", "Cocoon3 rocks!" );

then creating and run their pipeline adding the VariableExpander:

getClass().getResource( "/variables-expander.xml" ) )
                               .addVariableExpander( variables )
                               .setup( System.out )

the XML document will be processed by the next component in the
pipeline will look like:

    <delete dir="Users/cocoon/workspace" />
    <delete dir="Users/cocoon/download" />
    <echo>A property 'Cocoon3 rocks!' inside the text</echo>

WDYT? I hope it will be useful for you as well it is for me :P
Have a nice day, all the best!

View raw message