You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Simone Tripodi <si...@apache.org> on 2011/12/15 17:25:10 UTC

[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/

Re: [C3] new pipeline component: variabelExpander

Posted by Francesco Chicchiriccò <il...@apache.org>.
Il 15/12/2011 18:27, Simone Tripodi ha scritto:
> Hi Grosso!!!
>> Anyway, could you think of a way for using this new component inside
>> sitemap?
> ehm... yes, so... I was think about... ehm... yes I know how, yes...
> ehm... don't know yet :P
>
> jokes a part, what's your usecase using Stringtemplate inside the
> sitemap? We could start replicating the same behavior, just for
> start...

Well, just consider the way how StringTemplate transformer is currently 
included in cocoon-sample's sitemap:

<map:match wildcard="string-template/transformer">
<map:generate src="string-template/template.xml"/>
<map:transform type="string-template">
<map:parameter name="parameter" value="Another value"/>
<map:parameter name="booleanParameter" value="{jexl:false}"/>
</map:transform>
<map:serialize/>
</map:match>

where template.xml is something like:

<html>
<head>
<title>StringTemplate demo</title>
</head>
<body>
<h3>StringTemplate demo</h3>
<p>parameter=$parameter$</p>
$if(booleanParameter)$
<p>booleanParameter was TRUE</p>
$else$
<p>booleanParameter was FALSE</p>
$endif$
</body>
</html>

I don't expect, of course, that VariableExpander could handle the stuff 
related to booleanParameter: anyway, it should instead replace 
$parameter$ white "Another value".

Anyway, I am just realizing that using a "foreign" component like 
VariableExpander adds much more value in a Java pipeline than inside 
sitemap...

Regards.

-- 
Francesco Chicchiriccò

Apache Cocoon Committer and PMC Member
http://people.apache.org/~ilgrosso/


Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
Hola Thorsten!

>
> Another approach would be to use the transformer configure and use a
> language interpreter to generate a Properties object. That works since
> we can now inject object and not only strings. Like:
>
> <map:transform xmlns:map="http://apache.org/cocoon/sitemap"
> type="variableExpanderTransformer">
>  <map:parameter name="text"properties value="{properties:something}"/>
> </map:transform>
>
> This would allow to use other props beside the "env".
>
> wdyt?

I really like this approach!!! We could even support loading
properties files, URLs, ... great!
Thanks for your feedback!
-Simo

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

Re: [C3] new pipeline component: variabelExpander

Posted by Thorsten Scherler <sc...@gmail.com>.
On Thu, 2011-12-15 at 18:27 +0100, Simone Tripodi wrote:
> Hi Grosso!!!
> 
> >
> > Anyway, could you think of a way for using this new component inside
> > sitemap?
> >
> > Thanks.
> >
> 
> ehm... yes, so... I was think about... ehm... yes I know how, yes...
> ehm... don't know yet :P
> 
> jokes a part, what's your usecase using Stringtemplate inside the
> sitemap? We could start replicating the same behavior, just for
> start...
> 
> Thanks for the feedbacks and TIA for the new ones!
> All the best,

Actually Stringtemplate is very limited and lightweight and exists as
well as transformer. However I agree that this new component is a nice
extension to c3.

Regarding the example I would love that this component would work with
the Properties/Module generator I once wrote for forrest 

https://svn.apache.org/repos/asf/forrest/trunk/whiteboard/cocoon-2.2-blocks/propertiesGenerator/src/main/java/org/apache/forrest/generation/ModuleGenerator.java

In a context such as doing an aggregation of source and properties and
then run the transfomer. The only change would be need that we check
whether we have a properties element in the context and if so we can
create the Properties variables = new Properties(); out of the result
from the propertiesGenerator. 

If that is from interest I can migrate the block to c3 and instead of
input modules it would connect the language interpreter modules. This
way it would be easy integrated into the sitemap. 

Another approach would be to use the transformer configure and use a
language interpreter to generate a Properties object. That works since
we can now inject object and not only strings. Like:

<map:transform xmlns:map="http://apache.org/cocoon/sitemap"
type="variableExpanderTransformer">
  <map:parameter name="text"properties value="{properties:something}"/>
</map:transform>

This would allow to use other props beside the "env".

wdyt?
-- 
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/


Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
Hi Grosso!!!

>
> Anyway, could you think of a way for using this new component inside
> sitemap?
>
> Thanks.
>

ehm... yes, so... I was think about... ehm... yes I know how, yes...
ehm... don't know yet :P

jokes a part, what's your usecase using Stringtemplate inside the
sitemap? We could start replicating the same behavior, just for
start...

Thanks for the feedbacks and TIA for the new ones!
All the best,
-Simo

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

Re: [C3] new pipeline component: variabelExpander

Posted by Francesco Chicchiriccò <il...@apache.org>.
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/


Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
Hi again guys,

just to continue speaking about "core" transformer APIs, I just
modified the transformer as you suggested, the showcase is:

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

        newNonCachingPipeline().setURLGenerator(
getClass().getResource( "/variables-expander.xml" ) )
                               .addComponent( expander )
                               .addSerializer()
                               .withEmptyConfiguration()
                               .setup( System.out )
                               .execute();

Moreover following VariableExpanderTransformer methods are available:

loadAll(Map<String, String>)
loadAll(Properties)
loadEnvironmentVariables() // they are prefixed with 'env.' in the context
loadSystemProperties() // Java system properties
loadProperties(URL)
loadXmlProperties(URL)

Do you think could be useful inside a sitemap processing?
Many thanks in advance, all the best!!!
-Simo

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



On Fri, Dec 16, 2011 at 4:06 PM, Simone Tripodi
<si...@apache.org> wrote:
> Hi Nathaniel!
>
> *terrific* feedback, you already put me in the condition I'm going to
> modify the transformer adoption your suggestion!
> Clear, simple, linear - priceless!
> I'll let you know when terminated!
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
>
>
> On Fri, Dec 16, 2011 at 1:38 PM, Nathaniel, Alfred
> <Al...@six-group.com> wrote:
>> Hi Simone,
>>
>> Why this special API call to add it to the pipeline?
>>
>> I think is should be a regular transformer you can add any number of time wherever you need it:
>>
>>        VariableExpander expander = new VariableExpander();
>>        expander.addProperty( "build.base", "/Users/cocoon" );
>>        expander.addProperty( "build.home", "${build.base}/workspace" );
>>        expander.addProperty( "dist.home", "${build.base}/downloads" );
>>        expander.addProperty( "text.property", "Cocoon3 rocks!" );
>>
>> then creating and run their pipeline adding the VariableExpander:
>>
>>        newNonCachingPipeline().setURLGenerator(
>> getClass().getResource( "/variables-expander.xml" ) )
>>                               .addTransformer( expander )
>>                               .addSerializer()
>>                               .withEmptyConfiguration()
>>                               .setup( System.out )
>>                               .execute();
>>
>> That makes it also easier to add configuration to the expander, for example:
>>
>> * use other marker than ${}, in case you may want generate generate a file using that syntax for its own purposes
>> * what to do if there if the property name is undefined: replace it by nothing / leave as is / throw exception
>>
>> Also by not just using a stupid property map, it is much easier to avoid infinite recursions such as setProperty("build.home","${build.home}/workspace").
>>
>> Cheers, Alfred.
>>
>> -----Original Message-----
>> From: simone.tripodi@gmail.com [mailto:simone.tripodi@gmail.com] On Behalf Of Simone Tripodi
>> Sent: Donnerstag, 15. Dezember 2011 18:02
>> To: dev@cocoon.apache.org
>> Subject: Re: [C3] new pipeline component: variabelExpander
>>
>> Hi Robby :)
>>
>> On Thu, Dec 15, 2011 at 5:56 PM, Robby Pelssers <Ro...@nxp.com> wrote:
>>> Would it be justified to say that it acts as some kind of transformer (although non-xslt based) in this case which replaces all variable references with the value from the Map or Properties provided?
>>
>> exactly, it just replaces plain text inside attributes/body elements :P
>>
>>> And I suppose it works on any text, not just XML?!
>>>
>>
>> Not ATM, it works as XmlTransformer :(
>>
>>> Bring it on ;-)
>>>
>>
>> I'll do, thanks! :)
>> best;
>> -Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://simonetripodi.livejournal.com/
>> http://twitter.com/simonetripodi
>> http://www.99soft.org/
>>
>> The content of this e-mail is intended only for the confidential use of the person addressed.
>> If you are not the intended recipient, please notify the sender and delete this e-mail immediately.
>> Thank you.

Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
Hi Nathaniel!

*terrific* feedback, you already put me in the condition I'm going to
modify the transformer adoption your suggestion!
Clear, simple, linear - priceless!
I'll let you know when terminated!
-Simo

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



On Fri, Dec 16, 2011 at 1:38 PM, Nathaniel, Alfred
<Al...@six-group.com> wrote:
> Hi Simone,
>
> Why this special API call to add it to the pipeline?
>
> I think is should be a regular transformer you can add any number of time wherever you need it:
>
>        VariableExpander expander = new VariableExpander();
>        expander.addProperty( "build.base", "/Users/cocoon" );
>        expander.addProperty( "build.home", "${build.base}/workspace" );
>        expander.addProperty( "dist.home", "${build.base}/downloads" );
>        expander.addProperty( "text.property", "Cocoon3 rocks!" );
>
> then creating and run their pipeline adding the VariableExpander:
>
>        newNonCachingPipeline().setURLGenerator(
> getClass().getResource( "/variables-expander.xml" ) )
>                               .addTransformer( expander )
>                               .addSerializer()
>                               .withEmptyConfiguration()
>                               .setup( System.out )
>                               .execute();
>
> That makes it also easier to add configuration to the expander, for example:
>
> * use other marker than ${}, in case you may want generate generate a file using that syntax for its own purposes
> * what to do if there if the property name is undefined: replace it by nothing / leave as is / throw exception
>
> Also by not just using a stupid property map, it is much easier to avoid infinite recursions such as setProperty("build.home","${build.home}/workspace").
>
> Cheers, Alfred.
>
> -----Original Message-----
> From: simone.tripodi@gmail.com [mailto:simone.tripodi@gmail.com] On Behalf Of Simone Tripodi
> Sent: Donnerstag, 15. Dezember 2011 18:02
> To: dev@cocoon.apache.org
> Subject: Re: [C3] new pipeline component: variabelExpander
>
> Hi Robby :)
>
> On Thu, Dec 15, 2011 at 5:56 PM, Robby Pelssers <Ro...@nxp.com> wrote:
>> Would it be justified to say that it acts as some kind of transformer (although non-xslt based) in this case which replaces all variable references with the value from the Map or Properties provided?
>
> exactly, it just replaces plain text inside attributes/body elements :P
>
>> And I suppose it works on any text, not just XML?!
>>
>
> Not ATM, it works as XmlTransformer :(
>
>> Bring it on ;-)
>>
>
> I'll do, thanks! :)
> best;
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
> The content of this e-mail is intended only for the confidential use of the person addressed.
> If you are not the intended recipient, please notify the sender and delete this e-mail immediately.
> Thank you.

