Hi again...
Think I managed to fix the problem.
Overriding the initVelocity and setting the resource-loders outside the
properties file did the trick.
Still don't know why the velocity.properties configuration didn't work
though.
Thanks for your help
best
magnus
Magnus Kvalheim wrote:
Thanks for your reply Steve,
No, I'm not getting any calls to the isSourceModified or getLastModified
methods.
Using velocity-tools I have never had the need to specify any
resource-loaders before.
Taken from:
http://jakarta.apache.org/velocity/tools/view/index.html#Installation
"Velocity configuration is *optional*, and for most applications the
defaults will work fine. The *velocity.properties* file contains
settings that affect logging, encoding, and macro settings".
Does this mean that resourceLoaders with velocity-tools should be
defined outside the velocity.properties file?
Velocity only search for templates in the default
resource-handler(velocity-tools) and never hits my custom loader (except
on deploy).
One strange thing though: At the time of web-deploy the
CustomResourceLoader.getResourceStream is called searching for
/WEB-INF/VM_global_library.vm - which it will not find.
Is the ResourceManagerImpl making the call looking for the file?
... and will I have to write my own implementation of the
ResourceManager interface in order to make my resourceloader work properly?
Any help is much appreciated
thanks
Magnus
Steve O'Hara wrote:
Hi Magnus,
Answering your last question first, no, velocity will only load a
template using the resource loaders you specify. In your case, you've
only specified one, "custom". If you leave it blank, then it assumes
"file". If you want more than one loader, then you should do something
like the following;
resource.loader = custom,WebAppLoader
Back to your problem - are you getting calls to the methods
getLastModified & isSourceModified within your resource loader?
Perhaps you're not sending back anything in response to these calls and
therefore the loader manager is not bothering to call your
getResourceStream method.
Steve
-----Original Message-----
From:
[EMAIL PROTECTED]
.org
[mailto:[EMAIL PROTECTED]
a.apache.org] On Behalf Of Magnus Kvalheim
Sent: 23 November 2005 10:33
To: [email protected]
Subject: Write a custom resourceloader
Hi all,
I have tried to write a custom resourceloader on order to be able to
load templates from an alternate source.
I am using velocity-tools 1.2
I have extended the
org.apache.velocity.runtime.resource.loader.ResourceLoader class and
registered the resource loader in the velocity.properties file like
this.
---------
resource.loader = custom
custom.resource.loader.description = A custom resource loader
custom.resource.loader.class = package.CustomResourceLoader
-------
The resource loader is indeed being loaded - as the init function is
called when the project is deployed to the web server. It also calls the
getResourceStream with the "/WEB-INF/VM_global_library.vm" as parameter,
but I guess the ResourceManagerImpl is the cause of this.
The getResourceStream for my custom class is however NEVER called when I
request a template.
getTemplate("templateFromCustomSource.vm");
Have I missed something?
Shouldn't velocity now look for templates in both WebAppLoader and
CustomResourceLoader?
thanks
Magnus
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]