From: Alex Twisleton-Wykeham-F. <al...@fi...> - 2005-03-11 14:20:54
|
Last message (promise) :-) Here is a more efficient implementation:- package org.cord.node; import org.webmacro.*; import org.webmacro.engine.*; import org.webmacro.resource.*; public class EvaluatingTemplateLoader extends AbstractTemplateLoader { public final static String PROTOCOL = "evaluate:"; public void setConfig(String config) { } public Template load(String query, CacheElement ce) throws ResourceException { if (! query.startsWith(PROTOCOL)) { return null; } return new StringTemplate(broker, query.substring(PROTOCOL.length())); } } TemplateLoaderPath.1=evaluate: TemplateLoader.evaluate=org.cord.node.EvaluatingTemplateLoader #include as template "evaluate:<p>Hello, \$name</p>" This will now get invoked first of all out of the chain of TemplateLoaders and will rapidly discard any request that doesn't start with "evaluate:" thereby grabbing any requests as possible. The advantage with this is that the contents of the string that you are going to evaluate are going to change across a wide range of values. If the EvaluatingTemplateLoader is the last in the chain then all your default template loaders are going to have to scan their sources for each of your dynamic templates which will end up being very expensive. Hope this helps Alex |