|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.runtime.RuntimeSingleton
public class RuntimeSingleton
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:
RuntimeSingleton.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath); RuntimeSingleton.setProperty(RuntimeConstants.RUNTIME_LOG, pathToVelocityLog); RuntimeSingleton.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 ----------------------------------------------------------------------- RuntimeSingleton.init() If Runtime.init() is called by itself the Runtime will initialize with a set of default values. ----------------------------------------------------------------------- RuntimeSingleton.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. -----------------------------------------------------------------------
RuntimeInstance
Field Summary |
---|
Constructor Summary | |
---|---|
RuntimeSingleton()
|
Method Summary | |
---|---|
static void |
addProperty(String key,
Object value)
Add a property to the configuration. |
static boolean |
addVelocimacro(String name,
Node macro,
String[] argArray,
String sourceTemplate)
Adds a new Velocimacro. |
static boolean |
addVelocimacro(String name,
String macro,
String[] argArray,
String sourceTemplate)
Deprecated. Use addVelocimacro(String, Node, String[], String) instead |
static void |
clearProperty(String key)
Clear the values pertaining to a particular property. |
static void |
debug(Object message)
Deprecated. Use getLog() and call debug() on it. |
static boolean |
dumpVMNamespace(String namespace)
tells the vmFactory to dump the specified namespace. |
static void |
error(Object message)
Deprecated. Use getLog() and call error() on it. |
static Object |
getApplicationAttribute(Object key)
Gets the application attribute for the given key |
static boolean |
getBoolean(String key,
boolean def)
Boolean property accessor method to hide the configuration implementation. |
static ExtendedProperties |
getConfiguration()
Return the velocity runtime configuration object. |
static ContentResource |
getContent(String name)
Returns a static content resource from the resource manager. |
static ContentResource |
getContent(String name,
String encoding)
Returns a static content resource from the resource manager. |
EventCartridge |
getEventCartridge()
Returns the event handlers for the application. |
static int |
getInt(String key)
Int property accessor method to hide the configuration implementation. |
static int |
getInt(String key,
int defaultValue)
Int property accessor method to hide the configuration implementation. |
static Introspector |
getIntrospector()
Return the Introspector for this RuntimeInstance |
static String |
getLoaderNameForResource(String resourceName)
Determines is a template exists, and returns name of the loader that provides it. |
static Log |
getLog()
Returns a convenient Log instance that wraps the current LogChute. |
static Object |
getProperty(String key)
Allows an external caller to get a property. |
static RuntimeInstance |
getRuntimeInstance()
Deprecated. Use getRuntimeServices() instead. |
static RuntimeServices |
getRuntimeServices()
Returns the RuntimeServices Instance used by this wrapper. |
static String |
getString(String key)
String property accessor method to hide the configuration implementation |
static String |
getString(String key,
String defaultValue)
String property accessor method with default to hide the configuration implementation. |
static Template |
getTemplate(String name)
Returns a Template from the resource manager. |
static Template |
getTemplate(String name,
String encoding)
Returns a Template from the resource manager |
static Uberspect |
getUberspect()
Returns the Uberspect object for this Instance. |
static Directive |
getVelocimacro(String vmName,
String templateName)
Returns the appropriate VelocimacroProxy object if strVMname is a valid current Velocimacro. |
static void |
info(Object message)
Deprecated. Use getLog() and call info() on it. |
static void |
init()
This is the primary initialization method in the Velocity Runtime. |
static void |
init(Properties p)
Initialize the Velocity Runtime with a Properties object. |
static void |
init(String configurationFile)
Initialize the Velocity Runtime with the name of ExtendedProperties object. |
static boolean |
isInitialized()
Returns true if the RuntimeInstance has been successfully initialized. |
static boolean |
isVelocimacro(String vmName,
String templateName)
Checks to see if a VM exists |
static void |
loadDirective(String directiveClass)
Instantiates and loads the directive with some basic checks. |
static SimpleNode |
parse(Reader reader,
String templateName)
Parse the input and return the root of AST node structure. |
static SimpleNode |
parse(Reader reader,
String templateName,
boolean dumpNamespace)
Parse the input and return the root of the AST node structure. |
static void |
removeDirective(String name)
Remove a directive. |
static void |
setConfiguration(ExtendedProperties configuration)
Allow an external system to set an ExtendedProperties object to use. |
static void |
setProperty(String key,
Object value)
Allows an external system to set a property in the Velocity Runtime. |
static void |
warn(Object message)
Deprecated. Use getLog() and call warn() on it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RuntimeSingleton()
Method Detail |
---|
public static void init()
RuntimeInstance.init()
public static boolean isInitialized()
RuntimeInstance.isInitialized()
public static RuntimeServices getRuntimeServices()
public static void setProperty(String key, Object value)
key
- property keyvalue
- property valueRuntimeInstance.setProperty(String, Object)
public static void setConfiguration(ExtendedProperties configuration)
configuration
- RuntimeInstance.setConfiguration(ExtendedProperties)
public static void addProperty(String key, Object value)
key
- value
- RuntimeInstance.addProperty(String, Object)
public static void clearProperty(String key)
key
- of property to clearRuntimeInstance.clearProperty(String)
public static Object getProperty(String key)
key
- property to return
RuntimeInstance.getProperty(String)
public static void init(Properties p)
p
- RuntimeInstance.init(Properties)
public static void init(String configurationFile)
configurationFile
- RuntimeInstance.init(String)
public static SimpleNode parse(Reader reader, String templateName) throws ParseException
reader
- Reader retrieved by a resource loadertemplateName
- name of the template being parsed
ParseException
- When the template could not be parsed.RuntimeInstance.parse(Reader, String)
public static SimpleNode parse(Reader reader, String templateName, boolean dumpNamespace) throws ParseException
reader
- Reader retrieved by a resource loadertemplateName
- name of the template being parseddumpNamespace
- flag to dump the Velocimacro namespace for this template
ParseException
- When the template could not be parsed.RuntimeInstance.parse(Reader, String, boolean)
public static Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException
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.RuntimeInstance.getTemplate(String)
public static Template getTemplate(String name, String encoding) throws ResourceNotFoundException, ParseErrorException
Template
from the resource manager
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.RuntimeInstance.getTemplate(String, String)
public static ContentResource getContent(String name) throws ResourceNotFoundException, ParseErrorException
name
- Name of content resource to get
ResourceNotFoundException
- if template not found
from any available source.
ParseErrorException
- When the template could not be parsed.RuntimeInstance.getContent(String)
public static ContentResource getContent(String name, String encoding) throws ResourceNotFoundException, ParseErrorException
name
- Name of content resource to getencoding
- Character encoding to use
ResourceNotFoundException
- if template not found
from any available source.
ParseErrorException
- When the template could not be parsed.RuntimeInstance.getContent(String, String)
public static String getLoaderNameForResource(String resourceName)
resourceName
- Name of template or content resource
RuntimeInstance.getLoaderNameForResource(String)
public static Log getLog()
RuntimeInstance.getLog()
public static void warn(Object message)
message
- The message to log.Log.warn(Object)
public static void info(Object message)
message
- The message to log.Log.info(Object)
public static void error(Object message)
message
- The message to log.Log.error(Object)
public static void debug(Object message)
message
- The message to log.Log.debug(Object)
public static String getString(String key, String defaultValue)
key
- property keydefaultValue
- default value to return if key not
found in resource manager.
RuntimeInstance.getString(String, String)
public static Directive getVelocimacro(String vmName, String templateName)
vmName
- Name of velocimacro requestedtemplateName
- Name of the template that contains the velocimacro.
RuntimeInstance.getVelocimacro(String, String)
public static boolean addVelocimacro(String name, Node macro, String[] argArray, String sourceTemplate)
name
- Name of a new velocimacro.macro
- root AST node of the parsed macroargArray
- Array of strings, containing the
#macro() arguments. the 0th argument is the name.sourceTemplate
- The template from which the macro is requested.
RuntimeInstance.addVelocimacro(String, Node, String[], String)
public static boolean addVelocimacro(String name, String macro, String[] argArray, String sourceTemplate)
name
- Name of velocimacromacro
- String form of macro bodyargArray
- Array of strings, containing the
#macro() arguments. the 0th is the name.sourceTemplate
- Name of the template that contains the velocimacro.
RuntimeInstance.addVelocimacro(String, String, String[], String)
public static boolean isVelocimacro(String vmName, String templateName)
vmName
- Name of the Velocimacro.templateName
- Template on which to look for the Macro.
RuntimeInstance.isVelocimacro(String, String)
public static boolean dumpVMNamespace(String namespace)
namespace
- Namespace to dump.
RuntimeInstance.dumpVMNamespace(String)
public static String getString(String key)
key
- property key
RuntimeInstance.getString(String)
public static int getInt(String key)
key
- Property key
RuntimeInstance.getInt(String)
public static int getInt(String key, int defaultValue)
key
- property keydefaultValue
- The default value.
RuntimeInstance.getInt(String, int)
public static boolean getBoolean(String key, boolean def)
key
- property keydef
- The default value if property not found.
RuntimeInstance.getBoolean(String, boolean)
public static ExtendedProperties getConfiguration()
RuntimeInstance.getConfiguration()
public static Introspector getIntrospector()
RuntimeInstance.getIntrospector()
public EventCartridge getEventCartridge()
RuntimeInstance.getApplicationEventCartridge()
public static Object getApplicationAttribute(Object key)
key
-
RuntimeServices.getApplicationAttribute(Object)
,
RuntimeInstance.getApplicationAttribute(Object)
public static Uberspect getUberspect()
RuntimeServices.getUberspect()
,
RuntimeInstance.getUberspect()
public static RuntimeInstance getRuntimeInstance()
public static void removeDirective(String name)
name
- name of the directive.public static void loadDirective(String directiveClass)
directiveClass
- classname of directive to load
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |