Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Labels:None
-
Number of attachments :
Description
The jelly scripts could be cached, improving the performance of plugins using the JellyTemplateEngine:
Index: src/main/java/org/generama/JellyTemplateEngine.java
===================================================================
RCS file: /home/projects/generama/scm/generama/src/main/java/org/generama/JellyTemplateEngine.java,v
retrieving revision 1.2
diff -u -r1.2 JellyTemplateEngine.java
— src/main/java/org/generama/JellyTemplateEngine.java 16 Jan 2005 13:40:48 -0000 1.2
+++ src/main/java/org/generama/JellyTemplateEngine.java 18 Oct 2005 20:42:11 -0000
@@ -2,6 +2,7 @@
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.XMLOutput;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXContentHandler;
@@ -10,6 +11,8 @@
import org.xml.sax.SAXException;
import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -21,7 +24,8 @@
public class JellyTemplateEngine extends AbstractTemplateEngine implements TemplateEngine {
private boolean supressdeclaration = false;
private boolean expandEmpty = false;
-
+ private Map scriptByUrl = new HashMap();
+
public final void generate(Writer out, Map contextObjects, String encoding, Class pluginClass) throws GeneramaException {
JellyContext context = new GeneramaJellyContext();
Set keys = contextObjects.keySet();
@@ -48,7 +52,14 @@
try {
xmlOutput.startDocument();
- context.runScript(getScriptURL(pluginClass, ".jelly"), xmlOutput);
+
+ URL scriptURL = getScriptURL(pluginClass, ".jelly");
+ Script script = (Script) scriptByUrl.get(scriptURL);
+ if (script == null) { + script = context.compileScript(scriptURL); + scriptByUrl.put(scriptURL, script); + }+ script.run(context, xmlOutput);
xmlOutput.endDocument();
xmlWriter.write(saxHandler.getDocument());
xmlWriter.flush();
This doesn't solve the caching of (inner)called scripts.
I've looked there a couple weeks ago, i made some beta testing, but i then gave up.
Such feature should be a combination of caching at JellyTemplateEngine and at jelly context, and
assuming Script isn't mutable.
Maybe that's worth looking.