RE: [C3] new pipeline component: variabelExpander

Posted by "Nathaniel, Alfred" <Al...@six-group.com>.
Hi Simone,

Why this special API call to add it to the pipeline?

I think is should be a regular transformer you can add any number of time wherever you need it:

        VariableExpander expander = new VariableExpander();
        expander.addProperty( "build.base", "/Users/cocoon" );
        expander.addProperty( "build.home", "${build.base}/workspace" );
        expander.addProperty( "dist.home", "${build.base}/downloads" );
        expander.addProperty( "text.property", "Cocoon3 rocks!" );

then creating and run their pipeline adding the VariableExpander:

        newNonCachingPipeline().setURLGenerator(
getClass().getResource( "/variables-expander.xml" ) )
                               .addTransformer( expander )
                               .addSerializer()
                               .withEmptyConfiguration()
                               .setup( System.out )
                               .execute();

That makes it also easier to add configuration to the expander, for example:

* use other marker than ${}, in case you may want generate generate a file using that syntax for its own purposes 
* what to do if there if the property name is undefined: replace it by nothing / leave as is / throw exception

Also by not just using a stupid property map, it is much easier to avoid infinite recursions such as setProperty("build.home","${build.home}/workspace"). 

Cheers, Alfred.

-----Original Message-----
From: simone.tripodi@gmail.com [mailto:simone.tripodi@gmail.com] On Behalf Of Simone Tripodi
Sent: Donnerstag, 15. Dezember 2011 18:02
To: dev@cocoon.apache.org
Subject: Re: [C3] new pipeline component: variabelExpander

Hi Robby :)

On Thu, Dec 15, 2011 at 5:56 PM, Robby Pelssers <Ro...@nxp.com> wrote:
> Would it be justified to say that it acts as some kind of transformer (although non-xslt based) in this case which replaces all variable references with the value from the Map or Properties provided?

exactly, it just replaces plain text inside attributes/body elements :P

> And I suppose it works on any text, not just XML?!
>

Not ATM, it works as XmlTransformer :(

> Bring it on ;-)
>

I'll do, thanks! :)
best;
-Simo

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

The content of this e-mail is intended only for the confidential use of the person addressed. 
If you are not the intended recipient, please notify the sender and delete this e-mail immediately.
Thank you.

Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
Hi Robby :)

On Thu, Dec 15, 2011 at 5:56 PM, Robby Pelssers <Ro...@nxp.com> wrote:
> Would it be justified to say that it acts as some kind of transformer (although non-xslt based) in this case which replaces all variable references with the value from the Map or Properties provided?

exactly, it just replaces plain text inside attributes/body elements :P

> And I suppose it works on any text, not just XML?!
>

Not ATM, it works as XmlTransformer :(

> Bring it on ;-)
>

I'll do, thanks! :)
best;
-Simo

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

RE: [C3] new pipeline component: variabelExpander

Posted by Robby Pelssers <Ro...@nxp.com>.
Would it be justified to say that it acts as some kind of transformer (although non-xslt based) in this case which replaces all variable references with the value from the Map or Properties provided?  And I suppose it works on any text, not just XML?!

Bring it on ;-)

Robby

-----Original Message-----
From: simone.tripodi@gmail.com [mailto:simone.tripodi@gmail.com] On Behalf Of Simone Tripodi
Sent: Thursday, December 15, 2011 5:47 PM
To: dev@cocoon.apache.org
Subject: Re: [C3] new pipeline component: variabelExpander

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 <Ro...@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.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/

Re: [C3] new pipeline component: variabelExpander

Posted by Simone Tripodi <si...@apache.org>.
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 <Ro...@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.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/

RE: [C3] new pipeline component: variabelExpander

Posted by Robby Pelssers <Ro...@nxp.com>.
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/