Class FreeMarkerConfigurationFactory

java.lang.Object
com.aspectran.freemarker.FreeMarkerConfigurationFactory
All Implemented Interfaces:
ActivityContextAware, Aware
Direct Known Subclasses:
FreeMarkerConfigurationFactoryBean

public class FreeMarkerConfigurationFactory extends Object implements ActivityContextAware
Factory that configures a FreeMarker Configuration.

Created: 2016. 1. 9.

  • Constructor Details

    • FreeMarkerConfigurationFactory

      public FreeMarkerConfigurationFactory()
  • Method Details

    • setActivityContext

      @AvoidAdvice public void setActivityContext(@NonNull ActivityContext context)
      Specified by:
      setActivityContext in interface ActivityContextAware
    • setConfigLocation

      public void setConfigLocation(String configLocation)
      Set the location of the Freemarker settings file. Alternatively, you can specify all properties locally.
    • setFreemarkerSettings

      public void setFreemarkerSettings(Properties settings)
      Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method.
      Parameters:
      settings - the settings
      See Also:
      • freemarker.template.Configuration#setSettings
    • 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.
      Parameters:
      variables - the variables
      See Also:
      • freemarker.template.Configuration#setAllSharedVariables
    • 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).

      Parameters:
      defaultEncoding - the default encoding
      See Also:
      • freemarker.template.Configuration#setDefaultEncoding
    • setTemplateLoaderPath

      public void setTemplateLoaderPath(String templateLoaderPath)
      Set the Freemarker template loader path.
      Parameters:
      templateLoaderPath - the Freemarker template loader path
    • setTemplateLoaderPath

      public void setTemplateLoaderPath(String... templateLoaderPaths)
      Set multiple Freemarker template loader paths.
      Parameters:
      templateLoaderPaths - the multiple Freemarker template loader paths
    • setTemplateLoaderPath

      public void setTemplateLoaderPath(@NonNull List<String> templateLoaderPathList)
      Set a List of Freemarker template loader paths.
      Parameters:
      templateLoaderPathList - a List of Freemarker template loader paths
    • setTemplateLoader

      public void setTemplateLoader(freemarker.cache.TemplateLoader templateLoader)
      Set a TemplateLoader that will be used to search for templates.
      Parameters:
      templateLoader - the template loader
    • setTemplateLoader

      public void setTemplateLoader(freemarker.cache.TemplateLoader... templateLoaders)
      Set multiple TemplateLoaders that will be used to search for templates.
      Parameters:
      templateLoaders - the multiple TemplateLoaders
    • setTemplateLoader

      public void setTemplateLoader(@NonNull List<freemarker.cache.TemplateLoader> templateLoaderList)
      Set a List of TemplateLoaders that will be used to search for templates.
      Parameters:
      templateLoaderList - a List of TemplateLoaders
    • setTrimDirectives

      public void setTrimDirectives(TrimDirective... trimDirectives)
    • setTrimDirectives

      public void setTrimDirectives(@NonNull Parameters parameters)
    • createConfiguration

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

      protected freemarker.template.Configuration newConfiguration()
      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().

      Returns:
      the Configuration object
    • getAggregateTemplateLoader

      protected freemarker.cache.TemplateLoader getAggregateTemplateLoader(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.
      Parameters:
      templateLoaders - the final List of TemplateLoader instances
      Returns:
      the aggregate TemplateLoader
    • getTemplateLoaderForPath

      protected freemarker.cache.TemplateLoader getTemplateLoaderForPath(@NonNull String templateLoaderPath) throws IOException
      Determine a FreeMarker TemplateLoader for the given path.
      Parameters:
      templateLoaderPath - the path to load templates from
      Returns:
      an appropriate TemplateLoader
      Throws:
      IOException - if an I/O error has occurred
      See Also:
      • FileTemplateLoader