You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Marco Faustinelli <ma...@yahoo.com> on 2010/05/04 08:08:37 UTC

Transforming a text file line by line with ant.

Good morning,
I wish I could have some expert opinion on the following topic.

I have to write an xml file from a csv file inside an ant script. The way the csv lines are transformed depends on a very much complex choice, so using XSLT is excluded. Please just trust me on this one.

My idea would be to split the csv files into lines and process each line using a class which extends ProjectComponent and implements TokenFilter.Filter.

This class would be placed in a filterchain, would process the csv line and append the transformed output to a StringBuffer or send it to an OutputStream.

I have seen yesterday that filters can be called more than once per line, so I believe I have to put in place some mechanism for making sure to write only once to the output. I could do that, but...

...Is this feasible and reliable, or is it just trying to fix a square peg in a round hole? Is there a better way of doing this in the ant toolbox? Thanks in advance.

Have a nice day,
Marco Faustinelli

Re: Transforming a text file line by line with ant.

Posted by Marco Faustinelli <ma...@yahoo.com>.

Ehm, well....    :8}

I guess I mixed up mappers with filters.

Thank you for the advice.

Marco



________________________________
From: Stefan Bodewig <bo...@apache.org>
To: user@ant.apache.org
Sent: Tue, May 4, 2010 10:02:16 AM
Subject: Re: Transforming a text file line by line with ant.


They can?  Yesterday we talked about mappers acting on file names.
filters shouldn't be invoked multiple times.  In which situation do you
see such a behavior?

Re: Transforming a text file line by line with ant.

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-05-04, Marco Faustinelli <ma...@yahoo.com> wrote:

> I have to write an xml file from a csv file inside an ant script. The
> way the csv lines are transformed depends on a very much complex
> choice, so using XSLT is excluded. Please just trust me on this one.

> My idea would be to split the csv files into lines and process each
> line using a class which extends ProjectComponent and implements
> TokenFilter.Filter.

Sounds right.

> I have seen yesterday that filters can be called more than once per
> line,

They can?  Yesterday we talked about mappers acting on file names.
filters shouldn't be invoked multiple times.  In which situation do you
see such a behavior?

> ...Is this feasible and reliable, or is it just trying to fix a square
> peg in a round hole?

No, filters are exactly what you want to use.  You may need to throw in
additional classes into your filterchain that will ensure you get the
correct root element and closing tag (likely ConcatFilter will do), but
this is exactly the right extension point in Ant for a task like this.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org