geirm 00/11/25 07:12:51
Modified: src/java/org/apache/velocity/runtime/directive
VelocimacroProxy.java
Log:
Moved the created VM AST init() to render() to allow recursive macro definitions
such as :
#macro( foo $a )
#set $a = $a - 1
#if ($a > 0)
#foo($a)
#end
#end
Revision Changes Path
1.5 +30 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Index: VelocimacroProxy.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- VelocimacroProxy.java 2000/11/24 23:35:57 1.4
+++ VelocimacroProxy.java 2000/11/25 15:12:51 1.5
@@ -58,7 +58,7 @@
* a proxy Directive-derived object to fit with the current directive system
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: VelocimacroProxy.java,v 1.4 2000/11/24 23:35:57 jon Exp $
+ * @version $Id: VelocimacroProxy.java,v 1.5 2000/11/25 15:12:51 geirm Exp $
*/
package org.apache.velocity.runtime.directive;
@@ -88,6 +88,8 @@
private TreeMap tmArgIndexMap_ = null;
private SimpleNode nodeTree_ = null;
+ private boolean bInit_ = false;
+
public String getName() { return strMacroName_; }
public int getType() { return LINE; }
@@ -145,7 +147,29 @@
try
{
if (nodeTree_ != null)
+ {
+ /*
+ * to allow recursive VMs, we want to init them at render time,
not init time
+ * or else you wander down the VM calls forever.
+ *
+ * need a context clone() here so we don't modify the real
context, as we do the
+ * actions on stuff for introspection purposes (ex #set $a = $a -
1...)
+ *
+ * I am not happy about this and performance, but to get jon going
again with anakia,
+ * this will do for now
+ */
+
+ if (!bInit_)
+ {
+ Context ctxt = (Context) context.clone();
+
+ nodeTree_.init( ctxt, null );
+ bInit_ = true;
+ ctxt = null;
+ }
+
nodeTree_.render(context, writer );
+ }
else
Runtime.error( "VM error : " + strMacroName_ + ". Null AST");
}
@@ -214,7 +238,11 @@
ByteArrayInputStream inStream = new ByteArrayInputStream(
strExpanded.toString().getBytes() );
nodeTree_ = Runtime.parse( inStream );
- nodeTree_.init( context, null );
+
+ /*
+ * moved the init() down to render() to prevent problems with
recursive VMs
+ */
+ // nodeTree_.init( context, null );
}
catch ( Exception e )
{