public class TemplateEncoder
extends java.lang.Object
implements org.apache.velocity.util.ContextAware, org.apache.velocity.app.event.InvalidReferenceEventHandler, org.apache.velocity.app.event.ReferenceInsertionEventHandler, org.apache.velocity.app.event.NullSetEventHandler, java.io.Serializable
TemplateProcessor class.org.apache.velocity.app.event.InvalidReferenceEventHandler.InvalidGetMethodExecutor, org.apache.velocity.app.event.InvalidReferenceEventHandler.InvalidMethodExecutor, org.apache.velocity.app.event.InvalidReferenceEventHandler.InvalidSetMethodExecutor| Modifier and Type | Field and Description |
|---|---|
private static org.apache.log4j.Logger |
cvLogger
A reference to the Velocity log writer.
|
private int |
ivEncoderType
The encoder's type code.
|
private org.apache.velocity.context.InternalContextAdapter |
ivInternalContext
A reference to the Velocity internal context.
|
private java.util.ArrayList<java.lang.String> |
ivTemplateErrors
A collection of template error message text.
|
private static long |
serialVersionUID
The class' serialization version id.
|
static int |
TYPE_HTML
The type code for an html template encoder.
|
static int |
TYPE_TEXT
The type code for a text template encoder.
|
static int |
TYPE_XML
The type code for an xml template encoder.
|
| Constructor and Description |
|---|
TemplateEncoder(int type)
Constructs a template encoder for the given template type.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.ArrayList<java.lang.String> |
getTemplateErrors()
Returns the collection of template error message text.
|
java.lang.Object |
invalidGetMethod(org.apache.velocity.context.Context context,
java.lang.String reference,
java.lang.Object object,
java.lang.String property,
org.apache.velocity.util.introspection.Info info)
A call-back that is invoked during Velocity template processing.
|
java.lang.Object |
invalidMethod(org.apache.velocity.context.Context context,
java.lang.String reference,
java.lang.Object object,
java.lang.String method,
org.apache.velocity.util.introspection.Info info)
A call-back that is invoked during Velocity template processing.
|
boolean |
invalidSetMethod(org.apache.velocity.context.Context context,
java.lang.String leftreference,
java.lang.String rightreference,
org.apache.velocity.util.introspection.Info info)
A call-back that is invoked during Velocity template processing.
|
private boolean |
isDateFormatter(java.lang.String reference)
Answers if a reference is for a date or time formatter.
|
private boolean |
isHtmlExclusion(java.lang.String reference)
Answers if a reference should be excluded from html string encoding.
|
private boolean |
isHtmlJavaScript(java.lang.String reference)
Answers if a reference should be included in html script encoding.
|
private boolean |
isJDBCObjectReturned(java.lang.Object object,
java.lang.reflect.Method method)
Answers if an object is a JDBC object controller and if the method being
invoked on the controller returns a JDBC object.
|
private boolean |
isTextExclusion(java.lang.String reference)
Answers if a reference should be excluded from text string encoding.
|
private boolean |
isXmlExclusion(java.lang.String reference)
Answers if a reference should be excluded from xml string encoding.
|
private void |
logInvalidMethod(java.lang.String reference,
org.apache.velocity.util.introspection.Info info)
Writes a log entry to the Velocity log for an invalid reference.
|
private void |
logInvalidReference(java.lang.String reference,
org.apache.velocity.util.introspection.Info info)
Writes a log entry to the Velocity log for an invalid reference.
|
private void |
logNullInsertion(java.lang.String reference)
Writes a log entry to the Velocity log for a null value insertion.
|
java.lang.Object |
referenceInsert(java.lang.String reference,
java.lang.Object value)
A call-back that is invoked during Velocity template processing.
|
void |
setContext(org.apache.velocity.context.Context context)
Sets the Velocity internal context.
|
boolean |
shouldLogOnNullSet(java.lang.String lhs,
java.lang.String rhs)
A null reference in a #set directive should not log extra messages.
|
private static final long serialVersionUID
private static org.apache.log4j.Logger cvLogger
public static final int TYPE_HTML
public static final int TYPE_TEXT
public static final int TYPE_XML
private java.util.ArrayList<java.lang.String> ivTemplateErrors
private org.apache.velocity.context.InternalContextAdapter ivInternalContext
private int ivEncoderType
public TemplateEncoder(int type)
type - (int) The type of encoder to process. Must be one of
the TYPE_* constants defined by this class.public void setContext(org.apache.velocity.context.Context context)
setContext in ContextAware.setContext in interface org.apache.velocity.util.ContextAwarecontext - (Context) The internal context.public java.lang.Object invalidGetMethod(org.apache.velocity.context.Context context,
java.lang.String reference,
java.lang.Object object,
java.lang.String property,
org.apache.velocity.util.introspection.Info info)
invalidGetMethod in InvalidReferenceEventHandler.invalidGetMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandlercontext - (Context) The context when the invalid reference was
found.reference - (String) The complete invalid reference.object - (Object) The object referred to, or null if not
found.property - (String) The property name from the reference.info - (Info) Contains template, line and column details.null if no substitute.public boolean invalidSetMethod(org.apache.velocity.context.Context context,
java.lang.String leftreference,
java.lang.String rightreference,
org.apache.velocity.util.introspection.Info info)
invalidSetMethod in InvalidReferenceEventHandler.invalidSetMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandlercontext - (Context) The context when the invalid reference was
found.leftreference - (String) The left reference being assigned to.rightreference - (String) The invalid reference on the right.info - (Info) Contains template, line and column details.true then stop invoking invalidSetMethod
along the chain.public java.lang.Object invalidMethod(org.apache.velocity.context.Context context,
java.lang.String reference,
java.lang.Object object,
java.lang.String method,
org.apache.velocity.util.introspection.Info info)
Velocity seems to invoke this method for reasons other than what the
javadocs state, which indicate this method is invoked when object
or method don't exist. However, this method also seems to get
invoked when both object and method are valid but the
resulting return value is null. This implementation attempts to
determine if object or method really don't exist so false
errors don't get reported. It isn't possible to completely verify the
existence of method since parameter types aren't supplied and
therefore actual method signatures can't be checked, but most erroneous
errors can be eliminated by just determining that a method name exists.
invalidMethod in InvalidReferenceEventHandler.invalidMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandlercontext - (Context) The context when the invalid reference was
found.reference - (String) The complete invalid reference.object - (Object) The object referred to, or null if not
found.method - (String) The name of the (non-existent) method.info - (Info) Contains template, line and column details.null if no substitute.public java.lang.Object referenceInsert(java.lang.String reference,
java.lang.Object value)
referenceInsert in ReferenceInsertionEventHandler.referenceInsert in interface org.apache.velocity.app.event.ReferenceInsertionEventHandlerreference - (String) The reference from the template that is
about to be inserted.value - (Object) The value that is about to be inserted (after
its toString method is invoked).toString can be invoked
for output.public boolean shouldLogOnNullSet(java.lang.String lhs,
java.lang.String rhs)
shouldLogOnNullSet in interface org.apache.velocity.app.event.NullSetEventHandlerlhs - (String) The left reference being assigned to.rhs - (String) The invalid reference on the right.true If log message should be written.private boolean isDateFormatter(java.lang.String reference)
reference - (String) The reference from the template that is
about to be inserted.true if the reference is a date or time
formatter, otherwise false.private boolean isHtmlExclusion(java.lang.String reference)
reference - (String) The reference from the template that is
about to be inserted.true if the reference should be excluded,
otherwise false.private boolean isHtmlJavaScript(java.lang.String reference)
reference - (String) The reference from the template that is
about to be inserted.true if the reference should be included,
otherwise false.private boolean isJDBCObjectReturned(java.lang.Object object,
java.lang.reflect.Method method)
object - (Object) The object to check.method - (Method) The method being invoked.true if object is a JDBC object controller
and the method returns a JDBC object, otherwise false.private boolean isTextExclusion(java.lang.String reference)
reference - (String) The reference from the template that is
about to be inserted.true if the reference should be excluded,
otherwise false.private boolean isXmlExclusion(java.lang.String reference)
reference - (String) The reference from the template that is
about to be inserted.true if the reference should be excluded,
otherwise false.public java.util.ArrayList<java.lang.String> getTemplateErrors()
CURRENTLY ALWAYS RETURNS AN EMPTY VECTOR DUE TO A DEFICIENCY IN VELOCITY THAT RESULTS IN ERRONEOUS INVALID REFERENCES BEING RECORDED.
private void logInvalidMethod(java.lang.String reference,
org.apache.velocity.util.introspection.Info info)
reference - (String) The invalid reference.info - (Info) Contains template, line and column details.private void logInvalidReference(java.lang.String reference,
org.apache.velocity.util.introspection.Info info)
reference - (String) The invalid reference.info - (Info) Contains template, line and column details.private void logNullInsertion(java.lang.String reference)
reference - (String) The reference that resulted in a null value.