Spring.Template.Velocity
Implementation of the custom configuration parser for template configurations
based on
Erez Mazor
Initializes a new instance of the class.
Parse a template definition from the templating namespace
the root element defining the templating object
the parser context
Parses the object definition for the engine object, configures a single NVelocity template engine based
on the element definitions.
the root element defining the velocity engine
the parser context
Parses child element definitions for the NVelocity engine. Typically resource loaders and locally defined properties are parsed here
the XmlNodeList representing the child configuration of the root NVelocity engine element
the parser context
the MutablePropertyValues used to configure this object
Configures the NVelocity resource loader definitions from the xml definition
the root resource loader element
the MutablePropertyValues used to configure this object
the properties used to initialize the velocity engine
Set the caching and modification interval checking properties of a resource loader of a given type
the properties used to initialize the velocity engine
type of the resource loader
caching flag
modification interval value
Set global velocity resource loader properties (caching, modification interval etc.)
the properties used to initialize the velocity engine
the type of resource loader
the suffix property
the value of the property
Creates a nvelocity file based resource loader by setting the required properties
a list of nv:file elements defining the paths to template files
the properties used to initialize the velocity engine
Creates a nvelocity assembly based resource loader by setting the required properties
a list of nv:assembly elements defining the assemblies
the properties used to initialize the velocity engine
Creates a spring resource loader by setting the ResourceLoaderPaths of the
engine factory (the resource loader itself will be created internally either as
spring or as file resource loader based on the value of prefer-file-system-access
attribute).
list of resource loader path elements
the MutablePropertyValues to set the property for the engine factory
Create a custom resource loader from an nv:custom element
generates the 4 required nvelocity props for a resource loader (name, description, class and path).
the nv:custom xml definition element
the properties used to initialize the velocity engine
Parses the nvelocity properties map using ObjectNamespaceParserHelper
and appends it to the properties dictionary
root element of the map element
the parser context
the properties used to initialize the velocity engine
Gets the name of the object type for the specified element.
The element.
The name of the object type.
constructs an nvelocity style resource loader property in the format:
prefix.resource.loader.suffix
the prefix
the suffix
a concatenated string like: prefix.resource.loader.suffix
This method is overriden from ObjectsNamespaceParser since when invoked on
sub-elements from the objets namespace (e.g., objects:objectMap for nvelocity
property map) the element.SelectNodes fails because it is in
the nvelocity custom namespace and not the object's namespace (http://www.springframwork.net)
to amend this the object's namespace is added to the provided XmlNamespaceManager
The element to be searched in.
The name of the child nodes to look for.
The child s of the supplied
with the supplied .
Template definition constants
Engine element definition
Spring resource loader element definition
Custom resource loader element definition
uri attribute of the spring element
prefer-file-system-access attribute of the engine factory
config-file attribute of the engine factory
override-logging attribute of the engine factory
template-caching attribute of the nvelocity engine
default-cache-size attribute of the nvelocity engine resource manager
modification-check-interval attribute of the nvelocity engine resource loader
resource loader element
nvelocity propeties element (map)
PreferFileSystemAccess property of the engine factory
OverrideLogging property of the engine factory
ConfigLocation property of the engine factory
ResourceLoaderPaths property of the engine factory
VelocityProperties property of the engine factory
resource.loader.cache property of the resource loader configuration
resource.loader.modificationCheckInterval property of the resource loader configuration
the type used for file resource loader
the type used for assembly resource loader
the type used for spring resource loader
NVelocity LogSystem implementation for Commons Logging.
Erez Mazor
Shared logger instance.
Initializes the specified runtime services. No-op in current implementatin
the runtime services.
Log a NVelocity message using the commons logging system
LogLevel to match
message to log
NVelocity's abstract ResourceLoader extension which serves
as an adapter that loads templates via a Spring IResourceLoader.
Used by VelocityEngineFactory for any resource loader path that
cannot be resolved to a File or an Assembly or for
implementations which rely on spring's IResourceLoader
mechanism.
Important: this loader does not allow for modification detection.
Expects "spring.resource.loader" (IResourceLoader implementations)
and "spring.resource.loader.path" application attributes in the
NVelocity runtime.
Erez Mazor (.NET)
Prefix used for the NVelocity Configuration
The IResourceLoader implementation type
A flag indicating weather a template cache is used
Fully qualified name of the IResourceLoader implementation class
A comma delimited list of paths used by the spring IResourceLoader implementation
Shared logger instance.
Initialize the template loader with a resources class.
The ExtendedProperties representing the Velocity configuration.
Get the System.IO.Stream that the Runtime will parse to create a template.
the source template name
a System.IO.Stream representation of the resource
Given a template, check to see if the source of InputStream has been modified.
The resource.
true if the source of the InputStream has been modified; otherwise, false.
Get the last modified time of the InputStream source
that was used to create the template. We need the template
here because we have to extract the name of the template
in order to locate the InputStream source.
The resource.
Common Velocity constants.
File.
Type.
Assembly.
Class.
Name.
Description.
Path.
Separator.
Factory that configures a VelocityEngine. Can be used standalone,
but typically you will use VelocityEngineFactoryObject
for preparing a VelocityEngine as bean reference.
The optional "ConfigLocation" property sets the location of the Velocity
properties file, within the current application. Velocity properties can be
overridden via "VelocityProperties", or even completely specified locally,
avoiding the need for an external properties file.
The "ResourceLoaderPath" property can be used to specify the Velocity
resource loader path via Spring's IResource abstraction, possibly relative
to the Spring application context.
If "OverrideLogging" is true (the default), the VelocityEngine will be
configured to log via Commons Logging, that is, using the Spring-provided
CommonsLoggingLogSystem as log system.
The simplest way to use this class is to specify a ResourceLoaderPath
property. the VelocityEngine typically then does not need any further
configuration.
Erez Mazor
Shared logger instance.
Create and initialize the VelocityEngine instance and return it
VelocityEngine
This is to overcome an issue with the current NVelocity library, it seems the
default runetime properties/directives (nvelocity.properties and directive.properties
files) are not being properly located in the library at load time. A jira should
be filed but for now we attempt to do this on our own. Particularly our
concern here is with several required properties which I don't want
to require users to re-defined. e.g.,:
Pre-requisites:
resource.manager.class=NVelocity.Runtime.Resource.ResourceManagerImpl
directive.manager=NVelocity.Runtime.Directive.DirectiveManager
runtime.introspector.uberspect=NVelocity.Util.Introspection.UberspectImpl
Return a new VelocityEngine. Subclasses can override this for
custom initialization, or for using a mock object for testing.
Called by CreateVelocityEngine()
VelocityEngine instance (non-configured)
Initialize a Velocity resource loader for the given VelocityEngine:
either a standard Velocity FileResourceLoader or a SpringResourceLoader.
Called by CreateVelocityEngine().
velocityEngine the VelocityEngine to configure
paths the path list to load Velocity resources from
Initialize a SpringResourceLoader for the given VelocityEngine.
Called by InitVelocityResourceLoader.
Important: the NVeloctity ResourceLoaderFactory.getLoader
method replaces ';' with ',' when attempting to construct our resource
loader. The name on the SPRING_RESOURCE_LOADER_CLASS property
has to be in the form of "ClassFullName; AssemblyName" in replacement
of the tranditional "ClassFullName, AssemblyName" to work.
velocityEngine the VelocityEngine to configure
resourceLoaderPath the path to load Velocity resources from
To be implemented by subclasses that want to to perform custom
post-processing of the VelocityEngine after this FactoryObject
performed its default configuration (but before VelocityEngine.init)
Called by CreateVelocityEngine
velocityEngine the current VelocityEngine
Populates the velocity properties from the given resource
ExtendedProperties instance to populate
The resource from which to load the properties
A flag indicated weather the properties loaded from the resource should be appended or replaced in the extendedProperties
Set the location of the Velocity config file. Alternatively, you can specify all properties locally.
Set local NVelocity properties.
Single ResourceLoaderPath
Set the Velocity resource loader path via a Spring resource location.
Accepts multiple locations in Velocity's comma-separated path style.
When populated via a String, standard URLs like "file:" and "assembly:"
pseudo URLs are supported, as understood by IResourceLoader. Allows for
relative paths when running in an ApplicationContext.
Will define a path for the default Velocity resource loader with the name
"file". If the specified resource cannot be resolved to a File,
a generic SpringResourceLoader will be used under the name "spring", without
modification detection.
Take notice that resource caching will be enabled in any case. With the file
resource loader, the last-modified timestamp will be checked on access to
detect changes. With SpringResourceLoader, the resource will be throughout
the life time of the application context (for example for class path resources).
To specify a modification check interval for files, use Velocity's
standard "file.resource.loader.modificationCheckInterval" property. By default,
the file timestamp is checked on every access (which is surprisingly fast).
Of course, this just applies when loading resources from the file system.
To enforce the use of SpringResourceLoader, i.e. to not resolve a path
as file system resource in any case, turn off the "preferFileSystemAccess"
flag. See the latter's documentation for details.
Set the Spring ResourceLoader to use for loading Velocity template files.
The default is DefaultResourceLoader. Will get overridden by the
ApplicationContext if running in a context.
Set whether to prefer file system access for template loading.
File system access enables hot detection of template changes.
If this is enabled, VelocityEngineFactory will try to resolve the
specified "resourceLoaderPath" as file system resource.
Default is "true". Turn this off to always load via SpringResourceLoader
(i.e. as stream, without hot detection of template changes), which might
be necessary if some of your templates reside in a directory while
others reside in assembly files.
Set whether Velocity should log via Commons Logging, i.e. whether Velocity's
log system should be set to CommonsLoggingLogSystem. Default value is true
FactoryObject implementation that configures a VelocityEngine and provides it
as an object reference. This object is intended for any kind of usage of Velocity in
application code, e.g. for generating email content.
See the base class VelocityEngineFactory for configuration details.
Erez Mazor
Get the velocity engine underlying object
An instance of a configured VelocityEngine
Facilitate the creation of the velocity engine object
Get the type of the velocity engine
Singleton
Generalized Utility class for merging velocity templates into a text writer or return the result as a string
Erez Mazor
Shared logger instance.
Merge the specified Velocity template with the given model and write
the result to the given Writer.
VelocityEngine to work with
the location of template, relative to Velocity's resource loader path
encoding the encoding of the template file
the Hashtable that contains model names as keys and model objects
writer the TextWriter to write the result to
thrown if any exception is thrown by the velocity engine
Merge the specified Velocity template with the given model into a string.
VelocityEngine to work with
the location of template, relative to Velocity's resource loader path
the encoding string to use for the merge
the Hashtable that contains model names as keys and model objects
the result as string
thrown if any exception is thrown by the velocity engine