cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robby Pelssers <Robby.Pelss...@nxp.com>
Subject RE: [C3] new pipeline component: variabelExpander
Date Thu, 15 Dec 2011 16:32:49 GMT
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.tripodi@gmail.com [mailto:simone.tripodi@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/
Mime
View raw message