nbubna 2004/11/10 22:18:33
Modified: src/java/org/apache/velocity/tools/generic RenderTool.java
Log:
add support for using this with a VelocityEngine instead of the singleton
(bug #31287)
Revision Changes Path
1.9 +21 -7
jakarta-velocity-tools/src/java/org/apache/velocity/tools/generic/RenderTool.java
Index: RenderTool.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/generic/RenderTool.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RenderTool.java 10 Nov 2004 20:17:17 -0000 1.8
+++ RenderTool.java 11 Nov 2004 06:18:32 -0000 1.9
@@ -20,6 +20,7 @@
import java.io.StringWriter;
import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
@@ -75,13 +76,18 @@
public class RenderTool
{
+ private static final String LOG_TAG = "RenderTool.eval()";
+
+ private VelocityEngine engine = null;
+
/**
- * Constructs a new instance
+ * Allow user to specify a VelocityEngine to be used
+ * in place of the Velocity singleton.
*/
- public RenderTool()
- {}
-
- private static final String LOG_TAG = "RenderTool.eval()";
+ public void setVelocityEngine(VelocityEngine ve)
+ {
+ this.engine = ve;
+ }
/**
* <p>Evaluates a String containing VTL using the current context,
@@ -101,7 +107,15 @@
return null;
}
StringWriter sw = new StringWriter();
- boolean success = Velocity.evaluate(ctx, sw, LOG_TAG, vtl);
+ boolean success;
+ if (engine == null)
+ {
+ success = Velocity.evaluate(ctx, sw, LOG_TAG, vtl);
+ }
+ else
+ {
+ success = engine.evaluate(ctx, sw, LOG_TAG, vtl);
+ }
if (success)
{
return sw.toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]