Class VelocimacroProxy
- java.lang.Object
-
- org.apache.velocity.runtime.directive.Directive
-
- org.apache.velocity.runtime.directive.VelocimacroProxy
-
- All Implemented Interfaces:
Cloneable
,DirectiveConstants
public class VelocimacroProxy extends Directive
VelocimacroProxy.java a proxy Directive-derived object to fit with the current directive system- Version:
- $Id$
- Author:
- Geir Magnusson Jr.
-
-
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.List<Macro.MacroArg>
getMacroArgs()
Return the list of macro arguments associated with this macroString
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 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, Writer writer, Node node)
Render the macro AST nodeboolean
render(InternalContextAdapter context, Writer writer, Node node, Renderable body)
Renders the macro using the context.void
setMacroArgs(List<Macro.MacroArg> args)
sets the array of arguments specified in the macro definitionvoid
setName(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
-
-
-
-
Method Detail
-
getName
public String getName()
Return name of this Velocimacro.
-
getType
public int getType()
Velocimacros are always LINE type directives.
-
setName
public void setName(String name)
sets the directive name of this VM- Parameters:
name
-
-
setMacroArgs
public void setMacroArgs(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 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, Writer writer, Node node) throws IOException
Render the macro AST node- Specified by:
render
in classDirective
- Parameters:
context
-writer
-node
-- Returns:
- success status
- Throws:
IOException
-
render
public boolean render(InternalContextAdapter context, Writer writer, Node node, Renderable body) throws 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:
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 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
-
-