i had the same problem and i solved it by caching the SimpleNodes which are produced by the parse method. i didn't profile my application so i don't know if it really works well and it might be a quite stupid way, i hadn't time to look at it properly.

private Map<String, SimpleNode> rootNodesCache = new HashMap<String, SimpleNode>(); public SimpleNode getRootNodeFor(String template, RuntimeInstance runtimeInstance) {

       SimpleNode sn = rootNodesCache.get(template);

       if(sn == null) {
           try {
               Reader reader = new StringReader(template);
               sn = runtimeInstance.parse(reader, tag);

               rootNodesCache.put( template, sn);
           } catch(ParseException e) {
logger.error("VelocityException for template '" + value + "' :" + e.getMessage());
           }
       }
       return sn;
}


Xavier Noria wrote:

I am writing an application that needs a couple of functionalities I don't see in the developer's manual.

On the one hand I have snippets of templates in a XML file. I've read Velocity.evaluate() can instantiate them, but I would prefer to have a "precompiled" Template object (I'm new to Velocity and I am in fact assuming an object of type Template is a precompiled template). Is that possible or should I need to write my own StringReso

On the other hand, looks like there is no direct way to create Template objects given an absolute path, except by computing its dirname, setting it as template root dir, then load the basename as relative path. I've seen another workaround which consists of setting the root dir to the empty string. Isn't there a more convinient way like a simple method call?

-- fxn



---------------------------------------------------------------------
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