geirm 01/06/11 20:20:36
Modified: src/java/org/apache/velocity/runtime Runtime.java
VelocimacroManager.java
src/java/org/apache/velocity/runtime/directive
VelocimacroProxy.java
Log:
Runtime : added a second parse method to allow control over dumping the
vm namespace for a given template.
VelocimacroManager : added specification of namespace to VMProxy creation.
VMProxy : use proper namespace where the VM was declared, and also avoid dumping
the namespace when parsing the VM body
Revision Changes Path
1.111 +30 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
Index: Runtime.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- Runtime.java 2001/05/11 04:00:58 1.110
+++ Runtime.java 2001/06/12 03:20:35 1.111
@@ -141,7 +141,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jeff Bowden</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magusson Jr.</a>
- * @version $Id: Runtime.java,v 1.110 2001/05/11 04:00:58 geirm Exp $
+ * @version $Id: Runtime.java,v 1.111 2001/06/12 03:20:35 geirm Exp $
*/
public class Runtime implements RuntimeConstants
{
@@ -568,7 +568,7 @@
}
/**
- * Parse the input stream and return the root of
+ * Parse the input and return the root of
* AST node structure.
* <br><br>
* In the event that it runs out of parsers in the
@@ -585,6 +585,23 @@
public static SimpleNode parse( Reader reader, String templateName )
throws ParseException
{
+ /*
+ * do it and dump the VM namespace for this template
+ */
+ return parse( reader, templateName, true );
+ }
+
+ /**
+ * Parse the input and return the root of the AST node structure.
+ *
+ * @param InputStream inputstream retrieved by a resource loader
+ * @param String name of the template being parsed
+ * @param dumpNamespace flag to dump the Velocimacro namespace for this template
+ */
+ public static SimpleNode parse( Reader reader, String templateName, boolean
dumpNamespace )
+ throws ParseException
+ {
+
SimpleNode ast = null;
Parser parser = (Parser) parserPool.get();
boolean madeNew = false;
@@ -616,6 +633,17 @@
{
try
{
+ /*
+ * dump namespace if we are told to. Generally, you want to
+ * do this - you don't in special circumstances, such as
+ * when a VM is getting init()-ed & parsed
+ */
+
+ if ( dumpNamespace )
+ {
+ Runtime.dumpVMNamespace( templateName );
+ }
+
ast = parser.parse( reader, templateName );
}
finally
1.11 +12 -8
jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java
Index: VelocimacroManager.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- VelocimacroManager.java 2001/04/22 18:17:41 1.10
+++ VelocimacroManager.java 2001/06/12 03:20:35 1.11
@@ -84,7 +84,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jose Alberto Fernandez</a>
- * @version $Id: VelocimacroManager.java,v 1.10 2001/04/22 18:17:41 geirm Exp $
+ * @version $Id: VelocimacroManager.java,v 1.11 2001/06/12 03:20:35 geirm Exp $
*/
public class VelocimacroManager
{
@@ -118,7 +118,6 @@
*/
public boolean addVM(String vmName, String macroBody, String argArray[], String
namespace )
{
-
MacroEntry me = new MacroEntry( this, vmName, macroBody, argArray,
namespace );
if ( usingNamespaces( namespace ) )
@@ -151,6 +150,7 @@
*/
public VelocimacroProxy get( String vmName, String namespace )
{
+
if ( usingNamespaces( namespace ) )
{
Hashtable local = getNamespace( namespace, false );
@@ -162,9 +162,11 @@
if ( local != null)
{
MacroEntry me = (MacroEntry) local.get( vmName );
-
+
if (me != null)
- return me.createVelocimacro();
+ {
+ return me.createVelocimacro( namespace );
+ }
}
}
@@ -176,8 +178,10 @@
MacroEntry me = (MacroEntry) (getNamespace( GLOBAL_NAMESPACE )).get( vmName
);
if (me != null)
- return me.createVelocimacro();
-
+ {
+ return me.createVelocimacro( namespace );
+ }
+
return null;
}
@@ -337,14 +341,14 @@
return nodeTree;
}
- VelocimacroProxy createVelocimacro()
+ VelocimacroProxy createVelocimacro( String namespace )
{
VelocimacroProxy vp = new VelocimacroProxy();
vp.setName( this.macroname );
vp.setArgArray( this.argarray );
vp.setMacrobody( this.macrobody );
vp.setNodeTree( this.nodeTree);
-
+ vp.setNamespace( namespace );
return vp;
}
1.22 +18 -6
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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- VelocimacroProxy.java 2001/04/22 18:14:15 1.21
+++ VelocimacroProxy.java 2001/06/12 03:20:36 1.22
@@ -82,7 +82,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.21 2001/04/22 18:14:15 geirm Exp $
+ * @version $Id: VelocimacroProxy.java,v 1.22 2001/06/12 03:20:36 geirm Exp $
*/
public class VelocimacroProxy extends Directive
{
@@ -91,7 +91,8 @@
private String[] argArray = null;
private SimpleNode nodeTree = null;
private int numMacroArgs = 0;
-
+ private String namespace = "";
+
private boolean init = false;
private String[] callingArgs;
private int[] callingArgTypes;
@@ -161,6 +162,11 @@
macroBody = mb;
}
+ public void setNamespace( String ns )
+ {
+ this.namespace = ns;
+ }
+
/**
* Renders the macro using the context
*/
@@ -227,6 +233,9 @@
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?
*/
@@ -253,7 +262,7 @@
* now proxy each arg in the context
*/
- setupMacro( callingArgs, callingArgTypes);
+ setupMacro( callingArgs, callingArgTypes );
return;
}
@@ -271,12 +280,15 @@
*/
private void parseTree()
{
- // System.out.println("VMP.parseTree() : " + macroName );
-
try
{
BufferedReader br = new BufferedReader( new StringReader( macroBody ) );
- nodeTree = Runtime.parse( br, "VM:" + macroName );
+
+ /*
+ * now parse the macro - and don't dump the namespace
+ */
+
+ nodeTree = Runtime.parse( br, namespace, false );
}
catch ( Exception e )
{