|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 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 RuntimeServicesjava.lang.Exception
private void initializeIntrospection()
throws java.lang.Exception
java.lang.Exceptionprivate void setDefaultProperties()
public void setProperty(java.lang.String key,
java.lang.Object value)
setProperty in interface RuntimeServicespublic void setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
setConfiguration in interface RuntimeServices
public void addProperty(java.lang.String key,
java.lang.Object value)
addProperty in interface RuntimeServicespublic void clearProperty(java.lang.String key)
clearProperty in interface RuntimeServicespublic java.lang.Object getProperty(java.lang.String key)
getProperty in interface RuntimeServiceskey - property to returnprivate void initializeProperties()
public void init(java.util.Properties p)
throws java.lang.Exception
init in interface RuntimeServicesjava.lang.Exception
public void init(java.lang.String configurationFile)
throws java.lang.Exception
init in interface RuntimeServicesjava.lang.Exception
private void initializeResourceManager()
throws java.lang.Exception
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 RuntimeServicesParseException
public SimpleNode parse(java.io.Reader reader,
java.lang.String templateName,
boolean dumpNamespace)
throws ParseException
parse in interface RuntimeServicesdumpNamespace - flag to dump the Velocimacro namespace for this template
ParseException
public 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 RuntimeServicesname - 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 initialization
public Template getTemplate(java.lang.String name,
java.lang.String encoding)
throws ResourceNotFoundException,
ParseErrorException,
java.lang.Exception
Template from the resource manager
getTemplate in interface RuntimeServicesname - 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.
java.lang.Exception - if an error occurs in template initialization
public ContentResource getContent(java.lang.String name)
throws ResourceNotFoundException,
ParseErrorException,
java.lang.Exception
getContent in interface RuntimeServicesname - Name of content resource to get
ResourceNotFoundException - if template not found
from any available source.
ParseErrorException
java.lang.Exception
public ContentResource getContent(java.lang.String name,
java.lang.String encoding)
throws ResourceNotFoundException,
ParseErrorException,
java.lang.Exception
getContent in interface RuntimeServicesname - Name of content resource to getencoding - Character encoding to use
ResourceNotFoundException - if template not found
from any available source.
ParseErrorException
java.lang.Exceptionpublic java.lang.String getLoaderNameForResource(java.lang.String resourceName)
getLoaderNameForResource in interface RuntimeServicesresourceName - Name of template or content resource
private boolean showStackTrace()
private void log(int level,
java.lang.Object message)
public void warn(java.lang.Object message)
warn in interface RuntimeLoggerpublic void info(java.lang.Object message)
info in interface RuntimeLoggerpublic void error(java.lang.Object message)
error in interface RuntimeLoggerpublic void debug(java.lang.Object message)
debug in interface RuntimeLogger
public java.lang.String getString(java.lang.String key,
java.lang.String defaultValue)
getString in interface RuntimeServices
public Directive getVelocimacro(java.lang.String vmName,
java.lang.String templateName)
getVelocimacro in interface RuntimeServices
public boolean addVelocimacro(java.lang.String name,
java.lang.String macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
addVelocimacro in interface RuntimeServices
public boolean isVelocimacro(java.lang.String vmName,
java.lang.String templateName)
isVelocimacro in interface RuntimeServicespublic boolean dumpVMNamespace(java.lang.String namespace)
dumpVMNamespace in interface RuntimeServicespublic java.lang.String getString(java.lang.String key)
getString in interface RuntimeServiceskey - property key
public int getInt(java.lang.String key)
getInt in interface RuntimeServices
public int getInt(java.lang.String key,
int defaultValue)
getInt in interface RuntimeServiceskey - property key
public boolean getBoolean(java.lang.String key,
boolean def)
getBoolean in interface RuntimeServicespublic org.apache.commons.collections.ExtendedProperties getConfiguration()
getConfiguration in interface RuntimeServicespublic Introspector getIntrospector()
getIntrospector in interface RuntimeServicespublic java.lang.Object getApplicationAttribute(java.lang.Object key)
RuntimeServices
getApplicationAttribute in interface RuntimeServiceskey - 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: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||