You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jani <ka...@majorus.fi> on 2003/02/24 12:58:54 UTC
Macro reloading
Hey all,
I'm using Velocity embedded in my Java app. (See code below) Code is
called from a servlet. I'm using Tomcat on RH Linux. Velocity version is
1.3.1-rc2.
My problem is that macro reloading is not working. I have set
'velocimacro.library.autoreload' property as instructed in the
documentation. Nonetheless if I edit macros on my template, changes are
not visible until I restart Tomcat (or rename macros).
Any ideas? Thanks,
-Jani
--clip--
public class Template {
private static Logger log = Logger.getLogger(Template.class);
private static VelocityEngine ve = new VelocityEngine();
static {
String templatePath = Xcms.getProperty("system.base-dir") +
Xcms.getProperty("templates.base-dir");
log.debug("Setting templatePath = " + templatePath);
ve.setProperty("file.resource.loader.path", templatePath);
ve.setProperty("file.resource.loader.cache", "false");
ve.setProperty("velocimacro.library.autoreload", "true");
ve.setProperty("velocimacro.context.localscope", "true");
try {
ve.init();
} catch (Exception e) {
log.fatal("Init of VelocityEngine failed. Panic!", e);
}
}
public static org.dom4j.Document getTemplate (String fileName, HashMap contextObjects, boolean loadingFromFile) throws Exception {
contextObjects.put("constants", new Constants());
VelocityContext context = new VelocityContext();
if (contextObjects != null) {
Iterator cosKeys = contextObjects.keySet().iterator();
while (cosKeys.hasNext()) {
String key = (String) cosKeys.next();
context.put( key, contextObjects.get(key) );
}
}
org.apache.velocity.Template template = new org.apache.velocity.Template();
template = ve.getTemplate(fileName);
StringWriter sw = new StringWriter();
template.merge( context, sw );
Document doc = XMLUtils.parseText("<page-template>" + sw.toString() + "</page-template>");
return doc;
}
--clip---
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org