/// <summary> Used by Parser.java to process VMs during the parsing process. /// /// 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. /// </summary> /// <param name="rs"> /// </param> /// <param name="t"> /// </param> /// <param name="node"> /// </param> /// <param name="sourceTemplate"> /// </param> /// <throws> IOException </throws> /// <throws> ParseException </throws> public static void ProcessAndRegister(IRuntimeServices rs, Token t, INode node, string sourceTemplate) { /* * There must be at least one arg to #macro, * the name of the VM. Note that 0 following * args is ok for naming blocks of HTML */ int numArgs = node.GetNumChildren(); /* * this number is the # of args + 1. The + 1 * is for the block tree */ if (numArgs < 2) { /* * Error - they didn't name the macro or * define a block */ rs.Log.Error("#macro error : Velocimacro must have name as 1st " + "argument to #macro(). #args = " + numArgs); throw new MacroParseException("First argument to #macro() must be " + " macro name.", sourceTemplate, t); } /* * lets make sure that the first arg is an ASTWord */ int firstType = node.GetChild(0).Type; if (firstType != NVelocity.Runtime.Parser.ParserTreeConstants.JJTWORD) { throw new MacroParseException("First argument to #macro() must be a" + " token without surrounding \' or \", which specifies" + " the macro name. Currently it is a " + NVelocity.Runtime.Parser.ParserTreeConstants.jjtNodeName[firstType], sourceTemplate, t); } // Get the arguments to the use of the VM - element 0 contains the macro name string[] argArray = GetArgArray(node, rs); /* * we already have the macro parsed as AST so there is no point to * transform it into a String again */ rs.AddVelocimacro(argArray[0], node.GetChild(numArgs - 1), argArray, sourceTemplate); /* * Even if the Add attempt failed, we don't Log anything here. * Logging must be done at VelocimacroFactory or VelocimacroManager because * those classes know the real reason. */ }
public static void ProcessAndRegister(IRuntimeServices rs, Token t, INode node, string sourceTemplate) { int numChildren = node.GetNumChildren(); if (numChildren < 2) { rs.Log.Error("#macro error : Velocimacro must have name as 1st argument to #macro(). #args = " + numChildren); throw new MacroParseException("First argument to #macro() must be macro name.", sourceTemplate, t); } int type = node.GetChild(0).Type; if (type != 9) { throw new MacroParseException("First argument to #macro() must be a token without surrounding ' or \", which specifies the macro name. Currently it is a " + ParserTreeConstants.jjtNodeName[type], sourceTemplate, t); } string[] argArray = Macro.GetArgArray(node, rs); rs.AddVelocimacro(argArray[0], node.GetChild(numChildren - 1), argArray, sourceTemplate); }
public static void processAndRegister(IRuntimeServices rs, INode node, string sourceTemplate) { int childrenCount = node.ChildrenCount; if (childrenCount < 2) { rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()"); } else { string[] argArray = Macro.getArgArray(node); IList aSTAsStringArray = Macro.getASTAsStringArray(node.GetChild(childrenCount - 1)); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < aSTAsStringArray.Count; i++) { stringBuilder.Append(aSTAsStringArray[i]); } string macro = stringBuilder.ToString(); rs.AddVelocimacro(argArray[0], macro, argArray, sourceTemplate); } }
/// <summary> /// Used by Parser.java to process VMs within 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 /// </summary> public static void processAndRegister(IRuntimeServices rs, INode node, String sourceTemplate) { // There must be at least one arg to #macro, // the name of the VM. Note that 0 following // args is ok for naming blocks of HTML int numArgs = node.ChildrenCount; // this number is the # of args + 1. The + 1 // is for the block tree if (numArgs < 2) { // error - they didn't name the macro or // define a block rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()"); return; } // get the arguments to the use of the VM String[] argArray = getArgArray(node); // now, try and eat the code block. Pass the root. IList macroArray = getASTAsStringArray(node.GetChild(numArgs - 1)); // make a big string out of our macro StringBuilder temp = new StringBuilder(); for (int i = 0; i < macroArray.Count; i++) { temp.Append(macroArray[i]); } String macroBody = temp.ToString(); // now, try to add it. The Factory controls permissions, // so just give it a whack... rs.AddVelocimacro(argArray[0], macroBody, argArray, sourceTemplate); return; }
/// <summary> /// Used by Parser.java to process VMs within 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 /// </summary> public static void processAndRegister(IRuntimeServices rs, INode node, String sourceTemplate) { // There must be at least one arg to #macro, // the name of the VM. Note that 0 following // args is ok for naming blocks of HTML int numArgs = node.ChildrenCount; // this number is the # of args + 1. The + 1 // is for the block tree if (numArgs < 2) { // error - they didn't name the macro or // define a block rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()"); return; } // get the arguments to the use of the VM String[] argArray = getArgArray(node); // now, try and eat the code block. Pass the root. IList macroArray = getASTAsStringArray(node.GetChild(numArgs - 1)); // make a big string out of our macro StringBuilder temp = new StringBuilder(); for(int i = 0; i < macroArray.Count; i++) { temp.Append(macroArray[i]); } String macroBody = temp.ToString(); // now, try to add it. The Factory controls permissions, // so just give it a whack... rs.AddVelocimacro(argArray[0], macroBody, argArray, sourceTemplate); return; }