Hi Robby!

The Stringtemplate generator is much more sophisticated (you have
iterators, access to objects methods, ...) compared to this simple
component, that simply provides variable expansion.

The other difference is: Stringtemplate is a generator, the
VariableExpander is a component you can put in the middle of the
pipeline whenever you need - in my case, I needed to plug it at the
3rd stage of the pipeline.

For what it worths, Stringtemplate generator brings a 3rd party
dependency, VariableExpander comes dependencies-free inside the
cocoon-sax package.

Hope this clarifies, don't hesitate to ask if you need to know more!
All the best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Thu, Dec 15, 2011 at 5:32 PM, Robby Pelssers <robby.pelss...@nxp.com> wrote:
> Hi Simone,
>
> This sounds useful. But it's not really clear to me as to how this differs 
> from the Stringtemplate generator which is also part of C3.
>
> Robby
>
> -----Original Message-----
> From: simone.trip...@gmail.com [mailto:simone.trip...@gmail.com] On Behalf Of 
> Simone Tripodi
> Sent: Thursday, December 15, 2011 5:25 PM
> To: dev@cocoon.apache.org
> Subject: [C3] new pipeline component: variabelExpander
>
> 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
>
> <project>
>  <target>
>    <delete dir="${build.home}" />
>    <delete dir="${dist.home}" />
>    <echo>A property '${text.property}' inside the text</echo>
>  </target>
> </project>
>
> 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( "text.property", "Cocoon3 rocks!" );
>
> then creating and run their pipeline adding the VariableExpander:
>
>        newNonCachingPipeline().setURLGenerator(
> getClass().getResource( "/variables-expander.xml" ) )
>                               .addVariableExpander( variables )
>                               .addSerializer()
>                               .withEmptyConfiguration()
>                               .setup( System.out )
>                               .execute();
>
> the XML document will be processed by the next component in the
> pipeline will look like:
>
> <project>
>  <target>
>    <delete dir="Users/cocoon/workspace" />
>    <delete dir="Users/cocoon/download" />
>    <echo>A property 'Cocoon3 rocks!' inside the text</echo>
>  </target>
> </project>
>
> WDYT? I hope it will be useful for you as well it is for me :P
> Have a nice day, all the best!
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/

Reply via email to