velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Cohen <sco...@javactivity.org>
Subject Re: velocimarco.library property and StringResourceLoader
Date Thu, 08 Jan 2009 13:47:48 GMT
I continue to find out new things (new for me) about Velocity. 

I am trying to wrap my head around the StringResourceLoader concept, 
which sounds like something I've been looking for.  Up to now my usage 
of Velocity (for this AOL-Instant Messager-based app I've talked about 
before) has been to embed each bit of text I want to display in a little 
xhtml file loaded by Velocity including merging dynamic text into the file.

It works great, but it has felt a bit like overkill sometimes, 
especially with the smaller bits of text.  The idea of string resource 
loading was floating around the back of mind when I saw this post.

But I find I'm not quite getting the concept of StringResourceLoader as 
it is laid out in the javadocs.  The documentation there is all about 
dynamically loading strings INTO the repository.  This is not at all 
what I am after.  I am after statically loading a bunch of string 
resources as opposed to file resources (i.e., multiple string resources 
in a file) somewhere where Velocity can find them for later retrieval by 
the application.

Is there some sample code or other documentation demonstrating in more 
detail the uses of the StringResourceLoader?


Nathan Bubna wrote:
> On Tue, Jan 6, 2009 at 3:54 PM, Caleb Jones <calebjones@gmail.com> wrote:
>   
>> Following the Javadoc for StringResourceLoader I have my velocity.properties
>> setup as follows:
>>
>> -------------------------------
>> template.encoding = UTF8
>> input.encoding=UTF-8
>> output.encoding=UTF-8
>> velocimacro.library=VM_global_library.vm
>> resource.loader = string
>> string.resource.loader.description = Velocity StringResource loader
>> string.resource.loader.class =
>> org.apache.velocity.runtime.resource.loader.StringResourceLoader
>>     
>
> looks good.
>
>   
>> string.resource.loader.repository.class =
>> org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl
>>     
>
> you don't need this property unless you are using your own repository impl.
>
>   
>> --------------------------------
>>
>> The problem I have is that Velocity cannot find my VM_global_library.vm.  I
>> can see why the StringResourceLoader wouldn't know what to do with
>> "VM_global_library.vm", but I as per the velocimacro.library docs at
>> http://velocity.apache.org/engine/devel/developer-guide.html:
>>
>> ----------------------------------
>> velocimacro.library = VM_global_library.vm
>> Multi-valued key. Will accept CSV for value. Filename(s) of Velocimacro
>> library to be loaded when the Velocity Runtime engine starts. These
>> Velocimacros are accessable to all templates. The file is assumed to be
>> relative to the root of the file loader resource path.
>> -----------------------------------
>>
>> ...it doesn't mention how or if this can be configured when using a
>> StringResourceLoader.
>>
>> What is the best way to load global macro files when using a
>> StringResourceLoader?
>>     
>
> Depends on if you want to load it from the file system or as a String.
>  I haven't actually tried the latter, but i think you simply need to
> put it into the repository before you init() Velocity.   So, somewhere
> before Velocity is initialized you should do:
>
> StringResourceLoader.getRepository().putStringResource("VM_global_library.vm",
> theMacrosAsAString);
>
> for the former (which actually sounds more like what you want), you
> simply need to have another resource loader configured.  Note that the
> resource.loader property takes a comma separated list of names of
> loaders that should be initialized and used.  Velocity will check the
> resource loaders in the order listed until it finds the requested
> file.  So, you might do:
>
> velocimacro.library=VM_global_library.vm
> resource.loader = string,file
> string.resource.loader.class =
> org.apache.velocity.runtime.resource.loader.StringResourceLoader
> file.resource.loader.class =
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
>
> and you can, of course, add a file.resource.loader.path property or
> use a different resource loader(s) entirely.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
>   


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


Mime
View raw message