On Tue, Jan 6, 2009 at 3:54 PM, Caleb Jones <[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to