@Deprecated
public class VelocityEngineFactory
extends java.lang.Object
VelocityEngineFactoryBean
for preparing a VelocityEngine as bean reference, or
VelocityConfigurer
for web views.
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 Resource 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
CommonsLogLogChute
as log system.
The simplest way to use this class is to specify a
"resourceLoaderPath"
; the
VelocityEngine typically then does not need any further configuration.
setConfigLocation(org.springframework.core.io.Resource)
,
setVelocityProperties(java.util.Properties)
,
setResourceLoaderPath(java.lang.String)
,
setOverrideLogging(boolean)
,
createVelocityEngine()
,
VelocityEngineFactoryBean
,
VelocityConfigurer
,
VelocityEngine
Constructor and Description |
---|
VelocityEngineFactory()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
org.apache.velocity.app.VelocityEngine |
createVelocityEngine()
Deprecated.
Prepare the VelocityEngine instance and return it.
|
protected ResourceLoader |
getResourceLoader()
Deprecated.
Return the Spring ResourceLoader to use for loading Velocity template files.
|
protected void |
initSpringResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine,
java.lang.String resourceLoaderPath)
Deprecated.
Initialize a SpringResourceLoader for the given VelocityEngine.
|
protected void |
initVelocityResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine,
java.lang.String resourceLoaderPath)
Deprecated.
Initialize a Velocity resource loader for the given VelocityEngine:
either a standard Velocity FileResourceLoader or a SpringResourceLoader.
|
protected boolean |
isPreferFileSystemAccess()
Deprecated.
Return whether to prefer file system access for template loading.
|
protected org.apache.velocity.app.VelocityEngine |
newVelocityEngine()
Deprecated.
Return a new VelocityEngine.
|
protected void |
postProcessVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)
Deprecated.
To be implemented by subclasses that want to perform custom
post-processing of the VelocityEngine after this FactoryBean
performed its default configuration (but before VelocityEngine.init).
|
void |
setConfigLocation(Resource configLocation)
Deprecated.
Set the location of the Velocity config file.
|
void |
setOverrideLogging(boolean overrideLogging)
Deprecated.
Set whether Velocity should log via Commons Logging, i.e.
|
void |
setPreferFileSystemAccess(boolean preferFileSystemAccess)
Deprecated.
Set whether to prefer file system access for template loading.
|
void |
setResourceLoader(ResourceLoader resourceLoader)
Deprecated.
Set the Spring ResourceLoader to use for loading Velocity template files.
|
void |
setResourceLoaderPath(java.lang.String resourceLoaderPath)
Deprecated.
Set the Velocity resource loader path via a Spring resource location.
|
void |
setVelocityProperties(java.util.Properties velocityProperties)
Deprecated.
Set Velocity properties, like "file.resource.loader.path".
|
void |
setVelocityPropertiesMap(java.util.Map<java.lang.String,java.lang.Object> velocityPropertiesMap)
Deprecated.
Set Velocity properties as Map, to allow for non-String values
like "ds.resource.loader.instance".
|
protected final Log logger
public void setConfigLocation(Resource configLocation)
public void setVelocityProperties(java.util.Properties velocityProperties)
Note that the Velocity resource loader path also be set to any Spring resource location via the "resourceLoaderPath" property. Setting it here is just necessary when using a non-file-based resource loader.
public void setVelocityPropertiesMap(java.util.Map<java.lang.String,java.lang.Object> velocityPropertiesMap)
public void setResourceLoaderPath(java.lang.String resourceLoaderPath)
When populated via a String, standard URLs like "file:" and "classpath:" pseudo URLs are supported, as understood by ResourceLoader. 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 java.io.File
,
a generic SpringResourceLoader will be used under the name "spring", without
modification detection.
Note 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 cached forever (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 javadoc for details.
public void setResourceLoader(ResourceLoader resourceLoader)
DefaultResourceLoader
,
ApplicationContext
protected ResourceLoader getResourceLoader()
public void setPreferFileSystemAccess(boolean preferFileSystemAccess)
If this is enabled, VelocityEngineFactory will try to resolve the specified "resourceLoaderPath" as file system resource (which will work for expanded class path resources and ServletContext resources too).
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 an expanded classes directory while others reside in jar files.
setResourceLoaderPath(java.lang.String)
protected boolean isPreferFileSystemAccess()
public void setOverrideLogging(boolean overrideLogging)
CommonsLogLogChute
. Default is "true".public org.apache.velocity.app.VelocityEngine createVelocityEngine() throws java.io.IOException, org.apache.velocity.exception.VelocityException
java.io.IOException
- if the config file wasn't foundorg.apache.velocity.exception.VelocityException
- on Velocity initialization failureprotected org.apache.velocity.app.VelocityEngine newVelocityEngine() throws java.io.IOException, org.apache.velocity.exception.VelocityException
Called by createVelocityEngine()
.
java.io.IOException
- if a config file wasn't foundorg.apache.velocity.exception.VelocityException
- on Velocity initialization failurecreateVelocityEngine()
protected void initVelocityResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, java.lang.String resourceLoaderPath)
Called by createVelocityEngine()
.
velocityEngine
- the VelocityEngine to configureresourceLoaderPath
- the path to load Velocity resources fromFileResourceLoader
,
SpringResourceLoader
,
initSpringResourceLoader(org.apache.velocity.app.VelocityEngine, java.lang.String)
,
createVelocityEngine()
protected void initSpringResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, java.lang.String resourceLoaderPath)
Called by initVelocityResourceLoader
.
velocityEngine
- the VelocityEngine to configureresourceLoaderPath
- the path to load Velocity resources fromSpringResourceLoader
,
initVelocityResourceLoader(org.apache.velocity.app.VelocityEngine, java.lang.String)
protected void postProcessVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine) throws java.io.IOException, org.apache.velocity.exception.VelocityException
Called by createVelocityEngine()
.
velocityEngine
- the current VelocityEnginejava.io.IOException
- if a config file wasn't foundorg.apache.velocity.exception.VelocityException
- on Velocity initialization failurecreateVelocityEngine()
,
VelocityEngine.init()