Class Macro
- java.lang.Object
-
- org.apache.velocity.runtime.directive.Directive
-
- org.apache.velocity.runtime.directive.Macro
-
- All Implemented Interfaces:
Cloneable,DirectiveConstants
public class Macro extends Directive
Macro implements the macro definition directive of VTL. example: #macro( isnull $i ) #if( $i ) $i #end #end This object is used at parse time to mainly process and register the macro. It is used inline in the parser when processing a directive.- Version:
- $Id$
- Author:
- Geir Magnusson Jr., Henning P. Schmiedehausen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMacro.MacroArgMacroArgs holds the information for a single argument in a macro definition.
-
Constructor Summary
Constructors Constructor Description Macro()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckArgs(ArrayList<Integer> argtypes, Token t, String templateName)Check the argument types of a macro call, called by the parser to do validationStringgetName()Return name of this directive.intgetType()Return type of this directive.voidinit(RuntimeServices rs, InternalContextAdapter context, Node node)How this directive is to be initialized.booleanisScopeProvided()Since this class does no processing of content, there is never a need for an internal scope.static StringBuildermacroToString(StringBuilder buf, List<Macro.MacroArg> macroArgs, RuntimeServices rsvc)For debugging purposes.booleanrender(InternalContextAdapter context, Writer writer, Node node)render() doesn't do anything in the final output rendering.-
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, getScopeName, getTemplate, getTemplateName, makeScope, postRender, preRender, setLocation, setLocation
-
-
-
-
Method Detail
-
getName
public String getName()
Return name of this directive.
-
getType
public int getType()
Return type of this directive.
-
isScopeProvided
public boolean isScopeProvided()
Since this class does no processing of content, there is never a need for an internal scope.- Overrides:
isScopeProvidedin classDirective- Returns:
- true if there will be a scope control injected into the context when rendering this directive.
-
render
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException
render() doesn't do anything in the final output rendering. There is no output from a #macro() directive.- Specified by:
renderin classDirective- Parameters:
context-writer-node-- Returns:
- True if the directive rendered successfully.
- Throws:
IOException
-
init
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException
Description copied from class:DirectiveHow this directive is to be initialized.
-
checkArgs
public void checkArgs(ArrayList<Integer> argtypes, Token t, String templateName) throws ParseException
Check the argument types of a macro call, called by the parser to do validation- Overrides:
checkArgsin classDirective- Parameters:
argtypes- type, Array of argument types of each argument to the directive for example StandardParserTreeConstants.JJTWORDt- token of directivetemplateName- the name of the template this directive is referenced in.- Throws:
ParseException
-
macroToString
public static StringBuilder macroToString(StringBuilder buf, List<Macro.MacroArg> macroArgs, RuntimeServices rsvc)
For debugging purposes. Formats the arguments fromargArrayand appends them tobuf.- Parameters:
buf- A StringBuilder. If null, a new StringBuilder is allocated.macroArgs- Array of macro arguments, containing the #macro() arguments and default values. the 0th is the name.- Returns:
- A StringBuilder containing the formatted arguments. If a StringBuilder has passed in as buf, this method returns it.
- Since:
- 1.5
-
-