Class VelocimacroProxy
- java.lang.Object
-
- org.apache.velocity.runtime.directive.Directive
-
- org.apache.velocity.runtime.directive.VelocimacroProxy
-
- All Implemented Interfaces:
java.lang.Cloneable
,DirectiveConstants
public class VelocimacroProxy extends Directive
VelocimacroProxy.java a proxy Directive-derived object to fit with the current directive system- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
bodyReference
private boolean
enableBCmode
private java.lang.String[]
literalArgArray
private java.util.List<Macro.MacroArg>
macroArgs
private java.lang.String
macroName
private int
maxCallDepth
private SimpleNode
nodeTree
private static java.lang.Object
NULL_VALUE_MARKER
private int
numMacroArgs
private boolean
strictArguments
-
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
-
-
Constructor Summary
Constructors Constructor Description VelocimacroProxy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkArgumentCount(Node node, int callArgNum)
Check whether the number of arguments given matches the number defined.protected void
checkDepth(InternalContextAdapter context)
check that we aren't already at the max call depth and throws a MacroOverflowException if we are there.java.util.List<Macro.MacroArg>
getMacroArgs()
Return the list of macro arguments associated with this macrojava.lang.String
getName()
Return name of this Velocimacro.int
getNumArgs()
returns the number of ars needed for this VMint
getType()
Velocimacros are always LINE type directives.protected java.lang.Object[]
handleArgValues(InternalContextAdapter context, Node node, int callArgNum)
Gets the macro argument values and puts them in the context under the argument names.void
init(RuntimeServices rs)
Initialize members of VelocimacroProxy.boolean
render(InternalContextAdapter context, java.io.Writer writer, Node node)
Render the macro AST nodeboolean
render(InternalContextAdapter context, java.io.Writer writer, Node node, Renderable body)
Renders the macro using the context.void
setMacroArgs(java.util.List<Macro.MacroArg> args)
sets the array of arguments specified in the macro definitionvoid
setName(java.lang.String name)
sets the directive name of this VMvoid
setNodeTree(SimpleNode tree)
-
Methods inherited from class org.apache.velocity.runtime.directive.Directive
checkArgs, getColumn, getLine, getScopeName, getTemplate, getTemplateName, init, isScopeProvided, makeScope, postRender, preRender, setLocation, setLocation
-
-
-
-
Field Detail
-
macroName
private java.lang.String macroName
-
macroArgs
private java.util.List<Macro.MacroArg> macroArgs
-
literalArgArray
private java.lang.String[] literalArgArray
-
nodeTree
private SimpleNode nodeTree
-
numMacroArgs
private int numMacroArgs
-
strictArguments
private boolean strictArguments
-
maxCallDepth
private int maxCallDepth
-
bodyReference
private java.lang.String bodyReference
-
enableBCmode
private boolean enableBCmode
-
NULL_VALUE_MARKER
private static final java.lang.Object NULL_VALUE_MARKER
-
-
Method Detail
-
getName
public java.lang.String getName()
Return name of this Velocimacro.
-
getType
public int getType()
Velocimacros are always LINE type directives.
-
setName
public void setName(java.lang.String name)
sets the directive name of this VM- Parameters:
name
-
-
setMacroArgs
public void setMacroArgs(java.util.List<Macro.MacroArg> args)
sets the array of arguments specified in the macro definition- Parameters:
args
- Array of macro arguments, containing the #macro() arguments and default values. the 0th is the name.
-
getMacroArgs
public java.util.List<Macro.MacroArg> getMacroArgs()
Return the list of macro arguments associated with this macro- Returns:
- macro arguments
-
setNodeTree
public void setNodeTree(SimpleNode tree)
- Parameters:
tree
-
-
getNumArgs
public int getNumArgs()
returns the number of ars needed for this VM- Returns:
- The number of ars needed for this VM
-
init
public void init(RuntimeServices rs)
Initialize members of VelocimacroProxy. called from MacroEntry- Parameters:
rs
- runtime services
-
render
public boolean render(InternalContextAdapter context, java.io.Writer writer, Node node) throws java.io.IOException
Render the macro AST node
-
render
public boolean render(InternalContextAdapter context, java.io.Writer writer, Node node, Renderable body) throws java.io.IOException
Renders the macro using the context.- Parameters:
context
- Current rendering contextwriter
- Writer for outputnode
- AST that calls the macrobody
- the macro body- Returns:
- true if the directive rendered successfully.
- Throws:
java.io.IOException
-
checkArgumentCount
protected void checkArgumentCount(Node node, int callArgNum)
Check whether the number of arguments given matches the number defined.- Parameters:
node
-callArgNum
-
-
checkDepth
protected void checkDepth(InternalContextAdapter context)
check that we aren't already at the max call depth and throws a MacroOverflowException if we are there.- Parameters:
context
-
-
handleArgValues
protected java.lang.Object[] handleArgValues(InternalContextAdapter context, Node node, int callArgNum)
Gets the macro argument values and puts them in the context under the argument names. Store and return an array of old and new values paired for each argument name, for later cleanup. Also, put literal representations of arguments which evaluate to null in the context.- Parameters:
context
-node
-callArgNum
-- Returns:
- macro arguments values
-
-