Class FreemarkerManager

java.lang.Object
org.apache.struts2.views.freemarker.FreemarkerManager

public class FreemarkerManager extends Object

Static Configuration Manager for the FreemarkerResult's configuration

Possible extension points are:

  • createConfiguration method
  • loadSettings method
  • createTemplateLoader method
  • populateContext method

createConfiguration method
Create a freemarker Configuration.

loadSettings method
Load freemarker settings, default to freemarker.properties (if found in classpath)

createTemplateLoader method
create a freemarker TemplateLoader that loads freemarker template in the following order:

  1. path defined in ServletContext init parameter named 'templatePath' or 'TemplatePath' (must be an absolute path)
  2. webapp classpath
  3. struts's static folder (under [STRUT2_SOURCE]/org/apache/struts2/static/

populateContext method
populate the created model.

  • Field Details

  • Constructor Details

    • FreemarkerManager

      public FreemarkerManager()
  • Method Details

    • setEncoding

      public void setEncoding(String encoding)
    • setWrapperAltMap

      public void setWrapperAltMap(String val)
    • setCacheBeanWrapper

      public void setCacheBeanWrapper(String val)
    • setMruMaxStrongSize

      public void setMruMaxStrongSize(String size)
    • setTemplateUpdateDelay

      public void setTemplateUpdateDelay(String delay)
    • setContainer

      public void setContainer(Container container)
    • setFileManagerFactory

      public void setFileManagerFactory(FileManagerFactory fileManagerFactory)
    • setThemeTemplateLoader

      public void setThemeTemplateLoader(FreemarkerThemeTemplateLoader themeTemplateLoader)
    • getNoCharsetInContentType

      public boolean getNoCharsetInContentType()
    • getTemplatePath

      public String getTemplatePath()
    • getNocache

      public boolean getNocache()
    • getDebug

      public boolean getDebug()
    • getConfig

      public freemarker.template.Configuration getConfig()
    • getWrapper

      public freemarker.template.ObjectWrapper getWrapper()
    • getContentType

      public String getContentType()
    • getConfiguration

      public freemarker.template.Configuration getConfiguration(jakarta.servlet.ServletContext servletContext)
    • init

      public void init(jakarta.servlet.ServletContext servletContext) throws freemarker.template.TemplateException
      Throws:
      freemarker.template.TemplateException
    • configureTemplateLoader

      protected void configureTemplateLoader(freemarker.cache.TemplateLoader templateLoader)
      Sets the Freemarker Configuration's template loader with the FreemarkerThemeTemplateLoader at the top.
      Parameters:
      templateLoader - the template loader
      See Also:
    • createConfiguration

      protected freemarker.template.Configuration createConfiguration(jakarta.servlet.ServletContext servletContext) throws freemarker.template.TemplateException
      Create the instance of the freemarker Configuration object.

      this implementation

      • obtains the default configuration from Configuration.getDefaultConfiguration()
      • sets up template loading from a ClassTemplateLoader and a WebappTemplateLoader
      • sets up the object wrapper to be the BeansWrapper
      • loads settings from the classpath file /freemarker.properties
      Parameters:
      servletContext - the servlet context
      Returns:
      a instance of the freemarker configuration object
      Throws:
      freemarker.template.TemplateException - in case of errors during creating the configuration
    • getFreemarkerVersion

      protected freemarker.template.Version getFreemarkerVersion(jakarta.servlet.ServletContext servletContext)
    • buildScopesHashModel

      protected ScopesHashModel buildScopesHashModel(jakarta.servlet.ServletContext servletContext, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, freemarker.template.ObjectWrapper wrapper, ValueStack stack)
    • createObjectWrapper

      protected freemarker.template.ObjectWrapper createObjectWrapper(jakarta.servlet.ServletContext servletContext)
    • createTemplateLoader

      protected freemarker.cache.TemplateLoader createTemplateLoader(jakarta.servlet.ServletContext servletContext, String templatePath)
      Create the template loader. The default implementation will create a ClassTemplateLoader if the template path starts with "class://", a FileTemplateLoader if the template path starts with "file://", and a WebappTemplateLoader otherwise.
      Parameters:
      servletContext - the servlet path
      templatePath - the template path to create a loader for
      Returns:
      a newly created template loader
    • loadSettings

      protected void loadSettings(jakarta.servlet.ServletContext servletContext)
      Load the settings from the /freemarker.properties file on the classpath
      Parameters:
      servletContext - the servlet context
      See Also:
      • for the definition of valid settings
    • addSetting

      public void addSetting(String name, String value) throws freemarker.template.TemplateException
      Throws:
      freemarker.template.TemplateException
    • buildTemplateModel

      public ScopesHashModel buildTemplateModel(ValueStack stack, Object action, jakarta.servlet.ServletContext servletContext, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, freemarker.template.ObjectWrapper wrapper)
    • populateContext

      protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)