velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <shinobu.ka...@gmail.com>
Subject Re: #parse content from a variable?
Date Sun, 19 Sep 2004 12:34:39 GMT
Hi Timo,

> > Are you saying that you want something that has the function of the
> > #parse directive and the (View)RenderTool combined?  
> Yes, I think so. 
Picky, picky, picky... ;)

> Parse just asks the loader(s) to go find "thingy.vm", right? 
I guess so.

> Normally, this might be found using a file rsrc or webapp rsrc loader,
> perhaps a third loader in the chain might go looking inside the
> Request/Session/App bags?
Okay, then how about this:
1. Create a ResourceLoader that does something like RenderTool.
2. Add it to the ResourceLoader stack.
This way, anything that's not found in the other loaders will be parsed
as VTL.

I think a quick-fix should look something like
public class TimoResourceLoader extends ResourceLoader
{
public abstract InputStream getResourceStream( String source ) 
    throws ResourceNotFoundException
{
    String template = "$render.recurse(${" + source + "})";
    return new ByteArrayInputStream(template.getBytes());
}
}
# Actually, since the loader doesn't have any reference to the context,
# this is the best I can think of...

> Or maybe there is a way to have *.var trigger the custom resource loader?
None that I know of.

> > Why not just put the contents of "A.THINGY" in a template file and
> > always use #parse?
> Because the template of A.THINGY will be variable, possibly from a database,
> or possibly from a form input (think real-time render).
Picky, picky, picky... ;)

OR, of course, you can make a cool tool that does all this stuff for you.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai(shinobu.kawai@gmail.com)

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message