|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.app.VelocityEngine
This class provides a separate new-able instance of the Velocity template engine. The alternative model for use is using the Velocity class which employs the singleton model.
Please ensure that you call one of the init() variants. This is critical for proper behavior.
Coming soon : Velocity will call the parameter-less init() at the first use of this class if the init() wasn't explicitly called. While this will ensure that Velocity functions, it almost certainly won't function in the way you intend, so please make sure to call init().
Field Summary | |
private RuntimeInstance |
ri
|
Constructor Summary | |
VelocityEngine()
|
Method Summary | |
void |
addProperty(java.lang.String key,
java.lang.Object value)
Add a Velocity Runtime property. |
void |
clearProperty(java.lang.String key)
Clear a Velocity Runtime property. |
void |
debug(java.lang.Object message)
Log a debug message. |
void |
error(java.lang.Object message)
Log an error message. |
boolean |
evaluate(Context context,
java.io.Writer writer,
java.lang.String logTag,
java.io.InputStream instream)
Deprecated. Use evaluate( Context context, Writer writer,
String logTag, Reader reader ) |
boolean |
evaluate(Context context,
java.io.Writer writer,
java.lang.String logTag,
java.io.Reader reader)
Renders the input reader using the context into the output writer. |
boolean |
evaluate(Context context,
java.io.Writer out,
java.lang.String logTag,
java.lang.String instring)
renders the input string using the context into the output writer. |
java.lang.Object |
getProperty(java.lang.String key)
Get a Velocity Runtime property. |
Template |
getTemplate(java.lang.String name)
Returns a Template from the Velocity
resource management system. |
Template |
getTemplate(java.lang.String name,
java.lang.String encoding)
Returns a Template from the Velocity
resource management system. |
void |
info(java.lang.Object message)
Log an info message. |
void |
init()
initialize the Velocity runtime engine, using the default properties of the Velocity distribution |
void |
init(java.util.Properties p)
initialize the Velocity runtime engine, using default properties plus the properties in the passed in java.util.Properties object |
void |
init(java.lang.String propsFilename)
initialize the Velocity runtime engine, using default properties plus the properties in the properties file passed in as the arg |
boolean |
invokeVelocimacro(java.lang.String vmName,
java.lang.String logTag,
java.lang.String[] params,
Context context,
java.io.Writer writer)
Invokes a currently registered Velocimacro with the parms provided and places the rendered stream into the writer. |
boolean |
mergeTemplate(java.lang.String templateName,
Context context,
java.io.Writer writer)
merges a template and puts the rendered stream into the writer |
boolean |
mergeTemplate(java.lang.String templateName,
java.lang.String encoding,
Context context,
java.io.Writer writer)
merges a template and puts the rendered stream into the writer |
void |
setConfiguration(Configuration configuration)
Deprecated. Use setExtendedProperties( ExtendedProperties ) |
void |
setExtendedProperties(org.apache.commons.collections.ExtendedProperties configuration)
Set an entire configuration at once. |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Set a Velocity Runtime property. |
boolean |
templateExists(java.lang.String templateName)
Determines if a template is accessable via the currently configured resource loaders. |
void |
warn(java.lang.Object message)
Log a warning message. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private RuntimeInstance ri
Constructor Detail |
public VelocityEngine()
Method Detail |
public void init() throws java.lang.Exception
public void init(java.lang.String propsFilename) throws java.lang.Exception
propsFilename
- file containing properties to use to initialize
the Velocity runtimepublic void init(java.util.Properties p) throws java.lang.Exception
p
- Proprties object containing initialization propertiespublic void setProperty(java.lang.String key, java.lang.Object value)
String
- keyObject
- valuepublic void addProperty(java.lang.String key, java.lang.Object value)
String
- keyObject
- valuepublic void clearProperty(java.lang.String key)
key
- of property to clearpublic void setConfiguration(Configuration configuration)
setExtendedProperties( ExtendedProperties )
Configuration
- configurationpublic void setExtendedProperties(org.apache.commons.collections.ExtendedProperties configuration)
ExtendedProperties
- configurationpublic java.lang.Object getProperty(java.lang.String key)
key
- property to retrievepublic boolean evaluate(Context context, java.io.Writer out, java.lang.String logTag, java.lang.String instring) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, java.io.IOException
context
- context to use in rendering input stringout
- Writer in which to render the outputlogTag
- string to be used as the template name for log
messages in case of errorinstring
- input string containing the VTL to be renderedpublic boolean evaluate(Context context, java.io.Writer writer, java.lang.String logTag, java.io.InputStream instream) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, java.io.IOException
evaluate( Context context, Writer writer,
String logTag, Reader reader )
context
- context to use in rendering input stringout
- Writer in which to render the outputlogTag
- string to be used as the template name for log messages
in case of errorinstream
- input stream containing the VTL to be renderedpublic boolean evaluate(Context context, java.io.Writer writer, java.lang.String logTag, java.io.Reader reader) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, java.io.IOException
context
- context to use in rendering input stringout
- Writer in which to render the outputlogTag
- string to be used as the template name for log messages
in case of errorreader
- Reader containing the VTL to be renderedpublic boolean invokeVelocimacro(java.lang.String vmName, java.lang.String logTag, java.lang.String[] params, Context context, java.io.Writer writer)
vmName
- name of Velocimacro to calllogTag
- string to use to indentify 'template' in logsparams[]
- args used to invoke Velocimacro. In context key format :
eg "foo","bar" (rather than "$foo","$bar")context
- Context object containing data/objects used for rendering.writer
- Writer for output streampublic boolean mergeTemplate(java.lang.String templateName, Context context, java.io.Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, java.lang.Exception
templateName
- name of template to be used in mergecontext
- filled context to be used in mergewriter
- writer to write template intomergeTemplate( String templateName, String encoding,
Context context, Writer writer )
public boolean mergeTemplate(java.lang.String templateName, java.lang.String encoding, Context context, java.io.Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, java.lang.Exception
templateName
- name of template to be used in mergeencoding
- encoding used in templatecontext
- filled context to be used in mergewriter
- writer to write template intopublic Template getTemplate(java.lang.String name) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Template
from the Velocity
resource management system.name
- The file name of the desired template.ResourceNotFoundException
- if template not found
from any available source.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.java.lang.Exception
- if an error occurs in template initializationpublic Template getTemplate(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Template
from the Velocity
resource management system.name
- The file name of the desired template.encoding
- The character encoding to use for the template.ResourceNotFoundException
- if template not found
from any available source.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.java.lang.Exception
- if an error occurs in template initializationpublic boolean templateExists(java.lang.String templateName)
templateName
- name of the temlpate to search forpublic void warn(java.lang.Object message)
Object
- message to logpublic void info(java.lang.Object message)
Object
- message to logpublic void error(java.lang.Object message)
Object
- message to logpublic void debug(java.lang.Object message)
Object
- message to log
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |