类 FreeMarkerConfigurationFactory

    • 字段详细资料

    • 方法详细资料

      • setFreemarkerSettings

        public void setFreemarkerSettings​(Properties settings)
        Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method.
        另请参阅:
        Configurable.setSettings(java.util.Properties)
      • setFreemarkerVariables

        public void setFreemarkerVariables​(Map<String,​Object> variables)
        Set a Map that contains well-known FreeMarker objects which will be passed to FreeMarker's Configuration.setAllSharedVariables() method.
        另请参阅:
        Configuration.setAllSharedVariables(freemarker.template.TemplateHashModelEx)
      • setDefaultEncoding

        public void setDefaultEncoding​(String defaultEncoding)
        Set the default encoding for the FreeMarker configuration. If not specified, FreeMarker will use the platform file encoding.

        Used for template rendering unless there is an explicit encoding specified for the rendering process (for example, on Spring's FreeMarkerView).

        另请参阅:
        Configuration.setDefaultEncoding(java.lang.String), FreeMarkerView.setEncoding(java.lang.String)
      • setTemplateLoaderPaths

        public void setTemplateLoaderPaths​(String... templateLoaderPaths)
        Set multiple Freemarker template loader paths via Spring resource locations.

        When populated via a String, standard URLs like "file:" and "classpath:" pseudo URLs are supported, as understood by ResourceEditor. Allows for relative paths when running in an ApplicationContext.

        Will define a path for the default FreeMarker template loader. If a specified resource cannot be resolved to a java.io.File, a generic SpringTemplateLoader will be used, without modification detection.

        To enforce the use of SpringTemplateLoader, 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.

        If you wish to specify your own list of TemplateLoaders, do not set this property and instead use setTemplateLoaders(List templateLoaders)

        另请参阅:
        ResourceEditor, ResourceLoader.getResource(java.lang.String), Configuration.setDirectoryForTemplateLoading(java.io.File), SpringTemplateLoader
      • setResourceLoader

        public void setResourceLoader​(ResourceLoader resourceLoader)
        Set the Spring ResourceLoader to use for loading FreeMarker template files. The default is DefaultResourceLoader. Will get overridden by the ApplicationContext if running in a context.
        另请参阅:
        DefaultResourceLoader
      • 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, FreeMarkerConfigurationFactory will try to resolve the specified "templateLoaderPath" 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 SpringTemplateLoader (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.

        另请参阅:
        setTemplateLoaderPath(java.lang.String)
      • isPreferFileSystemAccess

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

        public freemarker.template.Configuration createConfiguration()
                                                              throws IOException,
                                                                     freemarker.template.TemplateException
        Prepare the FreeMarker Configuration and return it.
        返回:
        the FreeMarker Configuration object
        抛出:
        IOException - if the config file wasn't found
        freemarker.template.TemplateException - on FreeMarker initialization failure
      • newConfiguration

        protected freemarker.template.Configuration newConfiguration()
                                                              throws IOException,
                                                                     freemarker.template.TemplateException
        Return a new Configuration object. Subclasses can override this for custom initialization (e.g. specifying a FreeMarker compatibility level which is a new feature in FreeMarker 2.3.21), or for using a mock object for testing.

        Called by createConfiguration().

        返回:
        the Configuration object
        抛出:
        IOException - if a config file wasn't found
        freemarker.template.TemplateException - on FreeMarker initialization failure
        另请参阅:
        createConfiguration()
      • getTemplateLoaderForPath

        protected freemarker.cache.TemplateLoader getTemplateLoaderForPath​(String templateLoaderPath)
        Determine a FreeMarker TemplateLoader for the given path.

        Default implementation creates either a FileTemplateLoader or a SpringTemplateLoader.

        参数:
        templateLoaderPath - the path to load templates from
        返回:
        an appropriate TemplateLoader
        另请参阅:
        FileTemplateLoader, SpringTemplateLoader
      • postProcessTemplateLoaders

        protected void postProcessTemplateLoaders​(List<freemarker.cache.TemplateLoader> templateLoaders)
        To be overridden by subclasses that want to register custom TemplateLoader instances after this factory created its default template loaders.

        Called by createConfiguration(). Note that specified "postTemplateLoaders" will be registered after any loaders registered by this callback; as a consequence, they are not included in the given List.

        参数:
        templateLoaders - the current List of TemplateLoader instances, to be modified by a subclass
        另请参阅:
        createConfiguration(), setPostTemplateLoaders(freemarker.cache.TemplateLoader...)
      • getAggregateTemplateLoader

        protected freemarker.cache.TemplateLoader getAggregateTemplateLoader​(List<freemarker.cache.TemplateLoader> templateLoaders)
        Return a TemplateLoader based on the given TemplateLoader list. If more than one TemplateLoader has been registered, a FreeMarker MultiTemplateLoader needs to be created.
        参数:
        templateLoaders - the final List of TemplateLoader instances
        返回:
        the aggregate TemplateLoader
      • postProcessConfiguration

        protected void postProcessConfiguration​(freemarker.template.Configuration config)
                                         throws IOException,
                                                freemarker.template.TemplateException
        To be overridden by subclasses that want to perform custom post-processing of the Configuration object after this factory performed its default initialization.

        Called by createConfiguration().

        参数:
        config - the current Configuration object
        抛出:
        IOException - if a config file wasn't found
        freemarker.template.TemplateException - on FreeMarker initialization failure
        另请参阅:
        createConfiguration()