public class RuntimeInstance extends java.lang.Object implements RuntimeConstants, RuntimeServices
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. -----------------------------------------------------------------------
COUNTER_INITIAL_VALUE, COUNTER_NAME, DEBUG_PREFIX, DEFAULT_RUNTIME_DIRECTIVES, DEFAULT_RUNTIME_PROPERTIES, DEFINE_DIRECTIVE_MAXDEPTH, DIRECTIVE_IF_TOSTRING_NULLCHECK, ENCODING_DEFAULT, ERROR_PREFIX, ERRORMSG_END, ERRORMSG_START, EVALUATE_CONTEXT_CLASS, EVENTHANDLER_INCLUDE, EVENTHANDLER_INVALIDREFERENCES, EVENTHANDLER_METHODEXCEPTION, EVENTHANDLER_NULLSET, EVENTHANDLER_REFERENCEINSERTION, FILE_RESOURCE_LOADER_CACHE, FILE_RESOURCE_LOADER_PATH, HAS_NEXT_NAME, INFO_PREFIX, INPUT_ENCODING, INTERPOLATE_STRINGLITERALS, INTROSPECTOR_RESTRICT_CLASSES, INTROSPECTOR_RESTRICT_PACKAGES, MAX_NUMBER_LOOPS, NUMBER_OF_PARSERS, OUTPUT_ENCODING, PARSE_DIRECTIVE_MAXDEPTH, PARSER_POOL_CLASS, PARSER_POOL_SIZE, PROVIDE_SCOPE_CONTROL, RESOURCE_LOADER, RESOURCE_MANAGER_CACHE_CLASS, RESOURCE_MANAGER_CLASS, RESOURCE_MANAGER_DEFAULTCACHE_SIZE, RESOURCE_MANAGER_LOGWHENFOUND, RUNTIME_LOG, RUNTIME_LOG_ERROR_STACKTRACE, RUNTIME_LOG_INFO_STACKTRACE, RUNTIME_LOG_LOGSYSTEM, RUNTIME_LOG_LOGSYSTEM_CLASS, RUNTIME_LOG_REFERENCE_LOG_INVALID, RUNTIME_LOG_WARN_STACKTRACE, RUNTIME_REFERENCES_STRICT, RUNTIME_REFERENCES_STRICT_ESCAPE, SET_NULL_ALLOWED, SKIP_INVALID_ITERATOR, STRICT_MATH, TRACE_PREFIX, UBERSPECT_CLASSNAME, UNKNOWN_PREFIX, VM_ARGUMENTS_STRICT, VM_BODY_REFERENCE, VM_CONTEXT_LOCALSCOPE, VM_LIBRARY, VM_LIBRARY_AUTORELOAD, VM_LIBRARY_DEFAULT, VM_MAX_DEPTH, VM_MESSAGES_ON, VM_PERM_ALLOW_INLINE, VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, VM_PERM_INLINE_LOCAL, WARN_PREFIX| 构造器和说明 |
|---|
RuntimeInstance()
Creates a new RuntimeInstance object.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addDirective(Directive directive)
Programatically add a directive.
|
void |
addProperty(java.lang.String key,
java.lang.Object value)
Add a property to the configuration.
|
boolean |
addVelocimacro(java.lang.String name,
Node macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
Adds a new Velocimacro.
|
boolean |
addVelocimacro(java.lang.String name,
java.lang.String macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
已过时。
Use addVelocimacro(String, Node, String[], String) instead
|
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)
已过时。
Use getLog() and call debug() on it.
|
boolean |
dumpVMNamespace(java.lang.String namespace)
tells the vmFactory to dump the specified namespace.
|
void |
error(java.lang.Object message)
已过时。
Use getLog() and call error() on it.
|
boolean |
evaluate(Context context,
java.io.Writer writer,
java.lang.String logTag,
java.io.Reader reader)
Renders the input reader using the context into the output writer.
|
boolean |
evaluate(Context context,
java.io.Writer out,
java.lang.String logTag,
java.lang.String instring)
Renders the input string using the context into the output writer.
|
java.lang.Object |
getApplicationAttribute(java.lang.Object key)
Gets the application attribute for the given key
|
EventCartridge |
getApplicationEventCartridge()
Returns the event handlers for the application.
|
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.
|
Directive |
getDirective(java.lang.String name)
Retrieve a previously instantiated directive.
|
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 if a template exists and returns name of the loader that
provides it.
|
Log |
getLog()
Returns a convenient Log instance that wraps the current LogChute.
|
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 Uberspect object for this Instance.
|
Directive |
getVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Returns the appropriate VelocimacroProxy object if vmName
is a valid current Velocimacro.
|
Directive |
getVelocimacro(java.lang.String vmName,
java.lang.String templateName,
java.lang.String renderingTemplate)
Returns the appropriate VelocimacroProxy object if vmName
is a valid current Velocimacro.
|
void |
info(java.lang.Object message)
已过时。
Use getLog() and call info() on it.
|
void |
init()
This is the primary initialization method in the Velocity
Runtime.
|
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.
|
void |
initTemplate(Resource template) |
void |
initTemplate(Resource template,
java.lang.String encoding)
Returns a
Template from the resource manager |
boolean |
invokeVelocimacro(java.lang.String vmName,
java.lang.String logTag,
java.lang.String[] params,
Context context,
java.io.Writer writer)
Invokes a currently registered Velocimacro with the params provided
and places the rendered stream into the writer.
|
boolean |
isInitialized()
Returns true if the RuntimeInstance has been successfully initialized.
|
boolean |
isVelocimacro(java.lang.String vmName,
java.lang.String templateName)
Checks to see if a VM exists
|
void |
loadDirective(java.lang.String directiveClass)
instantiates and loads the directive with some basic checks
|
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.
|
SimpleNode |
parse(java.lang.String string,
java.lang.String templateName)
Parse the input and return the root of
AST node structure.
|
void |
removeDirective(java.lang.String name)
Remove a directive.
|
boolean |
render(Context context,
java.io.Writer writer,
java.lang.String logTag,
SimpleNode nodeTree)
Initializes and renders the AST
SimpleNode using the context
into the output writer. |
java.lang.Object |
setApplicationAttribute(java.lang.Object key,
java.lang.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 |
setProperties(java.util.Properties props)
Add all the properties in props to the RuntimeInstance properties
|
void |
setProperties(java.lang.String fileName)
Add all properties contained in the file fileName to the RuntimeInstance properties
|
void |
setProperty(java.lang.String key,
java.lang.Object value)
Allows an external system to set a property in
the Velocity Runtime.
|
void |
warn(java.lang.Object message)
已过时。
Use getLog() and call warn() on it.
|
public void init()
init 在接口中 RuntimeServicespublic boolean isInitialized()
isInitialized 在接口中 RuntimeServicespublic void setProperty(java.lang.String key,
java.lang.Object value)
setProperty 在接口中 RuntimeServiceskey - property keyvalue - property valuepublic void setProperties(java.lang.String fileName)
public void setProperties(java.util.Properties props)
public void setConfiguration(org.apache.commons.collections.ExtendedProperties configuration)
setConfiguration 在接口中 RuntimeServicesconfiguration - public void addProperty(java.lang.String key,
java.lang.Object value)
addProperty 在接口中 RuntimeServiceskey - value - public void clearProperty(java.lang.String key)
clearProperty 在接口中 RuntimeServiceskey - of property to clearpublic java.lang.Object getProperty(java.lang.String key)
getProperty 在接口中 RuntimeServiceskey - property to returnpublic void init(java.util.Properties p)
init 在接口中 RuntimeServicesp - Velocity properties for initializationpublic void init(java.lang.String configurationFile)
init 在接口中 RuntimeServicesconfigurationFile - public void addDirective(Directive directive)
directive - public Directive getDirective(java.lang.String name)
getDirective 在接口中 RuntimeServicesname - name of the directiveDirective for that namepublic void removeDirective(java.lang.String name)
name - name of the directive.public void loadDirective(java.lang.String directiveClass)
directiveClass - classname of directive to loadpublic Parser createNewParser()
createNewParser 在接口中 RuntimeServicespublic SimpleNode parse(java.lang.String string, java.lang.String templateName) throws ParseException
parse 在接口中 RuntimeServicesstring - String to be parsedtemplateName - name of the template being parsedParseException - When the string could not be parsed as a template.public SimpleNode parse(java.io.Reader reader, java.lang.String templateName) throws ParseException
parse 在接口中 RuntimeServicesreader - Reader retrieved by a resource loadertemplateName - name of the template being parsedParseException - When the template could not be parsed.public SimpleNode parse(java.io.Reader reader, java.lang.String templateName, boolean dumpNamespace) throws ParseException
parse 在接口中 RuntimeServicesreader - Reader retrieved by a resource loadertemplateName - name of the template being parseddumpNamespace - flag to dump the Velocimacro namespace for this templateParseException - When the template could not be parsed.public boolean evaluate(Context context, java.io.Writer out, java.lang.String logTag, java.lang.String instring)
evaluate 在接口中 RuntimeServicescontext - context to use in rendering input stringout - Writer in which to render the outputlogTag - string to be used as the template name for log
messages in case of errorinstring - input string containing the VTL to be renderedParseErrorException - The template could not be parsed.MethodInvocationException - A method on a context object could not be invoked.ResourceNotFoundException - A referenced resource could not be loaded.public boolean evaluate(Context context, java.io.Writer writer, java.lang.String logTag, java.io.Reader reader)
evaluate 在接口中 RuntimeServicescontext - context to use in rendering input stringwriter - Writer in which to render the outputlogTag - string to be used as the template name for log messages
in case of errorreader - Reader containing the VTL to be renderedParseErrorException - The template could not be parsed.MethodInvocationException - A method on a context object could not be invoked.ResourceNotFoundException - A referenced resource could not be loaded.public boolean render(Context context, java.io.Writer writer, java.lang.String logTag, SimpleNode nodeTree)
SimpleNode using the context
into the output writer.context - context to use in rendering input stringwriter - Writer in which to render the outputlogTag - string to be used as the template name for log messages
in case of errornodeTree - SimpleNode which is the root of the AST to be renderedParseErrorException - The template could not be parsed.MethodInvocationException - A method on a context object could not be invoked.ResourceNotFoundException - A referenced resource could not be loaded.public boolean invokeVelocimacro(java.lang.String vmName,
java.lang.String logTag,
java.lang.String[] params,
Context context,
java.io.Writer writer)
invokeVelocimacro 在接口中 RuntimeServicesvmName - name of Velocimacro to calllogTag - string to be used for template name in case of error. if null,
the vmName will be usedparams - keys for args used to invoke Velocimacro, in java format
rather than VTL (eg "foo" or "bar" rather than "$foo" or "$bar")context - Context object containing data/objects used for rendering.writer - Writer for output streampublic Template getTemplate(java.lang.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"getTemplate 在接口中 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.public void initTemplate(Resource template)
public Template getTemplate(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException
Template from the resource managergetTemplate 在接口中 RuntimeServicesname - 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.public void initTemplate(Resource template, java.lang.String encoding)
Template from the resource managerencoding - 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.public ContentResource getContent(java.lang.String name) throws ResourceNotFoundException, ParseErrorException
getContent 在接口中 RuntimeServicesname - Name of content resource to getResourceNotFoundException - if template not found
from any available source.ParseErrorException - When the template could not be parsed.public ContentResource getContent(java.lang.String name, java.lang.String encoding) throws ResourceNotFoundException, ParseErrorException
getContent 在接口中 RuntimeServicesname - Name of content resource to getencoding - Character encoding to useResourceNotFoundException - if template not found
from any available source.ParseErrorException - When the template could not be parsed.public java.lang.String getLoaderNameForResource(java.lang.String resourceName)
getLoaderNameForResource 在接口中 RuntimeServicesresourceName - Name of template or content resourcepublic Log getLog()
getLog 在接口中 RuntimeServicespublic void warn(java.lang.Object message)
warn 在接口中 RuntimeLoggermessage - The message to log.Log.warn(Object)public void info(java.lang.Object message)
info 在接口中 RuntimeLoggermessage - The message to log.Log.info(Object)public void error(java.lang.Object message)
error 在接口中 RuntimeLoggermessage - The message to log.Log.error(Object)public void debug(java.lang.Object message)
debug 在接口中 RuntimeLoggermessage - The message to log.Log.debug(Object)public java.lang.String getString(java.lang.String key,
java.lang.String defaultValue)
getString 在接口中 RuntimeServiceskey - property keydefaultValue - default value to return if key not
found in resource manager.public Directive getVelocimacro(java.lang.String vmName, java.lang.String templateName)
getVelocimacro 在接口中 RuntimeServicesvmName - Name of velocimacro requestedtemplateName - Name of the template that contains the velocimacro.public Directive getVelocimacro(java.lang.String vmName, java.lang.String templateName, java.lang.String renderingTemplate)
getVelocimacro 在接口中 RuntimeServicesvmName - Name of velocimacro requestedtemplateName - Name of the namespace.renderingTemplate - Name of the template we are currently rendering. This
information is needed when VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL setting is true
and template contains a macro with the same name as the global macro library.public boolean addVelocimacro(java.lang.String name,
java.lang.String macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
addVelocimacro 在接口中 RuntimeServicesname - 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.public boolean addVelocimacro(java.lang.String name,
Node macro,
java.lang.String[] argArray,
java.lang.String sourceTemplate)
addVelocimacro 在接口中 RuntimeServicesname - Name of velocimacromacro - root AST node of the parsed macroargArray - Array of strings, containing the
#macro() arguments. the 0th is the name.sourceTemplate - public boolean isVelocimacro(java.lang.String vmName,
java.lang.String templateName)
isVelocimacro 在接口中 RuntimeServicesvmName - Name of the Velocimacro.templateName - Template on which to look for the Macro.public boolean dumpVMNamespace(java.lang.String namespace)
dumpVMNamespace 在接口中 RuntimeServicesnamespace - Namespace to dump.public java.lang.String getString(java.lang.String key)
getString 在接口中 RuntimeServiceskey - property keypublic int getInt(java.lang.String key)
getInt 在接口中 RuntimeServiceskey - Property keypublic int getInt(java.lang.String key,
int defaultValue)
getInt 在接口中 RuntimeServiceskey - property keydefaultValue - The default value.public boolean getBoolean(java.lang.String key,
boolean def)
getBoolean 在接口中 RuntimeServiceskey - property keydef - The default value if property not found.public org.apache.commons.collections.ExtendedProperties getConfiguration()
getConfiguration 在接口中 RuntimeServicespublic Introspector getIntrospector()
getIntrospector 在接口中 RuntimeServicespublic EventCartridge getApplicationEventCartridge()
getApplicationEventCartridge 在接口中 RuntimeServicespublic java.lang.Object getApplicationAttribute(java.lang.Object key)
getApplicationAttribute 在接口中 RuntimeServiceskey - public java.lang.Object setApplicationAttribute(java.lang.Object key,
java.lang.Object o)
setApplicationAttribute 在接口中 RuntimeServiceskey - o - The new application attribute.public Uberspect getUberspect()
getUberspect 在接口中 RuntimeServices