类 VelocityEngineFactory
VelocityEngineFactoryBean
for preparing a VelocityEngine as bean reference, or
link cn.aradin.spring.velocity.view.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.
The simplest way to use this class is to specify a
"resourceLoaderPath"; the
VelocityEngine typically then does not need any further configuration.
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明org.apache.velocity.app.VelocityEnginePrepare the VelocityEngine instance and return it.protected org.springframework.core.io.ResourceLoaderprotected voidinitSpringResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, String resourceLoaderPath) Initialize a SpringResourceLoader for the given VelocityEngine.protected voidinitVelocityResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, String resourceLoaderPath) Initialize a Velocity resource loader for the given VelocityEngine: either a standard Velocity FileResourceLoader or a SpringResourceLoader.protected booleanprotected org.apache.velocity.app.VelocityEngineReturn a new VelocityEngine.protected voidpostProcessVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine) 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).voidsetConfigLocation(org.springframework.core.io.Resource configLocation) Set the location of the Velocity config file.voidsetPreferFileSystemAccess(boolean preferFileSystemAccess) Set whether to prefer file system access for template loading.voidsetResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) Set the Spring ResourceLoader to use for loading Velocity template files.voidsetResourceLoaderPath(String resourceLoaderPath) Set the Velocity resource loader path via a Spring resource location.voidsetVelocityProperties(Properties velocityProperties) Set Velocity properties, like "file.resource.loader.path".voidsetVelocityPropertiesMap(Map<String, Object> velocityPropertiesMap) Set Velocity properties as Map, to allow for non-String values like "ds.resource.loader.instance".
-
字段详细资料
-
logger
protected final org.apache.commons.logging.Log logger
-
-
构造器详细资料
-
VelocityEngineFactory
public VelocityEngineFactory()
-
-
方法详细资料
-
setConfigLocation
public void setConfigLocation(org.springframework.core.io.Resource configLocation) Set the location of the Velocity config file. Alternatively, you can specify all properties locally. -
setVelocityProperties
Set Velocity properties, like "file.resource.loader.path". Can be used to override values in a Velocity config file, or to specify all necessary properties locally.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.
- 参数:
velocityProperties- velocityProperties- 另请参阅:
-
setVelocityPropertiesMap
Set Velocity properties as Map, to allow for non-String values like "ds.resource.loader.instance".- 参数:
velocityPropertiesMap- velocityPropertiesMap- 另请参阅:
-
setResourceLoaderPath
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 "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.
- 参数:
resourceLoaderPath- resourceLoaderPath- 另请参阅:
-
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) 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.- 参数:
resourceLoader- resourceLoader- 另请参阅:
-
DefaultResourceLoaderApplicationContext
-
getResourceLoader
protected org.springframework.core.io.ResourceLoader getResourceLoader()- 返回:
- Return the Spring ResourceLoader to use for loading Velocity template files.
-
setPreferFileSystemAccess
public void setPreferFileSystemAccess(boolean preferFileSystemAccess) 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 (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.
- 参数:
preferFileSystemAccess- preferFileSystemAccess- 另请参阅:
-
isPreferFileSystemAccess
protected boolean isPreferFileSystemAccess()- 返回:
- Return whether to prefer file system access for template loading.
-
createVelocityEngine
public org.apache.velocity.app.VelocityEngine createVelocityEngine() throws IOException, org.apache.velocity.exception.VelocityExceptionPrepare the VelocityEngine instance and return it.- 返回:
- the VelocityEngine instance
- 抛出:
IOException- if the config file wasn't foundorg.apache.velocity.exception.VelocityException- on Velocity initialization failure
-
newVelocityEngine
protected org.apache.velocity.app.VelocityEngine newVelocityEngine() throws IOException, org.apache.velocity.exception.VelocityExceptionReturn a new VelocityEngine. Subclasses can override this for custom initialization, or for using a mock object for testing.Called by
createVelocityEngine().- 返回:
- the VelocityEngine instance
- 抛出:
IOException- if a config file wasn't foundorg.apache.velocity.exception.VelocityException- on Velocity initialization failure- 另请参阅:
-
initVelocityResourceLoader
protected void initVelocityResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, String resourceLoaderPath) Initialize a Velocity resource loader for the given VelocityEngine: either a standard Velocity FileResourceLoader or a SpringResourceLoader.Called by
createVelocityEngine().- 参数:
velocityEngine- the VelocityEngine to configureresourceLoaderPath- the path to load Velocity resources from- 另请参阅:
-
initSpringResourceLoader
protected void initSpringResourceLoader(org.apache.velocity.app.VelocityEngine velocityEngine, String resourceLoaderPath) Initialize a SpringResourceLoader for the given VelocityEngine.Called by
initVelocityResourceLoader.- 参数:
velocityEngine- the VelocityEngine to configureresourceLoaderPath- the path to load Velocity resources from- 另请参阅:
-
postProcessVelocityEngine
protected void postProcessVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine) throws IOException, org.apache.velocity.exception.VelocityException 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).Called by
createVelocityEngine().- 参数:
velocityEngine- the current VelocityEngine- 抛出:
IOException- if a config file wasn't foundorg.apache.velocity.exception.VelocityException- on Velocity initialization failure- 另请参阅:
-
createVelocityEngine()VelocityEngine.init()
-