Well that clears up a lot... I'll explain.
I am using velocity for building deployment descriptors for a J2EE
Enterprise-level project. What I am using velocity for is fairly
straightforward but important, iterating over a list of files, merging and
writing new files. While setting the initial root works if it's high enough
in the structure, changing target drives on an NT workstation is a problem.
I would like to simply have a way to change root initializations on the fly
but I see now that that would not work the way the code is currently
written. I'm not sure why Velocity requires a predefined root (by default
taking the current working directory); I can only assume that it is related
to optimization of the internal path-finding code.
However, your point about using multiple VelocityEngine instances will allow
me to solve my problem simply by registering the drives ahead of time and
implementing a little dispatcher pattern code to choose the correct engine
for a given file. I expect that on Unix this isn't a problem.
I would like to learn more about Velocity but the existing docs seem to be
more reference than tutorial (a section on usage planning would be valuable
since there seems to be many ways to use it). For example, I found
interesting, your recommendation to try to not use the Runtime classes
directly when, after looking at some code, the Velocity code simply calls
the Runtime. Is this to plan against code breaking as the project evolves? I
never saw anything in the docs that addresses the topic of who should use
what when and how. Maybe my expectations were too high, since the project is
so impressive from what I've seen so far.
Thanks for your help.
p.s. In that project I mentioned, I implemented the Velocity processsing
piece as an ANT Task.
-----Original Message-----
From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 9:48 AM
To: [EMAIL PROTECTED]
Subject: Re: Dynamic Velocity Root designations?
"Provencher, Samuel" wrote:
>
> Does anyone know what the deal is with changing root directories? Velocity
> takes a root definition, under which, it looks for files you request. What
I
> haven't been able to do is change that root designation to another
directory
> or other drive - the code below doesn't work... any ideas?
>
> Properties p = new Properties();
> p.setProperty(Runtime.FILE_RESOURCE_LOADER_PATH, myRoot);
>
> // Initialize the Velocity runtime engine passing the properties object.
> Runtime.init(p);
>
> NOTE: To date, I have worked around the issue by setting the drive root as
> Velocity's root and provide subdirectories as part of the target file
> designation. This, however, does not allow me to target new drives.
What is 'myRoot'.
First, Velocity's singleton runtime ('Runtime') will only allowed itself
to be initialized once, so if this is a subsequent init(), it won't
work.
Second, you can setup multiple template path nodes :
Runtime.setProperty( Runtime.FILE_RESOURCE_LOADER_PATH, "/foo, /bar,
"/woogie/glop" );
Runtime.init();
Third, if you really can't have multiple (suppose there are duplicate
templates in /foo and /bar) then you should use multiple runtime
instances :
VelocityEngine ve1 = new VelocityEngine();
VelocityEngine ve2 = new VelocityEngine();
and set properties and init() the VelocityEngines just as you would a
Runtime.
Also, please note that you shouldn't use any of the Runtime* classes -
there are classes provided for application use, namely
org.apache.velocity.app.Velocity // the singleton
org.apache.velocity.app.VelocityEngine // the non-singleton
geir
--
Geir Magnusson Jr. [EMAIL PROTECTED]
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb