You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Swearingen, David W." <dw...@tasc.com> on 2002/05/03 17:45:01 UTC
Newbie: outputing multiple files
I just cranked up velocity and successfully used the #for loop to generate
to stdout several iterations of my template.
Now I want to put each iteration into a separate file, each file being
auto-named, where the name would be the value of some variable in the
ArrayList I'm iterating. (I'm generating a bunch of SVG files, each one
with slightly different content.)
It's not clear to me from the docs or examples how to do this. Help greatly
appreciated.
David Swearingen
-------------------------------------------------------------------------
David Swearingen
Northrop-Grumman Information Technology - TASC
4801 Stonecroft Blvd. Chantilly, VA 20151-3822
703-633-8300 x4790 voice
703-449-1610 fax
dwswearingen@tasc.com
------------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Newbie: outputing multiple files
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 5/3/02 11:45 AM, "Swearingen, David W." <dw...@tasc.com> wrote:
> I just cranked up velocity and successfully used the #for loop to generate
> to stdout several iterations of my template.
>
> Now I want to put each iteration into a separate file, each file being
> auto-named, where the name would be the value of some variable in the
> ArrayList I'm iterating. (I'm generating a bunch of SVG files, each one
> with slightly different content.)
Cool!
Here's how I would do it. Note, I'm lazy. Also note that you cannot and
should not try to fool with the underlying Writer.
Make a little tool that writes to files :
public class Tool
{
... Vars ...
public void open(String filename)
{
..open file..
}
public void write(String stuff )
{
.. Write to file...
}
public void close()
{
... Yep, close file...
}
}
Then put one of those in the context.
Next, put the output as a VM :
#macro( mySVG $data )
...
#end
And then
#foreach($data in $mydata)
$tool.open($data.filename)
$tool.write("#mySVG($data)")
$tool.close()
#end
And that should do it :)
>
> It's not clear to me from the docs or examples how to do this. Help greatly
> appreciated.
>
> David Swearingen
>
> -------------------------------------------------------------------------
> David Swearingen
> Northrop-Grumman Information Technology - TASC
> 4801 Stonecroft Blvd. Chantilly, VA 20151-3822
> 703-633-8300 x4790 voice
> 703-449-1610 fax
> dwswearingen@tasc.com
> ------------------------------------------------------------------------
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
--
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>