geirm 00/12/01 19:31:32
Modified: src/java/org/apache/velocity/runtime/directive
VelocimacroProxy.java
Log:
Small changes to support new Velocity tool for application support.
Revision Changes Path
1.10 +35 -15
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- VelocimacroProxy.java 2000/12/01 13:50:33 1.9
+++ VelocimacroProxy.java 2000/12/02 03:31:32 1.10
@@ -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.9 2000/12/01 13:50:33 geirm Exp $
+ * @version $Id: VelocimacroProxy.java,v 1.10 2000/12/02 03:31:32 geirm Exp $
*/
package org.apache.velocity.runtime.directive;
@@ -88,6 +88,7 @@
private String[] strMacroArray_ = null;
private TreeMap tmArgIndexMap_ = null;
private SimpleNode nodeTree_ = null;
+ private int iNumArgs_ = 0;
private boolean bInit_ = false;
@@ -122,9 +123,24 @@
public void setArgArray( String [] strArray )
{
strArgArray_ = strArray;
+
+ /*
+ * get the arg count from the arg array. remember that the arg array
+ * has the macro name as it's 0th element
+ */
+
+ iNumArgs_ = strArgArray_.length - 1;
}
/**
+ * returns the number of ars needed for this VM
+ */
+ public int getNumArgs()
+ {
+ return iNumArgs_;
+ }
+
+ /**
* sets the array of macro elements. (The macro body is an array of token
literals..)
* Currently, this isn't used in init or render, but keeping it around if
* someone needs it later.
@@ -205,24 +221,20 @@
public void init(Context context, Node node)
throws Exception
{
- /*
+ /*
* how many args did we get?
*/
int i = node.jjtGetNumChildren();
/*
- * get the arg count from the arg array. remember that the arg array
- * has the macro name as it's 0th element
- * if we don't have enough children specified...?
+ * right number of args?
*/
-
- int iArgCount = strArgArray_.length - 1;
- if ( iArgCount != i )
+ if ( getNumArgs() != i )
{
- Runtime.error("VM : error : too few arguments to macro. Wanted "
- + iArgCount + " got " + i + " -->");
+ Runtime.error("VM #" + strMacroName_ + ": error : too few arguments to
macro. Wanted "
+ + getNumArgs() + " got " + i + " -->");
return;
}
@@ -236,6 +248,19 @@
* now, expand our macro out to a string patched with the instance
arguments
*/
+ expandAndParse( strCallingArgs );
+
+ return;
+ }
+
+ /**
+ * takes an array of calling args, patches the VM and parses it.
+ * called by init() or callable alone if you know what you are doing.
+ *
+ * @param strCallingArgs array of reference literals
+ */
+ public void expandAndParse( String strCallingArgs[] )
+ {
StringBuffer strExpanded = expandMacroArray( strCallingArgs );
/*
@@ -253,11 +278,6 @@
ByteArrayInputStream inStream = new ByteArrayInputStream(
strExpanded.toString().getBytes() );
nodeTree_ = Runtime.parse( inStream );
-
- /*
- * moved the init() down to render() to prevent problems with
recursive VMs
- */
- // nodeTree_.init( context, null );
}
catch ( Exception e )
{