On 5/6/07, Thilo Schwarz <[EMAIL PROTECTED]> 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:

http://velocity.apache.org/engine/releases/velocity-1.5/apidocs/org/apache/velocity/runtime/resource/loader/StringResourceLoader.html

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

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:

http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/runtime/resource/loader/StringResourceLoader.html

Any hints are helpfull.
Thanks and regards
Thilo

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to