| java.lang.Object org.apache.velocity.app.VelocityEngine
VelocityEngine | public class VelocityEngine implements RuntimeConstants(Code) | |
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().
version: $Id: VelocityEngine.java 471381 2006-11-05 08:56:58Z wglass $ |
Method Summary | |
public void | addProperty(String key, Object value) Add a Velocity Runtime property. | public void | clearProperty(String key) Clear a Velocity Runtime property. | public void | debug(Object message) | public void | error(Object message) | public boolean | evaluate(Context context, Writer out, String logTag, String instring) renders the input string using the context into the output writer.
To be used when a template is dynamically constructed, or want to use
Velocity as a token replacer.
Parameters: context - context to use in rendering input string Parameters: out - Writer in which to render the output Parameters: logTag - string to be used as the template name for logmessages in case of error Parameters: instring - input string containing the VTL to be rendered true if successful, false otherwise. | public boolean | evaluate(Context context, Writer writer, String logTag, InputStream instream) Renders the input stream using the context into the output writer.
To be used when a template is dynamically constructed, or want to
use Velocity as a token replacer.
Parameters: context - context to use in rendering input string Parameters: writer - Writer in which to render the output Parameters: logTag - string to be used as the template name for log messagesin case of error Parameters: instream - input stream containing the VTL to be rendered true if successful, false otherwise. | public boolean | evaluate(Context context, Writer writer, String logTag, Reader reader) Renders the input reader using the context into the output writer.
To be used when a template is dynamically constructed, or want to
use Velocity as a token replacer.
Parameters: context - context to use in rendering input string Parameters: writer - Writer in which to render the output Parameters: logTag - string to be used as the template name for log messagesin case of error Parameters: reader - Reader containing the VTL to be rendered true if successful, false otherwise. | public 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. | public Log | getLog() Returns a convenient Log instance that wraps the current LogChute.
Use this to log error messages. | public Object | getProperty(String key) Get a Velocity Runtime property. | public Template | getTemplate(String name) Returns a Template from the Velocity
resource management system.
Parameters: name - The file name of the desired template. | public Template | getTemplate(String name, String encoding) Returns a Template from the Velocity
resource management system.
Parameters: name - The file name of the desired template. Parameters: encoding - The character encoding to use for the template. | public void | info(Object message) | public void | init() | public void | init(String propsFilename) | public void | init(Properties p) | public boolean | invokeVelocimacro(String vmName, String logTag, String params, Context context, Writer writer) Invokes a currently registered Velocimacro with the parms provided
and places the rendered stream into the writer.
Note : currently only accepts args to the VM if they are in the context.
Parameters: vmName - name of Velocimacro to call Parameters: logTag - string to be used for template name in case of error Parameters: params - args used to invoke Velocimacro. | public boolean | mergeTemplate(String templateName, Context context, Writer writer) Merges a template and puts the rendered stream into the writer.
The default encoding that Velocity uses to read template files is defined in
the property input.encoding and defaults to ISO-8859-1.
Parameters: templateName - name of template to be used in merge Parameters: context - filled context to be used in merge Parameters: writer - writer to write template into true if successful, false otherwise. | public boolean | mergeTemplate(String templateName, String encoding, Context context, Writer writer) merges a template and puts the rendered stream into the writer
Parameters: templateName - name of template to be used in merge Parameters: encoding - encoding used in template Parameters: context - filled context to be used in merge Parameters: writer - writer to write template into true if successful, false otherwise. | public boolean | resourceExists(String resourceName) Determines if a resource is accessable via the currently
configured resource loaders. | 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. | public void | setExtendedProperties(ExtendedProperties configuration) Set an entire configuration at once. | public void | setProperty(String key, Object value) Set a Velocity Runtime property. | public boolean | templateExists(String resourceName) | public void | warn(Object message) |
VelocityEngine | public VelocityEngine()(Code) | | Init-less CTOR
|
VelocityEngine | public VelocityEngine(String propsFilename) throws Exception(Code) | | CTOR that invokes an init(String), initializing
the engine using the properties file specified
Parameters: propsFilename - name of properties file to init with throws: Exception - |
VelocityEngine | public VelocityEngine(Properties p) throws Exception(Code) | | CTOR that invokes an init(String), initializing
the engine using the Properties specified
Parameters: p - name of properties to init with throws: Exception - |
addProperty | public void addProperty(String key, Object value)(Code) | | Add a Velocity Runtime property.
Parameters: key - Parameters: value - |
clearProperty | public void clearProperty(String key)(Code) | | Clear a Velocity Runtime property.
Parameters: key - of property to clear |
debug | public void debug(Object message)(Code) | | Parameters: message - |
error | public void error(Object message)(Code) | | Parameters: message - |
evaluate | public boolean evaluate(Context context, Writer writer, String logTag, InputStream instream) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code) | | Renders the input stream using the context into the output writer.
To be used when a template is dynamically constructed, or want to
use Velocity as a token replacer.
Parameters: context - context to use in rendering input string Parameters: writer - Writer in which to render the output Parameters: logTag - string to be used as the template name for log messagesin case of error Parameters: instream - input stream containing the VTL to be rendered true if successful, false otherwise. If false, seeVelocity runtime log throws: ParseErrorException - throws: MethodInvocationException - throws: ResourceNotFoundException - throws: IOException - VelocityEngine.evaluate(Context context,Writer writer,String logTag,Reader reader) |
getApplicationAttribute | public Object getApplicationAttribute(Object key)(Code) | |
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.
Parameters: key - object 'name' under which the object is stored value object to store under this key |
getLog | public Log getLog()(Code) | | Returns a convenient Log instance that wraps the current LogChute.
Use this to log error messages. It has the usual methods you'd expect.
A log object. |
getProperty | public Object getProperty(String key)(Code) | | Get a Velocity Runtime property.
Parameters: key - property to retrieve property value or null if the propertynot currently set |
info | public void info(Object message)(Code) | | Parameters: message - |
init | public void init() throws Exception(Code) | | initialize the Velocity runtime engine, using the default
properties of the Velocity distribution
throws: Exception - |
init | public void init(String propsFilename) throws Exception(Code) | | initialize the Velocity runtime engine, using default properties
plus the properties in the properties file passed in as the arg
Parameters: propsFilename - file containing properties to use to initializethe Velocity runtime throws: Exception - |
init | public void init(Properties p) throws Exception(Code) | | initialize the Velocity runtime engine, using default properties
plus the properties in the passed in java.util.Properties object
Parameters: p - Proprties object containing initialization properties throws: Exception - |
invokeVelocimacro | public boolean invokeVelocimacro(String vmName, String logTag, String params, Context context, Writer writer) throws Exception(Code) | | Invokes a currently registered Velocimacro with the parms provided
and places the rendered stream into the writer.
Note : currently only accepts args to the VM if they are in the context.
Parameters: vmName - name of Velocimacro to call Parameters: logTag - string to be used for template name in case of error Parameters: params - args used to invoke Velocimacro. In context key format :eg "foo","bar" (rather than "$foo","$bar") Parameters: context - Context object containing data/objects used for rendering. Parameters: writer - Writer for output stream true if Velocimacro exists and successfully invoked, false otherwise. throws: Exception - |
resourceExists | public boolean resourceExists(String resourceName)(Code) | | Determines if a resource is accessable via the currently
configured resource loaders.
Note that the current implementation will not
change the state of the system in any real way - so this
cannot be used to pre-load the resource cache, as the
previous implementation did as a side-effect.
The previous implementation exhibited extreme lazyness and
sloth, and the author has been flogged.
Parameters: resourceName - name of the resource to search for true if found, false otherwise |
setApplicationAttribute | public void setApplicationAttribute(Object key, Object value)(Code) | |
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.
Parameters: key - object 'name' under which the object is stored Parameters: value - object to store under this key |
setExtendedProperties | public void setExtendedProperties(ExtendedProperties configuration)(Code) | | Set an entire configuration at once. This is
useful in cases where the parent application uses
the ExtendedProperties class and the velocity configuration
is a subset of the parent application's configuration.
Parameters: configuration - |
setProperty | public void setProperty(String key, Object value)(Code) | | Set a Velocity Runtime property.
Parameters: key - Parameters: value - |
warn | public void warn(Object message)(Code) | | Parameters: message - |
|
|