velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caleb Jones" <calebjo...@gmail.com>
Subject Re: velocimarco.library property and StringResourceLoader
Date Wed, 07 Jan 2009 18:03:28 GMT
Thanks Nathan!

The following config works for me (it ended up being better for me to use a
class path loader):

-------------------------------------------------
 template.encoding = UTF8
 input.encoding=UTF-8
 output.encoding=UTF-8
 velocimacro.library=/my/class/path/VM_global_library.vm
 resource.loader = string,class
 string.resource.loader.description = Velocity StringResource loader
 string.resource.loader.class =
org.apache.velocity.runtime.resource.loader.StringResourceLoader
 string.resource.loader.repository.class =
org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl
 class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
--------------------------------------------------

On Tue, Jan 6, 2009 at 4:05 PM, Nathan Bubna <nbubna@gmail.com> 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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message