velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: changing file.resource.loader.path after velocity init
Date Wed, 28 Nov 2001 20:48:08 GMT
On 11/28/01 3:40 PM, "Ryan Carmody" <rcarmody@igetsmart.com> wrote:

> great!  is there a way to select which path should be searched in first?

It should be the order that they are added...

> for instance, if i have two directories DIRA and DIRB added to the path
> list.  if both DIRA and DIRB have TEMPLATE1 in them, is there any way to
> specify which TEMPLATE1 it will use(ie DIRA/TEMPLATE1 or DIRB/TEMPLATE1?),
> without having child directories under the path added to the list(ie add
> MASTERDIR to the path list and then just pull DIRA/TEMPLATE1 or
> DIRB/TEMPLATE1)  I now it's a strange question, but i'm looking for a
> solution to use a custom template for one instance while defaulting back to
> the regular template for normal use.
> 
> -----Original Message-----
> From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
> Sent: Wednesday, November 28, 2001 2:45 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: changing file.resource.loader.path after velocity init
> 
> 
> On 11/28/01 2:37 PM, "Ryan Carmody" <rcarmody@igetsmart.com> wrote:
> 
>> Thanks for the help!  I was really hoping to have multiple paths instead
> of
>> re-initing velocity(lot of cached templates and all).  I think I might try
>> to add some code, so that it would support multiple paths.
> 
> It already does support multiple paths.
> 
> You should be able to just crank them in :
> 
> 
>  VelocityEngine ve = new VelocityEngine();
> 
>  ve.setProperty( "file.resource.loader.path", path1 );
>  ve.setProperty( "file.resource.loader.path", path2 );
>  ve.setProperty( "file.resource.loader.path", path3 );
>  ve.setProperty( "file.resource.loader.path", path4 );
> 
>   ve.init();
> 
> 
> Or, you can specify them as a comma-delimited list in the
> velocity.properties file (is you use a properties to init...)
> 
> You could probably use one setProperty() call above, with a comma-delimited
> list as well...
> 
> 
> 
> It looks like
>> you were planning on doing that in the FileResourceLoader anyway from the
>> javadoc: "This is a simple template file loader. Currently it only
> supports
>> a single path to templates. That'll change once we decide how we want to
> do
>> configuration."
>> 
>> Thanks again for your help!
>> 
>> -----Original Message-----
>> From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
>> Sent: Tuesday, November 27, 2001 5:18 PM
>> To: velocity-user@jakarta.apache.org
>> Subject: Re: changing file.resource.loader.path after velocity init
>> 
>> 
>> On 11/27/01 5:09 PM, "Ryan Carmody" <rcarmody@igetsmart.com> wrote:
>> 
>>> Is it possible to change Velocity's v1.1 file.resource.loader.path after
>> it
>>> has gone through init?  I've tried manually setting it on top of the
>>> "default" velocity.properties but it appears I can only get that to work
>>> once, when the first init happens.
>> 
>> No, it doesn't accept changes after init() is called.
>> 
>> You might use a VelocityEngine and when you need to change the
> configuation,
>> just make and init() a new one.
>> 
>> I assume that this doesn't happen very often?
>> 
>>> 
>>> /////////////////////////////////////////////////
>>> private Velocity vengine;
>>> private VelocityContext context;
>>> 
>>>   public test(String pathname,String filename)
>>>   {
>>>       vengine = new Velocity();
>>>       context = new VelocityContext();
>>>       
>>>       try{ 
>>>           vengine.setProperty("file.resource.loader.path",pathname);
>>>           vengine.init();
>>>           template = vengine.getTemplate(filename);
>>>       }catch(ResourceNotFoundException ex){ System.out.println("Cannot
>>> find template " + templateFile +":"+ex.getMessage());
>>>       }catch(ParseErrorException ex){System.out.println("Syntax error in
>>> template " + templateFile + ":" + ex.getMessage() );
>>>       }catch(Exception ex){System.out.println("Syntax error in template "
>>> + templateFile + ":" + ex.getMessage() );
>>>       }
>>>   }
>>> /////////////////////////////////////////////////
>>> 
>>> Thanks In Advance,
>>> Ryan
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <mailto:velocity-user-help@jakarta.apache.org>
>>> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message