public class RuntimeInstance extends Object implements RuntimeConstants, RuntimeServices
RuntimeConstants.SpaceGobbling
CHECK_EMPTY_OBJECTS, CONTEXT_AUTOREFERENCE_KEY, CONVERSION_HANDLER_CLASS, DEFAULT_RUNTIME_DIRECTIVES, DEFAULT_RUNTIME_LOG_NAME, DEFAULT_RUNTIME_PROPERTIES, DEFINE_DIRECTIVE_MAXDEPTH, ENCODING_DEFAULT, ERRORMSG_END, ERRORMSG_START, EVENTHANDLER_INCLUDE, EVENTHANDLER_INVALIDREFERENCES, EVENTHANDLER_METHODEXCEPTION, EVENTHANDLER_REFERENCEINSERTION, FILE_RESOURCE_LOADER_CACHE, FILE_RESOURCE_LOADER_PATH, INPUT_ENCODING, INTERPOLATE_STRINGLITERALS, INTROSPECTOR_RESTRICT_CLASSES, INTROSPECTOR_RESTRICT_PACKAGES, MAX_NUMBER_LOOPS, NUMBER_OF_PARSERS, PARSE_DIRECTIVE_MAXDEPTH, PARSER_POOL_CLASS, PARSER_POOL_SIZE, PROVIDE_SCOPE_CONTROL, RESOURCE_LOADER, RESOURCE_LOADER_IDENTIFIER, RESOURCE_MANAGER_CACHE_CLASS, RESOURCE_MANAGER_CLASS, RESOURCE_MANAGER_DEFAULTCACHE_SIZE, RESOURCE_MANAGER_INSTANCE, RESOURCE_MANAGER_LOGWHENFOUND, RUNTIME_LOG_INSTANCE, RUNTIME_LOG_NAME, RUNTIME_LOG_REFERENCE_LOG_INVALID, RUNTIME_REFERENCES_STRICT, RUNTIME_REFERENCES_STRICT_ESCAPE, RUNTIME_STRING_INTERNING, SKIP_INVALID_ITERATOR, SPACE_GOBBLING, STRICT_MATH, UBERSPECT_CLASSNAME, VM_ARGUMENTS_STRICT, VM_BODY_REFERENCE, 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
Constructor and Description |
---|
RuntimeInstance()
Creates a new RuntimeInstance object.
|
Modifier and Type | Method and Description |
---|---|
void |
addDirective(Directive directive)
Programatically add a directive.
|
void |
addProperty(String key,
Object value)
Add a property to the configuration.
|
boolean |
addVelocimacro(String name,
Node macro,
List<Macro.MacroArg> macroArgs,
Template definingTemplate)
Adds a new Velocimacro.
|
void |
clearProperty(String key)
Clear the values pertaining to a particular
property.
|
Parser |
createNewParser()
Returns a JavaCC generated Parser.
|
boolean |
evaluate(Context context,
Writer writer,
String logTag,
Reader reader)
Renders the input reader using the context into the output writer.
|
boolean |
evaluate(Context context,
Writer out,
String logTag,
String instring)
Renders the input string using the context into the output writer.
|
Object |
getApplicationAttribute(Object key)
Gets the application attribute for the given key
|
EventCartridge |
getApplicationEventCartridge()
Returns the event handlers for the application.
|
boolean |
getBoolean(String key,
boolean def)
Boolean property accessor method to hide the configuration implementation.
|
ExtProperties |
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.
|
Directive |
getDirective(String name)
Retrieve a previously instantiated directive.
|
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.
|
String |
getLoaderNameForResource(String resourceName)
Determines if a template exists and returns name of the loader that
provides it.
|
org.slf4j.Logger |
getLog()
Returns a convenient Log instance that wraps the current LogChute.
|
org.slf4j.Logger |
getLog(String childNamespace)
Get a logger for the specified child namespace.
|
Object |
getProperty(String key)
Allows an external caller to get a property.
|
RuntimeConstants.SpaceGobbling |
getSpaceGobbling()
get space gobbling mode
|
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 Uberspect object for this Instance.
|
Directive |
getVelocimacro(String vmName,
Template renderingTemplate,
Template template)
Returns the appropriate VelocimacroProxy object if vmName
is a valid current Velocimacro.
|
void |
init()
This is the primary initialization method in the Velocity
Runtime.
|
void |
init(Properties p)
Initialize the Velocity Runtime with a Properties
object.
|
void |
init(String configurationFile)
Initialize the Velocity Runtime with a
properties file path.
|
boolean |
invokeVelocimacro(String vmName,
String logTag,
String[] params,
Context context,
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(String vmName,
Template template)
Checks to see if a VM exists
|
void |
loadDirective(String directiveClass)
instantiates and loads the directive with some basic checks
|
SimpleNode |
parse(Reader reader,
Template template)
Parse the input and return the root of
AST node structure.
|
void |
removeDirective(String name)
Remove a directive.
|
boolean |
render(Context context,
Writer writer,
String logTag,
SimpleNode nodeTree)
Initializes and renders the AST
SimpleNode using the context
into the output writer. |
void |
reset()
Resets the instance, so Velocity can be re-initialized again.
|
Object |
setApplicationAttribute(Object key,
Object o)
Sets the application attribute for the given key
|
void |
setConfiguration(ExtProperties configuration)
Allow an external system to set an ExtProperties
object to use.
|
void |
setProperties(Properties props)
Add all the properties in props to the RuntimeInstance properties
|
void |
setProperties(String fileName)
Add all properties contained in the file fileName to the RuntimeInstance properties
|
void |
setProperty(String key,
Object value)
Allows an external system to set a property in
the Velocity Runtime.
|
boolean |
useStringInterning()
Whether to use string interning
|
public void init()
init
in interface RuntimeServices
public void reset()
public boolean isInitialized()
isInitialized
in interface RuntimeServices
public void setProperty(String key, Object value)
setProperty
in interface RuntimeServices
key
- property keyvalue
- property valuepublic void setProperties(String fileName)
public void setProperties(Properties props)
public void setConfiguration(ExtProperties 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)
init
in interface RuntimeServices
p
- Velocity properties for initializationpublic void init(String configurationFile)
init
in interface RuntimeServices
configurationFile
- public void addDirective(Directive directive)
directive
- public Directive getDirective(String name)
getDirective
in interface RuntimeServices
name
- name of the directiveDirective
for that namepublic void removeDirective(String name)
name
- name of the directive.public void loadDirective(String directiveClass)
directiveClass
- classname of directive to loadpublic Parser createNewParser()
createNewParser
in interface RuntimeServices
public SimpleNode parse(Reader reader, Template template) throws ParseException
parse
in interface RuntimeServices
reader
- Reader retrieved by a resource loadertemplate
- template being parsedParseException
- When the template could not be parsed.public boolean evaluate(Context context, Writer out, String logTag, String instring)
evaluate
in interface RuntimeServices
context
- 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, Writer writer, String logTag, Reader reader)
evaluate
in interface RuntimeServices
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 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, Writer writer, 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(String vmName, String logTag, String[] params, Context context, Writer writer)
invokeVelocimacro
in interface RuntimeServices
vmName
- 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(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 UTF-8.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.public Template getTemplate(String name, String encoding) throws ResourceNotFoundException, ParseErrorException
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.public ContentResource getContent(String name) throws ResourceNotFoundException, ParseErrorException
getContent
in interface RuntimeServices
name
- 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(String name, String encoding) throws ResourceNotFoundException, ParseErrorException
getContent
in interface RuntimeServices
name
- 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 String getLoaderNameForResource(String resourceName)
getLoaderNameForResource
in interface RuntimeServices
resourceName
- Name of template or content resourcepublic org.slf4j.Logger getLog()
getLog
in interface RuntimeServices
public org.slf4j.Logger getLog(String childNamespace)
getLog
in interface RuntimeServices
childNamespace
- 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, Template renderingTemplate, Template template)
getVelocimacro
in interface RuntimeServices
vmName
- Name of velocimacro requestedrenderingTemplate
- 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.template
- Template which acts as the host for the macropublic boolean addVelocimacro(String name, Node macro, List<Macro.MacroArg> macroArgs, Template definingTemplate)
addVelocimacro
in interface RuntimeServices
name
- Name of velocimacromacro
- root AST node of the parsed macromacroArgs
- Array of macro arguments, containing the
#macro() arguments and default values. the 0th is the name.definingTemplate
- Template containing the source of the macropublic boolean isVelocimacro(String vmName, Template template)
isVelocimacro
in interface RuntimeServices
vmName
- Name of the Velocimacro.template
- Template on which to look for the Macro.public String getString(String key)
getString
in interface RuntimeServices
key
- property keypublic int getInt(String key)
getInt
in interface RuntimeServices
key
- Property keypublic int getInt(String key, int defaultValue)
getInt
in interface RuntimeServices
key
- property keydefaultValue
- The default value.public boolean getBoolean(String key, boolean def)
getBoolean
in interface RuntimeServices
key
- property keydef
- The default value if property not found.public ExtProperties getConfiguration()
getConfiguration
in interface RuntimeServices
public EventCartridge getApplicationEventCartridge()
getApplicationEventCartridge
in interface RuntimeServices
public Object getApplicationAttribute(Object key)
getApplicationAttribute
in interface RuntimeServices
key
- public Object setApplicationAttribute(Object key, Object o)
setApplicationAttribute
in interface RuntimeServices
key
- o
- The new application attribute.public Uberspect getUberspect()
getUberspect
in interface RuntimeServices
public boolean useStringInterning()
useStringInterning
in interface RuntimeServices
public RuntimeConstants.SpaceGobbling getSpaceGobbling()
getSpaceGobbling
in interface RuntimeServices
Copyright © 2000–2017 The Apache Software Foundation. All rights reserved.