Class Directive
- java.lang.Object
-
- org.apache.velocity.runtime.directive.Directive
-
- All Implemented Interfaces:
java.lang.Cloneable
,DirectiveConstants
- Direct Known Subclasses:
Block
,Break
,Evaluate
,Foreach
,InputBase
,Macro
,RuntimeMacro
,Stop
,VelocimacroProxy
public abstract class Directive extends java.lang.Object implements DirectiveConstants, java.lang.Cloneable
Base class for all directives used in Velocity.- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private int
column
private int
line
protected org.slf4j.Logger
log
private boolean
provideScope
protected RuntimeServices
rsvc
private Template
template
-
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
-
-
Constructor Summary
Constructors Constructor Description Directive()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
checkArgs(java.util.ArrayList<java.lang.Integer> argtypes, Token t, java.lang.String templateName)
The Parser calls this method during template parsing to check the arguments types.int
getColumn()
for log msg purposesint
getLine()
for log msg purposesabstract java.lang.String
getName()
Return the name of this directive.java.lang.String
getScopeName()
Template
getTemplate()
returns the template in which this directive appearsjava.lang.String
getTemplateName()
abstract int
getType()
Get the directive type BLOCK/LINE.void
init(RuntimeServices rs, InternalContextAdapter context, Node node)
How this directive is to be initialized.boolean
isScopeProvided()
protected Scope
makeScope(java.lang.Object prev)
protected void
postRender(InternalContextAdapter context)
This cleans up any scope control for this directive after rendering, assuming the scope control was turned on.protected void
preRender(InternalContextAdapter context)
This creates and places the scope control for this directive into the context (if scope provision is turned on).abstract boolean
render(InternalContextAdapter context, java.io.Writer writer, Node node)
How this directive is to be renderedvoid
setLocation(int line, int column)
Allows the template location to be set.void
setLocation(int line, int column, Template template)
Allows the template location to be set.
-
-
-
Field Detail
-
line
private int line
-
column
private int column
-
provideScope
private boolean provideScope
-
template
private Template template
-
log
protected org.slf4j.Logger log
-
rsvc
protected RuntimeServices rsvc
-
-
Method Detail
-
getName
public abstract java.lang.String getName()
Return the name of this directive.- Returns:
- The name of this directive.
-
getType
public abstract int getType()
Get the directive type BLOCK/LINE.- Returns:
- The directive type BLOCK/LINE.
-
setLocation
public void setLocation(int line, int column)
Allows the template location to be set.- Parameters:
line
-column
-
-
setLocation
public void setLocation(int line, int column, Template template)
Allows the template location to be set.- Parameters:
line
-column
-template
-
-
getTemplate
public Template getTemplate()
returns the template in which this directive appears- Returns:
- template
-
getLine
public int getLine()
for log msg purposes- Returns:
- The current line for log msg purposes.
-
getColumn
public int getColumn()
for log msg purposes- Returns:
- The current column for log msg purposes.
-
getTemplateName
public java.lang.String getTemplateName()
- Returns:
- The template file name this directive was defined in, or null if not defined in a file.
-
getScopeName
public java.lang.String getScopeName()
- Returns:
- the name to be used when a scope control is provided for this directive.
-
isScopeProvided
public boolean isScopeProvided()
- Returns:
- true if there will be a scope control injected into the context when rendering this directive.
-
init
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException
How this directive is to be initialized.- Parameters:
rs
-context
-node
-- Throws:
TemplateInitException
-
checkArgs
public void checkArgs(java.util.ArrayList<java.lang.Integer> argtypes, Token t, java.lang.String templateName) throws ParseException
The Parser calls this method during template parsing to check the arguments types. Be aware that this method is called pre init, so not all data is available in this method. The default implementation does not peform any checking. We do this so that Custom directives do not trigger any parse errors in IDEs.- Parameters:
argtypes
- type, Array of argument types of each argument to the directive for example ParserTreeConstants.JJTWORDt
- token of directivetemplateName
- the name of the template this directive is referenced in.- Throws:
ParseException
-
render
public abstract boolean render(InternalContextAdapter context, java.io.Writer writer, Node node) throws java.io.IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException
How this directive is to be rendered- Parameters:
context
-writer
-node
-- Returns:
- True if the directive rendered successfully.
- Throws:
java.io.IOException
ResourceNotFoundException
ParseErrorException
MethodInvocationException
-
preRender
protected void preRender(InternalContextAdapter context)
This creates and places the scope control for this directive into the context (if scope provision is turned on).- Parameters:
context
-
-
makeScope
protected Scope makeScope(java.lang.Object prev)
- Parameters:
prev
-- Returns:
- scope
-
postRender
protected void postRender(InternalContextAdapter context)
This cleans up any scope control for this directive after rendering, assuming the scope control was turned on.- Parameters:
context
-
-
-