Re: A WM brain bender
Alex Twisleton-Wykeham-Fiennes <[email protected]>
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
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
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click