Author: dlr
Date: Mon Sep 26 23:45:26 2005
New Revision: 291831
URL: http://svn.apache.org/viewcvs?rev=291831&view=rev
Log:
Documentation and logging improvements.
* src/java/org/apache/velocity/runtime/directive/Macro.java
(processAndRegister): Improved JavaDoc. Updated arguments for call to
getArgArray(). Instead of ignoring the return value of
RuntimeServices.addVleocimacro(), provide a warning message if the return
value indicates that the Velocimacro was not added.
(getArgArray): Improved JavaDoc. Added a RuntimeServices to allow for
logging, and delegate to the new formatArgArray() method with it when in
debugMode.
(formatArgArray): A new method for generating debug messages.
Modified:
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
Modified:
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
URL:
http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java?rev=291831&r1=291830&r2=291831&view=diff
==============================================================================
---
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
(original)
+++
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
Mon Sep 26 23:45:26 2005
@@ -101,12 +101,14 @@
}
/**
- * Used by Parser.java to process VMs withing the parsing process
+ * Used by Parser.java to process VMs during the parsing process.
*
- * processAndRegister() doesn't actually render the macro to the output
- * Processes the macro body into the internal representation used by the
- * VelocimacroProxy objects, and if not currently used, adds it
- * to the macro Factory
+ * This method does not render the macro to the output stream,
+ * but rather <i>processes the macro body</i> into the internal
+ * representation used by {#link
+ * org.apache.velocity.runtime.directive.VelocimacroProxy}
+ * objects, and if not currently used, adds it to the macro
+ * Factory.
*/
public static void processAndRegister(RuntimeServices rs, Node node,
String sourceTemplate)
@@ -158,7 +160,7 @@
* get the arguments to the use of the VM
*/
- String argArray[] = getArgArray(node);
+ String argArray[] = getArgArray(node, rs);
/*
* now, try and eat the code block. Pass the root.
@@ -183,25 +185,35 @@
* so just give it a whack...
*/
- rs.addVelocimacro(argArray[0], macroBody.toString(),
- argArray, sourceTemplate);
-
- return;
+ boolean macroAdded = rs.addVelocimacro(argArray[0],
+ macroBody.toString(),
+ argArray, sourceTemplate);
+ if (!macroAdded)
+ {
+ rs.warn("Failed to add macro " +
+ formatArgArray(new StringBuffer(), argArray) +
+ " from '" + sourceTemplate + '\'');
+ }
}
/**
- * creates an array containing the literal
- * strings in the macro arguement
+ * Creates an array containing the literal text from the macro
+ * arguement(s) (including the macro's name as the first arg).
+ *
+ * @param node The parse node from which to grok the argument
+ * list. It's expected to include the block node tree (for the
+ * macro body).
+ * @param rsvc For debugging purposes only.
*/
- private static String[] getArgArray(Node node)
+ private static String[] getArgArray(Node node, RuntimeServices rsvc)
{
/*
- * remember : this includes the block tree
+ * Get the number of arguments for the macro, excluding the
+ * last child node which is the block tree containing the
+ * macro body.
*/
-
int numArgs = node.jjtGetNumChildren();
-
numArgs--; // avoid the block tree...
String argArray[] = new String[numArgs];
@@ -235,15 +247,11 @@
if (debugMode)
{
- System.out.println("Macro.getArgArray() : #args = " + numArgs);
- System.out.print(argArray[0] + "(");
-
- for (i = 1; i < numArgs; i++)
- {
- System.out.print(" " + argArray[i]);
- }
-
- System.out.println(" )");
+ StringBuffer msg = new StringBuffer();
+ msg.append("Macro.getArgArray() : nbrArgs=" + numArgs);
+ msg.append(" : ");
+ formatArgArray(msg, argArray);
+ rsvc.debug(msg.toString());
}
return argArray;
@@ -284,5 +292,21 @@
list.add(NodeUtils.tokenLiteral(t));
return list;
+ }
+
+ /**
+ * For debugging purposes. Formats the arguments from
+ * <code>argArray</code> and appends them to <code>buf</code>.
+ */
+ private static StringBuffer formatArgArray(StringBuffer buf,
+ String[] argArray)
+ {
+ buf.append(argArray[0]).append('(');
+ for (int i = 1; i < argArray.length; i++)
+ {
+ buf.append(' ').append(argArray[i]);
+ }
+ buf.append(" )");
+ return buf;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]