velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <>
Subject Re: Configuration pattern for StringResourceRepository
Date Mon, 07 May 2007 17:15:39 GMT
On 5/6/07, Thilo Schwarz <> wrote:
> Hi to all!
> It seems, I need a hit on my head. I've got the problem to understand
> the pattern to configure the StringResourceRepository! I'm using
> velocity in a standalone application. To initialize the
> VelocityEngine, I do something like that:
> VelocityEngine velocityEngine = new VelocityEngine();
> Properties velocityProperties = new Properties();
> //  code to collect the props
> velocityEngine.init(velocityProperties);
> And it works as excpected!
> How I have to extend the code to work with the StringResourceRepository?

it's described here:

so you would do something like the following once you initialized your

StringResourceRepository vsRepository = StringResourceLoader.getRepository();
String myTemplateName = "/somewhere/intherepo/name";
String myTemplateBody = "Hi, ${username}... this is a some template!";
vsRepository.putStringResource(myTemplateName, myTemplateBody);

but be wary, since the repository is unfortunately a singleton in
Velocity 1.5, you can only initialize one VelocityEngine using the
StringResourceLoader.  if you try and initialize another
VelocityEngine configured to use the StringResourceLoader, you will
get an IllegalStateException. :(  Also, the VelocityEngine using it
must be initialized before you try to retrieve the repository.  :(

I've improved things greatly for the next version of Velocity.  If you
are willing to checkout and build the trunk, you can use it as
described here:

> Any hints are helpfull.
> Thanks and regards
> Thilo
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message