| java.lang.Object org.apache.velocity.app.Velocity
Velocity | public class Velocity implements RuntimeConstants(Code) | | This class provides services to the application
developer, such as :
- Simple Velocity Runtime engine initialization methods.
- Functions to apply the template engine to streams and strings
to allow embedding and dynamic template generation.
- Methods to access Velocimacros directly.
While the most common way to use Velocity is via templates, as
Velocity is a general-purpose template engine, there are other
uses that Velocity is well suited for, such as processing dynamically
created templates, or processing content streams.
The methods herein were developed to allow easy access to the Velocity
facilities without direct spelunking of the internals. If there is
something you feel is necessary to add here, please, send a patch.
author: Geir Magnusson Jr. author: Christoph Reck author: Jason van Zyl version: $Id: Velocity.java 471381 2006-11-05 08:56:58Z wglass $ |
Method Summary | |
public static void | addProperty(String key, Object value) Add a Velocity Runtime property. | public static void | clearProperty(String key) Clear a Velocity Runtime property. | public static void | debug(Object message) | public static void | error(Object message) | public static 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 static 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 static 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 static Log | getLog() Returns a convenient Log instance that wraps the current LogChute.
Use this to log error messages. | public static Object | getProperty(String key) Get a Velocity Runtime property. | public static Template | getTemplate(String name) Returns a Template from the Velocity
resource management system.
Parameters: name - The file name of the desired template. | public static 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 static void | info(Object message) | public static void | init() | public static void | init(String propsFilename) | public static void | init(Properties p) | public static 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 static 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 static 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 static boolean | resourceExists(String resourceName) Determines whether a resource is accessable via the
currently configured resource loaders. | public static void | setApplicationAttribute(Object key, Object value)
Set the an ApplicationAttribue, which is an Object
set by the application which is accessable 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 loaders and loggers.
Note that there is no enfocement or rules for the key
used - it is up to the application developer. | public static void | setExtendedProperties(ExtendedProperties configuration) Set an entire configuration at once. | public static void | setProperty(String key, Object value) Set a Velocity Runtime property. | public static boolean | templateExists(String resourceName) Parameters: resourceName - Name of the Template to check. | public static void | warn(Object message) |
addProperty | public static void addProperty(String key, Object value)(Code) | | Add a Velocity Runtime property.
Parameters: key - The property key. Parameters: value - The property value. |
clearProperty | public static void clearProperty(String key)(Code) | | Clear a Velocity Runtime property.
Parameters: key - of property to clear |
evaluate | public static boolean evaluate(Context context, Writer out, String logTag, String instring) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code) | | 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. If false, seeVelocity runtime log throws: ParseErrorException - The template could not be parsed. throws: MethodInvocationException - A method on a context object could not be invoked. throws: ResourceNotFoundException - A referenced resource could not be loaded. throws: IOException - While loading a reference, an I/O problem occured. |
evaluate | public static 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 logVelocity.evaluate(Context context,Writer writer,String logTag,Reader reader) throws: ParseErrorException - The template could not be parsed. throws: MethodInvocationException - A method on a context object could not be invoked. throws: ResourceNotFoundException - A referenced resource could not be loaded. throws: IOException - While loading a reference, an I/O problem occured. |
evaluate | public static boolean evaluate(Context context, Writer writer, String logTag, Reader reader) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code) | | 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. If false, seeVelocity runtime log throws: ParseErrorException - The template could not be parsed. throws: MethodInvocationException - A method on a context object could not be invoked. throws: ResourceNotFoundException - A referenced resource could not be loaded. throws: IOException - While loading a reference, an I/O problem occured. since: Velocity v1.1 |
getLog | public static Log getLog()(Code) | | Returns a convenient Log instance that wraps the current LogChute.
Use this to log error messages. It has the usual methods.
A convenience Log instance that wraps the current LogChute. |
getProperty | public static Object getProperty(String key)(Code) | | Get a Velocity Runtime property.
Parameters: key - property to retrieve property value or null if the propertynot currently set |
init | public static void init() throws Exception(Code) | | initialize the Velocity runtime engine, using the default
properties of the Velocity distribution
throws: Exception - When an error during initialization occurs. |
init | public static 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 - When an error during initialization occurs. |
init | public static 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 - Properties object containing initialization properties throws: Exception - When an error during initialization occurs. |
invokeVelocimacro | public static boolean invokeVelocimacro(String vmName, String logTag, String params, Context context, Writer writer)(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. |
resourceExists | public static boolean resourceExists(String resourceName)(Code) | | Determines whether a resource is accessable via the
currently configured resource loaders.
org.apache.velocity.runtime.resource.Resource is the generic
description of templates, static content, etc.
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.
Parameters: resourceName - The name of the resource to search for. Whether the resource was located. |
setApplicationAttribute | public static void setApplicationAttribute(Object key, Object value)(Code) | |
Set the an ApplicationAttribue, which is an Object
set by the application which is accessable 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 loaders and loggers.
Note that there is no enfocement 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 static 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 - A configuration object. |
setProperty | public static void setProperty(String key, Object value)(Code) | | Set a Velocity Runtime property.
Parameters: key - The property key. Parameters: value - The property value. |
|
|