You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Will Glass-Husain <wg...@forio.com> on 2006/04/20 21:48:18 UTC
Re: Private fields and methods in ResourceLoader
That sounds interesting. Did you remember to call VelocityEngine.init() or
Velocity.init() before parsing a template?
WILL
On 4/20/06, Tim Pizey <ti...@paneris.org> wrote:
>
> Hi,
>
> I have been trying to write a ResourceLoader, initially a
> FileResourceLoader, but found that I could not extend
> FileResourceLoader as the members and findTemplate method are private.
>
> This has forced me to a more general solution, where I have a
> ResouceLoader
> which is a decorator to any other and takes the InputStream returned,
> converts it to a String, does Perl5 substitutions on it and then
> converts the String back to an InputStream.
>
> My code is at work but from memory I do something like
>
> public abstract class WebMacroResourceLoader extends ResourceLoader {
>
> private ResourceLoader loader ;
>
> public void init( ExtendedProperties configuration) {
> loader.init(configuration);
> }
>
> public InputStream getResourceStream(String templateName) {
> if (templateName.endsWith(".wm") {
> // mugle about with Perl5
> // return new input stream
> } else
> return loader.getResourceStream(templateName);
> }
>
> }
>
> public class WebMacroClasspathResourceLoader extends
> WebMacroResourceLoader {
> public WebMacroClasspathResourceLoader() {
> this.loader = new ClasspathResourceLoader();
> }
> }
> public class WebMacroFileResourceLoader extends WebMacroResourceLoader {
> public WebMacroClasspathResourceLoader() {
> this.loader = new FileResourceLoader();
> }
> }
>
> Mine feels like a not-unusual requirement, is my approach sensible?
> PS Any idea why I am getting NPE thrown from the init method?
>
> yours
> Tim Pizey
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
--
Forio Business Simulations
Will Glass-Husain
wglass@forio.com
www.forio.com
Re: Private fields and methods in ResourceLoader
Posted by Tim Pizey <ti...@paneris.org>.
Hi Will,
Thanks for your reply.
On further investigation it turns out that my approach doesn't fly,
as a new ResouceLoader is not initialised and you cannot get an
initialised one from the ResouceManager.
However all I really needed was a static helper class
which converts the InputStream to a String, mungs it and then
returns a new InputStream.
See
http://www.melati.org/xref/org/melati/template/velocity/WebMacroClasspathResourceLoader.html
I found that there are a few problems with the RegExps in
convert/WebMacro
see
http://www.melati.org/xref/org/melati/template/velocity/WebMacroConverter.html
where I have had to escape the dollar in the output pattern as well as the
input pattern.
I have also added a pair of regexps to handle nulls.
So I have now got
http://www.melati.org/melati/org.melati.admin.Admin/contacts/Main
working using Velocity as the TemplateEngine using WebMacro templates,
which enables Melati to be mixed in to a Velocity project.
cheers
TimP
On Thursday 20 April 2006 20:48, Will Glass-Husain wrote:
> That sounds interesting. Did you remember to call VelocityEngine.init() or
> Velocity.init() before parsing a template?
>
> WILL
>
> On 4/20/06, Tim Pizey <ti...@paneris.org> wrote:
> > Hi,
> >
> > I have been trying to write a ResourceLoader, initially a
> > FileResourceLoader, but found that I could not extend
> > FileResourceLoader as the members and findTemplate method are private.
> >
> > This has forced me to a more general solution, where I have a
> > ResouceLoader
> > which is a decorator to any other and takes the InputStream returned,
> > converts it to a String, does Perl5 substitutions on it and then
> > converts the String back to an InputStream.
> >
> > My code is at work but from memory I do something like
> >
> > public abstract class WebMacroResourceLoader extends ResourceLoader {
> >
> > private ResourceLoader loader ;
> >
> > public void init( ExtendedProperties configuration) {
> > loader.init(configuration);
> > }
> >
> > public InputStream getResourceStream(String templateName) {
> > if (templateName.endsWith(".wm") {
> > // mugle about with Perl5
> > // return new input stream
> > } else
> > return loader.getResourceStream(templateName);
> > }
> >
> > }
> >
> > public class WebMacroClasspathResourceLoader extends
> > WebMacroResourceLoader {
> > public WebMacroClasspathResourceLoader() {
> > this.loader = new ClasspathResourceLoader();
> > }
> > }
> > public class WebMacroFileResourceLoader extends WebMacroResourceLoader {
> > public WebMacroClasspathResourceLoader() {
> > this.loader = new FileResourceLoader();
> > }
> > }
> >
> > Mine feels like a not-unusual requirement, is my approach sensible?
> > PS Any idea why I am getting NPE thrown from the init method?
> >
> > yours
> > Tim Pizey
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org