Class ASTReference
- java.lang.Object
-
- org.apache.velocity.runtime.parser.node.SimpleNode
-
- org.apache.velocity.runtime.parser.node.ASTReference
-
- All Implemented Interfaces:
java.lang.Cloneable,Node,Renderable
public class ASTReference extends SimpleNode
This class is responsible for handling the references in VTL ($foo). Please look at the Parser.jjt file which is what controls the generation of this class.- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringalternateNullStringKeyprivate ASTExpressionastAlternateValuenon null Indicates that an alternate value has been providedprivate ASTIndexastIndexnon null Indicates if we are setting an index reference e.g, $foo[2], which basically means that the last syntax of the reference are brackets.private booleancheckEmptyprivate booleancomputableReferenceprivate booleanescapedprivate java.lang.StringescPrefixprivate static intFORMAL_REFERENCEprivate java.lang.Stringidentifierprivate booleanlogOnNullprivate booleanlookupAlternateLiteralprivate java.lang.StringmorePrefixprivate static intNORMAL_REFERENCEprivate java.lang.StringnullStringprivate intnumChildrenprivate static intQUIET_REFERENCEprivate intreferenceTypeprivate java.lang.StringrootStringprivate static intRUNTbooleanstrictEscapeIndicates if we are using modified escape behavior in strict mode.booleanstrictRefIndicates if we are running in strict reference mode.protected InfouberInfoprivate booleanwarnInvalidNullReferencesWhether to trigger an event for invalid null references, that is when a value is present in the context or parent object but is nullprivate booleanwarnInvalidQuietReferencesWhether to trigger an event for invalid quiet referencesprivate booleanwarnInvalidTestedReferencesWhether to trigger an event for invalid tested references - as in #if($foo)
-
Constructor Summary
Constructors Constructor Description ASTReference(int id)ASTReference(Parser p, int id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanevaluate(InternalContextAdapter context)Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not nulljava.lang.Objectexecute(java.lang.Object o, InternalContextAdapter context)gets an Object that 'is' the value of the referenceprivate java.lang.StringgetNullString(InternalContextAdapter context)This method helps to implement the "render literal if null" functionality.private java.lang.StringgetRoot()java.lang.StringgetRootString()Returns the 'root string', the reference keyjava.lang.ObjectgetRootVariableValue(InternalContextAdapter context)java.lang.Objectinit(InternalContextAdapter context, java.lang.Object data)java.lang.ObjectjjtAccept(StandardParserVisitor visitor, java.lang.Object data)static java.lang.StringprintClass(java.lang.Class<?> clazz)Utility class to handle nulls when printing a class typebooleanrender(InternalContextAdapter context, java.io.Writer writer)gets the value of the reference and outputs it to the writer.booleansetValue(InternalContextAdapter context, java.lang.Object value)Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()java.lang.Objectvalue(InternalContextAdapter context)-
Methods inherited from class org.apache.velocity.runtime.parser.node.SimpleNode
childrenAccept, cleanupParserAndTokens, clone, clone, dump, dump, dump, getColumn, getFirstToken, getFirstTokenImage, getInfo, getLastToken, getLastTokenImage, getLine, getLocation, getParser, getRuntimeServices, getTemplate, getTemplateName, getType, isInvalid, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, literal, saveTokenImages, setFirstToken, setInfo, setInvalid, toString, toString
-
-
-
-
Field Detail
-
NORMAL_REFERENCE
private static final int NORMAL_REFERENCE
- See Also:
- Constant Field Values
-
FORMAL_REFERENCE
private static final int FORMAL_REFERENCE
- See Also:
- Constant Field Values
-
QUIET_REFERENCE
private static final int QUIET_REFERENCE
- See Also:
- Constant Field Values
-
RUNT
private static final int RUNT
- See Also:
- Constant Field Values
-
referenceType
private int referenceType
-
nullString
private java.lang.String nullString
-
alternateNullStringKey
private java.lang.String alternateNullStringKey
-
rootString
private java.lang.String rootString
-
escaped
private boolean escaped
-
computableReference
private boolean computableReference
-
logOnNull
private boolean logOnNull
-
lookupAlternateLiteral
private boolean lookupAlternateLiteral
-
escPrefix
private java.lang.String escPrefix
-
morePrefix
private java.lang.String morePrefix
-
identifier
private java.lang.String identifier
-
checkEmpty
private boolean checkEmpty
-
strictRef
public boolean strictRef
Indicates if we are running in strict reference mode.
-
astIndex
private ASTIndex astIndex
non null Indicates if we are setting an index reference e.g, $foo[2], which basically means that the last syntax of the reference are brackets.
-
astAlternateValue
private ASTExpression astAlternateValue
non null Indicates that an alternate value has been provided
-
strictEscape
public boolean strictEscape
Indicates if we are using modified escape behavior in strict mode. mainly we allow \$abc -> to render as $abc
-
numChildren
private int numChildren
-
warnInvalidQuietReferences
private boolean warnInvalidQuietReferences
Whether to trigger an event for invalid quiet references- Since:
- 2.2
-
warnInvalidNullReferences
private boolean warnInvalidNullReferences
Whether to trigger an event for invalid null references, that is when a value is present in the context or parent object but is null- Since:
- 2.2
-
warnInvalidTestedReferences
private boolean warnInvalidTestedReferences
Whether to trigger an event for invalid tested references - as in #if($foo)- Since:
- 2.2
-
uberInfo
protected Info uberInfo
-
-
Constructor Detail
-
ASTReference
public ASTReference(int id)
- Parameters:
id-
-
ASTReference
public ASTReference(Parser p, int id)
- Parameters:
p-id-
-
-
Method Detail
-
jjtAccept
public java.lang.Object jjtAccept(StandardParserVisitor visitor, java.lang.Object data)
- Specified by:
jjtAcceptin interfaceNode- Overrides:
jjtAcceptin classSimpleNode- Returns:
- The Node execution result object.
- See Also:
SimpleNode.jjtAccept(org.apache.velocity.runtime.parser.node.StandardParserVisitor, java.lang.Object)
-
init
public java.lang.Object init(InternalContextAdapter context, java.lang.Object data) throws TemplateInitException
- Specified by:
initin interfaceNode- Overrides:
initin classSimpleNode- Returns:
- The init result.
- Throws:
TemplateInitException- See Also:
SimpleNode.init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
-
getRootString
public java.lang.String getRootString()
Returns the 'root string', the reference key- Returns:
- the root string.
-
execute
public java.lang.Object execute(java.lang.Object o, InternalContextAdapter context) throws MethodInvocationExceptiongets an Object that 'is' the value of the reference- Specified by:
executein interfaceNode- Overrides:
executein classSimpleNode- Parameters:
o- Object parameter, unused per se, but non-null by convention inside an #if/#elseif evaluationcontext- context used to generate value- Returns:
- The execution result.
- Throws:
MethodInvocationException- See Also:
Node.execute(java.lang.Object, org.apache.velocity.context.InternalContextAdapter)
-
render
public boolean render(InternalContextAdapter context, java.io.Writer writer) throws java.io.IOException, MethodInvocationException
gets the value of the reference and outputs it to the writer.- Specified by:
renderin interfaceNode- Specified by:
renderin interfaceRenderable- Overrides:
renderin classSimpleNode- Parameters:
context- context of data to use in getting valuewriter- writer to render to- Returns:
- True if rendering was successful.
- Throws:
java.io.IOExceptionMethodInvocationException- See Also:
Node.render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)
-
getNullString
private java.lang.String getNullString(InternalContextAdapter context)
This method helps to implement the "render literal if null" functionality. VelocimacroProxy saves references to macro arguments (AST nodes) so that if we have a macro #foobar($a $b) then there is key "$a.literal" which points to the literal presentation of the argument provided to variable $a. If the value of $a is null, we render the string that was provided as the argument.- Parameters:
context-- Returns:
-
evaluate
public boolean evaluate(InternalContextAdapter context) throws MethodInvocationException
Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not null- Specified by:
evaluatein interfaceNode- Overrides:
evaluatein classSimpleNode- Parameters:
context- context to compute value with- Returns:
- True if evaluation was ok.
- Throws:
MethodInvocationException- See Also:
Node.evaluate(org.apache.velocity.context.InternalContextAdapter)
-
value
public java.lang.Object value(InternalContextAdapter context) throws MethodInvocationException
- Specified by:
valuein interfaceNode- Overrides:
valuein classSimpleNode- Returns:
- The node value.
- Throws:
MethodInvocationException- See Also:
SimpleNode.value(org.apache.velocity.context.InternalContextAdapter)
-
printClass
public static java.lang.String printClass(java.lang.Class<?> clazz)
Utility class to handle nulls when printing a class type- Parameters:
clazz-- Returns:
- class name, or the string "null"
-
setValue
public boolean setValue(InternalContextAdapter context, java.lang.Object value) throws MethodInvocationException
Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()- Parameters:
context- context object containing this referencevalue- Object to set as value- Returns:
- true if successful, false otherwise
- Throws:
MethodInvocationException- See Also:
ASTSetDirective
-
getRoot
private java.lang.String getRoot()
-
getRootVariableValue
public java.lang.Object getRootVariableValue(InternalContextAdapter context)
- Parameters:
context-- Returns:
- The evaluated value of the variable.
- Throws:
MethodInvocationException
-
-