|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.runtime.Runtime
This is the Runtime system for Velocity. It is the single access point for all functionality in Velocity. It adheres to the mediator pattern and is the only structure that developers need to be familiar with in order to get Velocity to perform. The Runtime will also cooperate with external systems like Turbine. Runtime properties can set and then the Runtime is initialized. Turbine for example knows where the templates are to be loaded from, and where the velocity log file should be placed. So in the case of Velocity cooperating with Turbine the code might look something like the following:
Runtime.setProperty(Runtime.FILE_RESOURCE_LOADER_PATH, templatePath); Runtime.setProperty(Runtime.RUNTIME_LOG, pathToVelocityLog); Runtime.init();
----------------------------------------------------------------------- N O T E S O N R U N T I M E I N I T I A L I Z A T I O N ----------------------------------------------------------------------- Runtime.init() If Runtime.init() is called by itself the Runtime will initialize with a set of default values. ----------------------------------------------------------------------- Runtime.init(String/Properties) In this case the default velocity properties are layed down first to provide a solid base, then any properties provided in the given properties object will override the corresponding default property. -----------------------------------------------------------------------
Constructor Summary | |
Runtime()
|
Method Summary | |
static void |
addProperty(java.lang.String key,
java.lang.Object value)
Add a property to the configuration. |
static boolean |
addVelocimacro(java.lang.String name,
java.lang.String macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
Adds a new Velocimacro. |
static void |
clearProperty(java.lang.String key)
Clear the values pertaining to a particular property. |
static void |
debug(java.lang.Object message)
Log a debug message. |
static boolean |
dumpVMNamespace(java.lang.String namespace)
tells the vmFactory to dump the specified namespace. |
static void |
error(java.lang.Object message)
Log an error message. |
static boolean |
getBoolean(java.lang.String key,
boolean def)
Boolean property accessor method to hide the configuration implementation. |
static org.apache.commons.collections.ExtendedProperties |
getConfiguration()
Return the velocity runtime configuration object. |
static ContentResource |
getContent(java.lang.String name)
Returns a static content resource from the resource manager. |
static ContentResource |
getContent(java.lang.String name,
java.lang.String encoding)
Returns a static content resource from the resource manager. |
static int |
getInt(java.lang.String key)
Int property accessor method to hide the configuration implementation. |
static int |
getInt(java.lang.String key,
int defaultValue)
Int property accessor method to hide the configuration implementation. |
static java.lang.String |
getLoaderNameForResource(java.lang.String resourceName)
Determines is a template exists, and returns name of the loader that provides it. |
static java.lang.Object |
getProperty(java.lang.String key)
Allows an external caller to get a property. |
static java.lang.String |
getString(java.lang.String key)
String property accessor method to hide the configuration implementation |
static java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
String property accessor method with default to hide the configuration implementation. |
static Template |
getTemplate(java.lang.String name)
Returns a Template from the resource manager. |
static Template |
getTemplate(java.lang.String name,
java.lang.String encoding)
Returns a Template from the resource manager |
static Directive |
getVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Returns the appropriate VelocimacroProxy object if strVMname is a valid current Velocimacro. |
static void |
info(java.lang.Object message)
Log an info message. |
static void |
init()
|
static void |
init(java.util.Properties p)
Initialize the Velocity Runtime with a Properties object. |
static void |
init(java.lang.String configurationFile)
Initialize the Velocity Runtime with the name of ExtendedProperties object. |
static boolean |
isVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Checks to see if a VM exists |
static SimpleNode |
parse(java.io.Reader reader,
java.lang.String templateName)
Parse the input and return the root of AST node structure. |
static SimpleNode |
parse(java.io.Reader reader,
java.lang.String templateName,
boolean dumpNamespace)
Parse the input and return the root of the AST node structure. |
static void |
setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
Allow an external system to set an ExtendedProperties object to use. |
static void |
setProperty(java.lang.String key,
java.lang.Object value)
Allows an external system to set a property in the Velocity Runtime. |
static void |
warn(java.lang.Object message)
Log a warning message. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public Runtime()
Method Detail |
public static void init() throws java.lang.Exception
public static void setProperty(java.lang.String key, java.lang.Object value)
String
- property keyString
- property valuepublic static void setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
ExtendedProperties
- configurationpublic static void addProperty(java.lang.String key, java.lang.Object value)
String
- keyString
- valuepublic static void clearProperty(java.lang.String key)
String
- key of property to clearpublic static java.lang.Object getProperty(java.lang.String key)
key
- property to returnpublic static void init(java.util.Properties p) throws java.lang.Exception
Properties
- public static void init(java.lang.String configurationFile) throws java.lang.Exception
Properties
- public static SimpleNode parse(java.io.Reader reader, java.lang.String templateName) throws ParseException
InputStream
- inputstream retrieved by a resource loaderString
- name of the template being parsedpublic static SimpleNode parse(java.io.Reader reader, java.lang.String templateName, boolean dumpNamespace) throws ParseException
InputStream
- inputstream retrieved by a resource loaderString
- name of the template being parseddumpNamespace
- flag to dump the Velocimacro namespace for this templatepublic static Template getTemplate(java.lang.String name) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Template
from the resource manager.
This method assumes that the character encoding of the
template is set by the input.encoding
property. The default is "ISO-8859-1"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 static Template getTemplate(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Template
from the resource managername
- The name of the desired template.encoding
- Character encoding of the templateResourceNotFoundException
- 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 static ContentResource getContent(java.lang.String name) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
name
- Name of content resource to getResourceNotFoundException
- if template not found
from any available source.public static ContentResource getContent(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
name
- Name of content resource to getencoding
- Character encoding to useResourceNotFoundException
- if template not found
from any available source.public static java.lang.String getLoaderNameForResource(java.lang.String resourceName)
resourceName
- Name of template or content resourcepublic static void warn(java.lang.Object message)
Object
- message to logpublic static void info(java.lang.Object message)
Object
- message to logpublic static void error(java.lang.Object message)
Object
- message to logpublic static void debug(java.lang.Object message)
Object
- message to logpublic static java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
String
- key property keyString
- defaultValue default value to return if key not
found in resource manager.public static Directive getVelocimacro(java.lang.String vmName, java.lang.String templateName)
String
- vmName Name of velocimacro requestedpublic static boolean addVelocimacro(java.lang.String name, java.lang.String macro, java.lang.String[] argArray, java.lang.String sourceTemplate)
String
- name Name of velocimacroString
- macro String form of macro bodyString
- argArray Array of strings, containing the
#macro() arguments. the 0th is the name.public static boolean isVelocimacro(java.lang.String vmName, java.lang.String templateName)
name
- Name of velocimacropublic static boolean dumpVMNamespace(java.lang.String namespace)
public static java.lang.String getString(java.lang.String key)
key
- property keypublic static int getInt(java.lang.String key)
String
- key property keypublic static int getInt(java.lang.String key, int defaultValue)
key
- property keyint
- default valuepublic static boolean getBoolean(java.lang.String key, boolean def)
String
- key property keyboolean
- default default value if property not foundpublic static org.apache.commons.collections.ExtendedProperties getConfiguration()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |