geirm 01/06/18 20:33:31
Modified: src/java/org/apache/velocity/runtime/directive
VMProxyArg.java VelocimacroProxy.java
Log:
VMProxyArg : changed and removed the special case for backwards compatibility
so #if() will work correctly - it will return a null as value when null, rather
than that cute nonsense for backwards compatibility.
VelocimacroProxy : change the init sequence to include sending a
VMReferenceMungeVisitor down through the tree to enable the reference
to print correctly if null in the VM.
Revision Changes Path
1.8 +1 -29
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
Index: VMProxyArg.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- VMProxyArg.java 2001/04/22 18:14:15 1.7
+++ VMProxyArg.java 2001/06/19 03:33:30 1.8
@@ -113,7 +113,7 @@
* into a local context.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: VMProxyArg.java,v 1.7 2001/04/22 18:14:15 geirm Exp $
+ * @version $Id: VMProxyArg.java,v 1.8 2001/06/19 03:33:30 geirm Exp $
*/
public class VMProxyArg
{
@@ -303,34 +303,6 @@
retObject = nodeTree.execute( null, context);
}
-
- /*
- * If this resolves to null, we need just the literal
representation of it
- * to support the 'cut-and-paste' features of VMs
- *
- * There are reasons why people do this, although why they can't
solve it
- * with some other method...
- *
- * Note that we lose a current feature of VMs, rendering the
literal of the
- * original calling arg. This needs to be fixed or we live with
it.
- *
- * below, what we do is technically wrong. Will revisit.
- */
-
- if( retObject == null && numTreeChildren > 0)
- {
- try
- {
- StringWriter writer = new StringWriter() ;
- nodeTree.render( context, writer );
-
- retObject = writer.toString();
- }
- catch (Exception e )
- {
- Runtime.error("VMProxyArg.getObject() : error rendering
reference : " + e );
- }
- }
}
else if( type == ParserTreeConstants.JJTOBJECTARRAY )
{
1.23 +45 -7
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- VelocimacroProxy.java 2001/06/12 03:20:36 1.22
+++ VelocimacroProxy.java 2001/06/19 03:33:30 1.23
@@ -69,6 +69,7 @@
import org.apache.velocity.context.VMContext;
import org.apache.velocity.context.Context;
+import org.apache.velocity.runtime.visitor.VMReferenceMungeVisitor;
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.Token;
@@ -82,7 +83,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.22 2001/06/12 03:20:36 geirm Exp $
+ * @version $Id: VelocimacroProxy.java,v 1.23 2001/06/19 03:33:30 geirm Exp $
*/
public class VelocimacroProxy extends Directive
{
@@ -97,8 +98,8 @@
private String[] callingArgs;
private int[] callingArgTypes;
private HashMap proxyArgHash = new HashMap();
- private HashMap keyMap = new HashMap();
+
/**
* Return name of this Velocimacro.
*/
@@ -233,9 +234,6 @@
public void init( InternalContextAdapter context, Node node)
throws Exception
{
- // Runtime.info("VMProxy:init() : calling for " + macroName + " with
namespace : " + namespace
- // + " curr templ : " + context.getCurrentTemplateName() );
-
/*
* how many args did we get?
*/
@@ -245,6 +243,7 @@
/*
* right number of args?
*/
+
if ( getNumArgs() != i )
{
Runtime.error("VM #" + macroName + ": error : too few arguments to
macro. Wanted "
@@ -266,10 +265,14 @@
return;
}
+ /**
+ * basic VM setup. Sets up the proxy args for this
+ * use, and parses the tree
+ */
public boolean setupMacro( String[] callArgs, int[] callArgTypes )
{
setupProxyArgs( callArgs, callArgTypes );
- parseTree();
+ parseTree( callArgs );
return true;
}
@@ -278,7 +281,7 @@
* parses the macro. We need to do this here, at init time, or else
* the local-scope template feature is hard to get to work :)
*/
- private void parseTree()
+ private void parseTree( String[] callArgs )
{
try
{
@@ -289,6 +292,41 @@
*/
nodeTree = Runtime.parse( br, namespace, false );
+
+ /*
+ * now, to make null references render as proper schmoo
+ * we need to tweak the tree and change the literal of
+ * the appropriate references
+ *
+ * we only do this at init time, so it's the overhead
+ * is irrelevant
+ */
+
+ HashMap hm = new HashMap();
+
+ for( int i = 1; i < argArray.length; i++)
+ {
+ String arg = callArgs[i-1];
+
+ /*
+ * if the calling arg is indeed a reference
+ * then we add to the map. We ignore other
+ * stuff
+ */
+
+ if (arg.charAt(0) == '$')
+ {
+ hm.put( argArray[i], arg );
+ }
+ }
+
+ /*
+ * now make one of our reference-munging visitor, and
+ * let 'er rip
+ */
+
+ VMReferenceMungeVisitor v = new VMReferenceMungeVisitor( hm );
+ nodeTree.jjtAccept( v, null );
}
catch ( Exception e )
{