On 15/12/2011 17:25, Simone Tripodi wrote:
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
Hi Simone,
this sounds like a really nice and lightweight improvement for C3 :-)
So far I have been achieving similar results by using
StringTemplateTransformer which implies, as known, an additional
dependency; however, StringTemplate for realizing only this is actually
too much.
Anyway, could you think of a way for using this new component inside
sitemap?
Thanks.
--
Francesco Chicchiriccò
Apache Cocoon Committer and PMC Member
http://people.apache.org/~ilgrosso/