|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.app.VelocityEngine
public class 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.
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 probably won't function in the way you intend, so it is strongly recommended that you call an init() method yourself if you use the default constructor.
Field Summary |
---|
Constructor Summary | |
---|---|
VelocityEngine()
Init-less CTOR |
|
VelocityEngine(Properties p)
CTOR that invokes an init(String), initializing the engine using the Properties specified |
|
VelocityEngine(String propsFilename)
CTOR that invokes an init(String), initializing the engine using the properties file specified |
Method Summary | |
---|---|
void |
addProperty(String key,
Object value)
Add a Velocity Runtime property. |
void |
clearProperty(String key)
Clear a Velocity Runtime property. |
void |
debug(Object message)
Deprecated. Use getLog() and call warn() on it. |
void |
error(Object message)
Deprecated. Use getLog() and call warn() on it. |
boolean |
evaluate(Context context,
Writer writer,
String logTag,
InputStream instream)
Deprecated. Use evaluate( Context context, Writer writer,
String logTag, Reader reader ) |
boolean |
evaluate(Context context,
Writer writer,
String logTag,
Reader reader)
Renders the input reader using the context into the output writer. |
boolean |
evaluate(Context context,
Writer out,
String logTag,
String instring)
renders the input string using the context into the output writer. |
Object |
getApplicationAttribute(Object key)
Return an application attribute (which can be any Object) that was set by the application in order to be accessible from any component of the system that gets a RuntimeServices. |
Log |
getLog()
Returns a convenient Log instance that wraps the current LogChute. |
Object |
getProperty(String key)
Get a Velocity Runtime property. |
Template |
getTemplate(String name)
Returns a Template from the Velocity
resource management system. |
Template |
getTemplate(String name,
String encoding)
Returns a Template from the Velocity
resource management system. |
void |
info(Object message)
Deprecated. Use getLog() and call warn() on it. |
void |
init()
initialize the Velocity runtime engine, using the default properties of the Velocity distribution |
void |
init(Properties p)
initialize the Velocity runtime engine, using default properties plus the properties in the passed in java.util.Properties object |
void |
init(String propsFilename)
initialize the Velocity runtime engine, using default properties plus the properties in the properties file passed in as the arg |
boolean |
invokeVelocimacro(String vmName,
String logTag,
String[] params,
Context context,
Writer writer)
Invokes a currently registered Velocimacro with the params provided and places the rendered stream into the writer. |
boolean |
mergeTemplate(String templateName,
Context context,
Writer writer)
Deprecated. Use mergeTemplate( String templateName, String encoding,
Context context, Writer writer ) |
boolean |
mergeTemplate(String templateName,
String encoding,
Context context,
Writer writer)
merges a template and puts the rendered stream into the writer |
boolean |
resourceExists(String resourceName)
Determines if a resource is accessable via the currently configured resource loaders. |
void |
setApplicationAttribute(Object key,
Object value)
Sets an application attribute (which can be any Object) that will be accessible from any component of the system that gets a RuntimeServices. |
void |
setExtendedProperties(ExtendedProperties configuration)
Set an entire configuration at once. |
void |
setProperty(String key,
Object value)
Set a Velocity Runtime property. |
boolean |
templateExists(String resourceName)
Deprecated. Use resourceExists(String) instead. |
void |
warn(Object message)
Deprecated. Use getLog() and call warn() on it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VelocityEngine()
public VelocityEngine(String propsFilename) throws Exception
propsFilename
- name of properties file to init with
Exception
public VelocityEngine(Properties p) throws Exception
p
- name of properties to init with
Exception
Method Detail |
---|
public void init() throws Exception
Exception
public void init(String propsFilename) throws Exception
propsFilename
- file containing properties to use to initialize
the Velocity runtime
Exception
public void init(Properties p) throws Exception
p
- Proprties object containing initialization properties
Exception
public void setProperty(String key, Object value)
key
- value
- public void addProperty(String key, Object value)
key
- value
- public void clearProperty(String key)
key
- of property to clearpublic void setExtendedProperties(ExtendedProperties configuration)
configuration
- public Object getProperty(String key)
key
- property to retrieve
public boolean evaluate(Context context, Writer out, String logTag, String instring) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, 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 rendered
ParseErrorException
- The template could not be parsed.
MethodInvocationException
- A method on a context object could not be invoked.
ResourceNotFoundException
- A referenced resource could not be loaded.
IOException
- While rendering to the writer, an I/O problem occured.public boolean evaluate(Context context, Writer writer, String logTag, InputStream instream) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
evaluate( Context context, Writer writer,
String logTag, Reader reader )
context
- context to use in rendering input stringwriter
- 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 rendered
ParseErrorException
MethodInvocationException
ResourceNotFoundException
IOException
public boolean evaluate(Context context, Writer writer, String logTag, Reader reader) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException
context
- context to use in rendering input stringwriter
- 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 rendered
ParseErrorException
- The template could not be parsed.
MethodInvocationException
- A method on a context object could not be invoked.
ResourceNotFoundException
- A referenced resource could not be loaded.
IOException
- While reading from the reader or rendering to the writer,
an I/O problem occured.public boolean invokeVelocimacro(String vmName, String logTag, String[] params, Context context, Writer writer) throws Exception
vmName
- name of Velocimacro to calllogTag
- string to be used for template name in case of error. if null,
the vmName will be usedparams
- keys for args used to invoke Velocimacro, in java format
rather than VTL (eg "foo" or "bar" rather than "$foo" or "$bar")context
- Context object containing data/objects used for rendering.writer
- Writer for output stream
IOException
- While rendering to the writer, an I/O problem occured.
Exception
public boolean mergeTemplate(String templateName, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception
mergeTemplate( String templateName, String encoding,
Context context, Writer writer )
templateName
- name of template to be used in mergecontext
- filled context to be used in mergewriter
- writer to write template into
ResourceNotFoundException
ParseErrorException
MethodInvocationException
Exception
public boolean mergeTemplate(String templateName, String encoding, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, 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 into
ResourceNotFoundException
ParseErrorException
MethodInvocationException
Exception
public Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException, 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.
Exception
- if an error occurs in template initializationpublic Template getTemplate(String name, String encoding) throws ResourceNotFoundException, ParseErrorException, 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.
Exception
- if an error occurs in template initializationpublic boolean resourceExists(String resourceName)
resourceName
- name of the resource to search for
public boolean templateExists(String resourceName)
resourceName
-
resourceExists(String)
public Log getLog()
public void warn(Object message)
message
- public void info(Object message)
message
- public void error(Object message)
message
- public void debug(Object message)
message
- public void setApplicationAttribute(Object key, Object value)
Sets an application attribute (which can be any Object) that will be accessible from any component of the system that gets a RuntimeServices. This allows communication between the application environment and custom pluggable components of the Velocity engine, such as ResourceLoaders and LogChutes.
Note that there is no enforcement or rules for the key used - it is up to the application developer. However, to help make the intermixing of components possible, using the target Class name (e.g. com.foo.bar ) as the key might help avoid collision.
key
- object 'name' under which the object is storedvalue
- object to store under this keypublic Object getApplicationAttribute(Object key)
Return an application attribute (which can be any Object) that was set by the application in order to be accessible from any component of the system that gets a RuntimeServices. This allows communication between the application environment and custom pluggable components of the Velocity engine, such as ResourceLoaders and LogChutes.
key
- object 'name' under which the object is stored
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |