Class VelocityEngineFactory

    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
    • Constructor Detail

      • VelocityEngineFactory

        public VelocityEngineFactory()
    • Method Detail

      • setVelocityPropertiesMap

        public void setVelocityPropertiesMap​(Map<String,​Object> velocityPropertiesMap)
        Set Velocity properties as Map, to allow for non-String values like "ds.resource.loader.instance".
        Parameters:
        velocityPropertiesMap - engine properties to include
        See Also:
        setVelocityProperties(java.util.Properties)
      • setResourceLoaderPath

        public void setResourceLoaderPath​(String 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 "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.

        Parameters:
        resourceLoaderPath - comma-separated resource paths
        See Also:
        setResourceLoader(org.springframework.core.io.ResourceLoader), setVelocityProperties(java.util.Properties), setPreferFileSystemAccess(boolean), SpringResourceLoader, FileResourceLoader
      • 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.

        Parameters:
        resourceLoader - Spring resource loader to ue
        See Also:
        DefaultResourceLoader, ApplicationContext
      • getResourceLoader

        protected org.springframework.core.io.ResourceLoader getResourceLoader()
        Return the Spring ResourceLoader to use for loading Velocity template files.
        Returns:
        Spring resource loader to use
      • 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 resources, but only when non-classpath resource paths are included.

        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.

        Parameters:
        preferFileSystemAccess - whether to rely on file-based loading when possible
        See Also:
        setResourceLoaderPath(java.lang.String)
      • isPreferFileSystemAccess

        protected boolean isPreferFileSystemAccess()
        Return whether to prefer file system access for template loading.
        Returns:
        whether to prefer file system access for template loading
      • postProcessVelocityEngine

        protected void postProcessVelocityEngine​(VelocityEngine velocityEngine)
                                          throws IOException,
                                                 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().

        Parameters:
        velocityEngine - the current VelocityEngine
        Throws:
        IOException - if a config file wasn't found
        VelocityException - on Velocity initialization failure
        See Also:
        createVelocityEngine(), VelocityEngine.init()