|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.runtime.RuntimeInstance
public class RuntimeInstance
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:
ri.setProperty(Runtime.FILE_RESOURCE_LOADER_PATH, templatePath);
ri.setProperty(Runtime.RUNTIME_LOG, pathToVelocityLog);
ri.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 ----------------------------------------------------------------------- init() If init() is called by itself the RuntimeInstance will initialize with a set of default values. ----------------------------------------------------------------------- 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. -----------------------------------------------------------------------
Field Summary |
---|
Constructor Summary | |
---|---|
RuntimeInstance()
|
Method Summary | |
---|---|
void |
addProperty(String key,
Object value)
Add a property to the configuration. |
boolean |
addVelocimacro(String name,
String macro,
String[] argArray,
String sourceTemplate,
int line,
int column)
Adds a new Velocimacro. |
void |
clearProperty(String key)
Clear the values pertaining to a particular property. |
Parser |
createNewParser()
Returns a JavaCC generated Parser. |
boolean |
dumpVMNamespace(String namespace)
tells the vmFactory to dump the specified namespace. |
Object |
getApplicationAttribute(Object key)
Gets the application attribute for the given key |
boolean |
getBoolean(String key,
boolean def)
Boolean property accessor method to hide the configuration implementation. |
org.apache.commons.collections.ExtendedProperties |
getConfiguration()
Return the velocity runtime configuration object. |
ContentResource |
getContent(String name)
Returns a static content resource from the resource manager. |
ContentResource |
getContent(String name,
String encoding)
Returns a static content resource from the resource manager. |
int |
getInt(String key)
Int property accessor method to hide the configuration implementation. |
int |
getInt(String key,
int defaultValue)
Int property accessor method to hide the configuration implementation. |
Introspector |
getIntrospector()
Return the Introspector for this instance |
String |
getLoaderNameForResource(String resourceName)
Determines is a template exists, and returns name of the loader that provides it. |
Object |
getProperty(String key)
Allows an external caller to get a property. |
String |
getString(String key)
String property accessor method to hide the configuration implementation |
String |
getString(String key,
String defaultValue)
String property accessor method with default to hide the configuration implementation. |
Template |
getTemplate(String name)
Returns a Template from the resource manager. |
Template |
getTemplate(String name,
String encoding)
Returns a Template from the resource manager |
Uberspect |
getUberspect()
Returns the configured class introspection/reflection implemenation. |
Directive |
getVelocimacro(String vmName,
String templateName)
Returns the appropriate VelocimacroProxy object if strVMname is a valid current Velocimacro. |
void |
init()
|
void |
init(Properties p)
Initialize the Velocity Runtime with a Properties object. |
void |
init(String configurationFile)
Initialize the Velocity Runtime with the name of ExtendedProperties object. |
boolean |
isVelocimacro(String vmName,
String templateName)
Checks to see if a VM exists |
SimpleNode |
parse(Reader reader,
String templateName)
Parse the input and return the root of AST node structure. |
SimpleNode |
parse(Reader reader,
String templateName,
boolean dumpNamespace)
Parse the input and return the root of the AST node structure. |
Object |
setApplicationAttribute(Object key,
Object o)
Sets the application attribute for the given key |
void |
setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
Allow an external system to set an ExtendedProperties object to use. |
void |
setProperty(String key,
Object value)
Allows an external system to set a property in the Velocity Runtime. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RuntimeInstance()
Method Detail |
---|
public void init() throws Exception
init
in interface RuntimeServices
Exception
public void setProperty(String key, Object value)
setProperty
in interface RuntimeServices
key
- property keyvalue
- property valuepublic void setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
setConfiguration
in interface RuntimeServices
configuration
- public void addProperty(String key, Object value)
addProperty
in interface RuntimeServices
key
- value
- public void clearProperty(String key)
clearProperty
in interface RuntimeServices
key
- of property to clearpublic Object getProperty(String key)
getProperty
in interface RuntimeServices
key
- property to returnpublic void init(Properties p) throws Exception
init
in interface RuntimeServices
p
-
Exception
public void init(String configurationFile) throws Exception
init
in interface RuntimeServices
configurationFile
-
Exception
public Parser createNewParser()
public SimpleNode parse(Reader reader, String templateName) throws ParseException
parse
in interface RuntimeServices
reader
- Reader retrieved by a resource loadertemplateName
- name of the template being parsed
ParseException
public SimpleNode parse(Reader reader, String templateName, boolean dumpNamespace) throws ParseException
parse
in interface RuntimeServices
reader
- Reader retrieved by a resource loadertemplateName
- name of the template being parseddumpNamespace
- flag to dump the Velocimacro namespace for this template
ParseException
public Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException, 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"
getTemplate
in interface RuntimeServices
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 resource manager
getTemplate
in interface RuntimeServices
name
- The name of the desired template.encoding
- Character encoding of 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 ContentResource getContent(String name) throws ResourceNotFoundException, ParseErrorException, Exception
getContent
in interface RuntimeServices
name
- Name of content resource to get
ResourceNotFoundException
- if template not found
from any available source.
ParseErrorException
Exception
public ContentResource getContent(String name, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception
getContent
in interface RuntimeServices
name
- Name of content resource to getencoding
- Character encoding to use
ResourceNotFoundException
- if template not found
from any available source.
ParseErrorException
Exception
public String getLoaderNameForResource(String resourceName)
getLoaderNameForResource
in interface RuntimeServices
resourceName
- Name of template or content resource
public String getString(String key, String defaultValue)
getString
in interface RuntimeServices
key
- property keydefaultValue
- default value to return if key not
found in resource manager.
public Directive getVelocimacro(String vmName, String templateName)
getVelocimacro
in interface RuntimeServices
vmName
- Name of velocimacro requestedtemplateName
-
public boolean addVelocimacro(String name, String macro, String[] argArray, String sourceTemplate, int line, int column)
addVelocimacro
in interface RuntimeServices
name
- Name of velocimacromacro
- String form of macro bodyargArray
- Array of strings, containing the
#macro() arguments. the 0th is the name.sourceTemplate
- line
- the line, where the macro startscolumn
- the column, where the macro starts
public boolean isVelocimacro(String vmName, String templateName)
isVelocimacro
in interface RuntimeServices
vmName
- Name of the Velocimacro.templateName
-
public boolean dumpVMNamespace(String namespace)
dumpVMNamespace
in interface RuntimeServices
public String getString(String key)
getString
in interface RuntimeServices
key
- property key
public int getInt(String key)
getInt
in interface RuntimeServices
key
- Property key
public int getInt(String key, int defaultValue)
getInt
in interface RuntimeServices
key
- property keydefaultValue
- default value
public boolean getBoolean(String key, boolean def)
getBoolean
in interface RuntimeServices
key
- property keydef
- default value if property not found
public org.apache.commons.collections.ExtendedProperties getConfiguration()
getConfiguration
in interface RuntimeServices
public Introspector getIntrospector()
getIntrospector
in interface RuntimeServices
public Object getApplicationAttribute(Object key)
getApplicationAttribute
in interface RuntimeServices
key
-
null
if not availablepublic Object setApplicationAttribute(Object key, Object o)
key
- o
-
public Uberspect getUberspect()
RuntimeServices
getUberspect
in interface RuntimeServices
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |