|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.velocity.runtime.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 | |
private java.util.Map |
applicationAttributes
|
private org.apache.commons.collections.ExtendedProperties |
configuration
Object that houses the configuration options for the velocity runtime. |
private boolean |
initialized
Indicate whether the Runtime has been fully initialized. |
private Introspector |
introspector
|
private LogSystem |
logSystem
The Runtime logger. |
private org.apache.commons.collections.ExtendedProperties |
overridingProperties
These are the properties that are laid down over top of the default properties when requested. |
private SimplePool |
parserPool
The Runtime parser pool |
private ResourceManager |
resourceManager
|
private java.util.Hashtable |
runtimeDirectives
This is a hashtable of initialized directives. |
private Uberspect |
uberSpect
|
private VelocimacroFactory |
vmFactory
VelocimacroFactory object to manage VMs |
Constructor Summary | |
RuntimeInstance()
|
Method Summary | |
void |
addProperty(java.lang.String key,
java.lang.Object value)
Add a property to the configuration. |
boolean |
addVelocimacro(java.lang.String name,
java.lang.String macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
Adds a new Velocimacro. |
void |
clearProperty(java.lang.String key)
Clear the values pertaining to a particular property. |
Parser |
createNewParser()
Returns a JavaCC generated Parser. |
void |
debug(java.lang.Object message)
Log a debug message. |
boolean |
dumpVMNamespace(java.lang.String namespace)
tells the vmFactory to dump the specified namespace. |
void |
error(java.lang.Object message)
Log an error message. |
java.lang.Object |
getApplicationAttribute(java.lang.Object key)
Return the specified applcation attribute. |
boolean |
getBoolean(java.lang.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(java.lang.String name)
Returns a static content resource from the resource manager. |
ContentResource |
getContent(java.lang.String name,
java.lang.String encoding)
Returns a static content resource from the resource manager. |
int |
getInt(java.lang.String key)
Int property accessor method to hide the configuration implementation. |
int |
getInt(java.lang.String key,
int defaultValue)
Int property accessor method to hide the configuration implementation. |
Introspector |
getIntrospector()
Return the Introspector for this instance |
java.lang.String |
getLoaderNameForResource(java.lang.String resourceName)
Determines is a template exists, and returns name of the loader that provides it. |
java.lang.Object |
getProperty(java.lang.String key)
Allows an external caller to get a property. |
java.lang.String |
getString(java.lang.String key)
String property accessor method to hide the configuration implementation |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
String property accessor method with default to hide the configuration implementation. |
Template |
getTemplate(java.lang.String name)
Returns a Template from the resource manager. |
Template |
getTemplate(java.lang.String name,
java.lang.String encoding)
Returns a Template from the resource manager |
Uberspect |
getUberspect()
Returns the configured class introspection/reflection implemenation. |
Directive |
getVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Returns the appropriate VelocimacroProxy object if strVMname is a valid current Velocimacro. |
void |
info(java.lang.Object message)
Log an info message. |
void |
init()
|
void |
init(java.util.Properties p)
Initialize the Velocity Runtime with a Properties object. |
void |
init(java.lang.String configurationFile)
Initialize the Velocity Runtime with the name of ExtendedProperties object. |
private void |
initializeDirectives()
This methods initializes all the directives that are used by the Velocity Runtime. |
private void |
initializeIntrospection()
Gets the classname for the Uberspect introspection package and instantiates an instance. |
private void |
initializeLogger()
Initialize the Velocity logging system. |
private void |
initializeParserPool()
Initializes the Velocity parser pool. |
private void |
initializeProperties()
Initialize Velocity properties, if the default properties have not been laid down first then do so. |
private void |
initializeResourceManager()
|
boolean |
isVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Checks to see if a VM exists |
private void |
loadDirective(java.lang.String directiveClass,
java.lang.String caption)
instantiates and loads the directive with some basic checks |
private void |
log(int level,
java.lang.Object message)
Handle logging. |
SimpleNode |
parse(java.io.Reader reader,
java.lang.String templateName)
Parse the input and return the root of AST node structure. |
SimpleNode |
parse(java.io.Reader reader,
java.lang.String templateName,
boolean dumpNamespace)
Parse the input and return the root of the AST node structure. |
java.lang.Object |
setApplicationAttribute(java.lang.Object key,
java.lang.Object o)
|
void |
setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
Allow an external system to set an ExtendedProperties object to use. |
private void |
setDefaultProperties()
Initializes the Velocity Runtime with properties file. |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Allows an external system to set a property in the Velocity Runtime. |
private boolean |
showStackTrace()
Added this to check and make sure that the configuration is initialized before trying to get properties from it. |
void |
warn(java.lang.Object message)
Log a warning message. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private VelocimacroFactory vmFactory
private LogSystem logSystem
private SimplePool parserPool
private boolean initialized
private org.apache.commons.collections.ExtendedProperties overridingProperties
private java.util.Hashtable runtimeDirectives
private org.apache.commons.collections.ExtendedProperties configuration
private ResourceManager resourceManager
private Introspector introspector
private java.util.Map applicationAttributes
private Uberspect uberSpect
Constructor Detail |
public RuntimeInstance()
Method Detail |
public void init() throws java.lang.Exception
init
in interface RuntimeServices
private void initializeIntrospection() throws java.lang.Exception
private void setDefaultProperties()
public void setProperty(java.lang.String key, java.lang.Object value)
setProperty
in interface RuntimeServices
String
- property keyString
- property valuepublic void setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
setConfiguration
in interface RuntimeServices
ExtendedProperties
- configurationpublic void addProperty(java.lang.String key, java.lang.Object value)
addProperty
in interface RuntimeServices
String
- keyString
- valuepublic void clearProperty(java.lang.String key)
clearProperty
in interface RuntimeServices
String
- key of property to clearpublic java.lang.Object getProperty(java.lang.String key)
getProperty
in interface RuntimeServices
key
- property to returnprivate void initializeProperties()
public void init(java.util.Properties p) throws java.lang.Exception
init
in interface RuntimeServices
Properties
- public void init(java.lang.String configurationFile) throws java.lang.Exception
init
in interface RuntimeServices
Properties
- private void initializeResourceManager() throws java.lang.Exception
private void initializeLogger() throws java.lang.Exception
java.lang.Exception
- private void initializeDirectives() throws java.lang.Exception
java.lang.Exception
- private void loadDirective(java.lang.String directiveClass, java.lang.String caption)
directiveClass
- classname of directive to loadprivate void initializeParserPool()
public Parser createNewParser()
public SimpleNode parse(java.io.Reader reader, java.lang.String templateName) throws ParseException
parse
in interface RuntimeServices
InputStream
- inputstream retrieved by a resource loaderString
- name of the template being parsedpublic SimpleNode parse(java.io.Reader reader, java.lang.String templateName, boolean dumpNamespace) throws ParseException
parse
in interface RuntimeServices
InputStream
- inputstream retrieved by a resource loaderString
- name of the template being parseddumpNamespace
- flag to dump the Velocimacro namespace for this templatepublic 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"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.java.lang.Exception
- if an error occurs in template initializationpublic Template getTemplate(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
Template
from the resource managergetTemplate
in interface RuntimeServices
name
- 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 ContentResource getContent(java.lang.String name) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
getContent
in interface RuntimeServices
name
- Name of content resource to getResourceNotFoundException
- if template not found
from any available source.public ContentResource getContent(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException, java.lang.Exception
getContent
in interface RuntimeServices
name
- Name of content resource to getencoding
- Character encoding to useResourceNotFoundException
- if template not found
from any available source.public java.lang.String getLoaderNameForResource(java.lang.String resourceName)
getLoaderNameForResource
in interface RuntimeServices
resourceName
- Name of template or content resourceprivate boolean showStackTrace()
private void log(int level, java.lang.Object message)
String
- message to logpublic void warn(java.lang.Object message)
warn
in interface RuntimeLogger
Object
- message to logpublic void info(java.lang.Object message)
info
in interface RuntimeLogger
Object
- message to logpublic void error(java.lang.Object message)
error
in interface RuntimeLogger
Object
- message to logpublic void debug(java.lang.Object message)
debug
in interface RuntimeLogger
Object
- message to logpublic java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
getString
in interface RuntimeServices
String
- key property keyString
- defaultValue default value to return if key not
found in resource manager.public Directive getVelocimacro(java.lang.String vmName, java.lang.String templateName)
getVelocimacro
in interface RuntimeServices
String
- vmName Name of velocimacro requestedpublic boolean addVelocimacro(java.lang.String name, java.lang.String macro, java.lang.String[] argArray, java.lang.String sourceTemplate)
addVelocimacro
in interface RuntimeServices
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 boolean isVelocimacro(java.lang.String vmName, java.lang.String templateName)
isVelocimacro
in interface RuntimeServices
name
- Name of velocimacropublic boolean dumpVMNamespace(java.lang.String namespace)
dumpVMNamespace
in interface RuntimeServices
public java.lang.String getString(java.lang.String key)
getString
in interface RuntimeServices
key
- property keypublic int getInt(java.lang.String key)
getInt
in interface RuntimeServices
String
- key property keypublic int getInt(java.lang.String key, int defaultValue)
getInt
in interface RuntimeServices
key
- property keyint
- default valuepublic boolean getBoolean(java.lang.String key, boolean def)
getBoolean
in interface RuntimeServices
String
- key property keyboolean
- default default value if property not foundpublic org.apache.commons.collections.ExtendedProperties getConfiguration()
getConfiguration
in interface RuntimeServices
public Introspector getIntrospector()
getIntrospector
in interface RuntimeServices
public java.lang.Object getApplicationAttribute(java.lang.Object key)
RuntimeServices
getApplicationAttribute
in interface RuntimeServices
org.apache.velocity.runtime.RuntimeServices
key
- The name of the attribute to retrieve.public java.lang.Object setApplicationAttribute(java.lang.Object key, java.lang.Object o)
public Uberspect getUberspect()
RuntimeServices
getUberspect
in interface RuntimeServices
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |