org.apache.struts2.sitemesh

## Class FreemarkerDecoratorServlet

- java.lang.Object
- - javax.servlet.GenericServlet
  - - javax.servlet.http.HttpServlet
    - - freemarker.ext.servlet.FreemarkerServlet
      - - org.apache.struts2.sitemesh.FreemarkerDecoratorServlet

- All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

      public class FreemarkerDecoratorServlet
      extends freemarker.ext.servlet.FreemarkerServlet

  This is a SiteMesh FreeMarker view servlet.

  It overrides the SiteMesh servlet to rely on the Freemarker Manager in Struts instead of creating it's own manager

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected freemarker.template.Configuration` | `config`
    `protected boolean` | `debug`
    `protected FreemarkerManager` | `freemarkerManager`
    `protected boolean` | `nocache`
    `static long` | `serialVersionUID`
    `protected String` | `templatePath`

    - ### Fields inherited from class freemarker.ext.servlet.FreemarkerServlet

      `INIT_PARAM_BUFFER_SIZE, INIT_PARAM_CLASSPATH_TLDS, INIT_PARAM_CONTENT_TYPE, INIT_PARAM_EXCEPTION_ON_MISSING_TEMPLATE, INIT_PARAM_META_INF_TLD_LOCATIONS, INIT_PARAM_NO_CACHE, INIT_PARAM_OVERRIDE_RESPONSE_CONTENT_TYPE, INIT_PARAM_OVERRIDE_RESPONSE_LOCALE, INIT_PARAM_RESPONSE_CHARACTER_ENCODING, INIT_PARAM_TEMPLATE_PATH, INIT_PARAM_VALUE_ALWAYS, INIT_PARAM_VALUE_DO_NOT_SET, INIT_PARAM_VALUE_FORCE_PREFIX, INIT_PARAM_VALUE_FROM_TEMPLATE, INIT_PARAM_VALUE_LEGACY, INIT_PARAM_VALUE_NEVER, INIT_PARAM_VALUE_WHEN_TEMPLATE_HAS_MIME_TYPE, KEY_APPLICATION, KEY_APPLICATION_PRIVATE, KEY_INCLUDE, KEY_JSP_TAGLIBS, KEY_REQUEST, KEY_REQUEST_PARAMETERS, KEY_REQUEST_PRIVATE, KEY_SESSION, META_INF_TLD_LOCATION_CLASSPATH, META_INF_TLD_LOCATION_CLEAR, META_INF_TLD_LOCATION_WEB_INF_PER_LIB_JARS, SYSTEM_PROPERTY_CLASSPATH_TLDS, SYSTEM_PROPERTY_META_INF_TLD_SOURCES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FreemarkerDecoratorServlet()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected freemarker.template.Configuration` | `createConfiguration()` Create the instance of the freemarker Configuration object.
    `protected Locale` | `deduceLocale(String templatePath, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Returns the locale used for the `Configuration.getTemplate(String, Locale)` call.
    `void` | `doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `void` | `doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `void` | `init()`
    `protected boolean` | `preTemplateProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, freemarker.template.Template template, freemarker.template.TemplateModel templateModel)` Called before the execution is passed to template.process().

    - ### Methods inherited from class freemarker.ext.servlet.FreemarkerServlet

      `createDefaultClassPathTlds, createDefaultMetaInfTldSources, createDefaultObjectWrapper, createModel, createObjectWrapper, createRequestParametersHashModel, createTaglibFactory, createTemplateLoader, getConfiguration, getDefaultOverrideResponseContentType, getObjectWrapper, getTemplatePath, initializeServletContext, initializeSession, postTemplateProcess, preprocessRequest, processEnvironment, requestUrlToTemplatePath, setConfigurationDefaults`

    - ### Methods inherited from class javax.servlet.http.HttpServlet

      `doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service`

    - ### Methods inherited from class javax.servlet.GenericServlet

      `destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          public static final long serialVersionUID

      See Also:
        Constant Field Values

    - #### freemarkerManager

          protected FreemarkerManager freemarkerManager

    - #### templatePath

          protected String templatePath

    - #### nocache

          protected boolean nocache

    - #### debug

          protected boolean debug

    - #### config

          protected freemarker.template.Configuration config

  - ### Constructor Detail

    - #### FreemarkerDecoratorServlet

          public FreemarkerDecoratorServlet()

  - ### Method Detail

    - #### init

          public void init()
                    throws javax.servlet.ServletException

      Overrides:
        `init` in class `freemarker.ext.servlet.FreemarkerServlet`
      Throws:
        `javax.servlet.ServletException`

    - #### doGet

          public void doGet(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws javax.servlet.ServletException,
                            IOException

      Overrides:
        `doGet` in class `freemarker.ext.servlet.FreemarkerServlet`
      Throws:
        `javax.servlet.ServletException`
        `IOException`

    - #### doPost

          public void doPost(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException

      Overrides:
        `doPost` in class `freemarker.ext.servlet.FreemarkerServlet`
      Throws:
        `javax.servlet.ServletException`
        `IOException`

    - #### deduceLocale

          protected Locale deduceLocale(String templatePath,
                                        javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)

      Returns the locale used for the `Configuration.getTemplate(String, Locale)` call. The base implementation simply returns the locale setting of the configuration. Override this method to provide different behaviour, i.e. to use the locale indicated in the request.
      Overrides:
        `deduceLocale` in class `freemarker.ext.servlet.FreemarkerServlet`

    - #### createConfiguration

          protected freemarker.template.Configuration createConfiguration()

      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
      Overrides:
        `createConfiguration` in class `freemarker.ext.servlet.FreemarkerServlet`

    - #### preTemplateProcess

          protected boolean preTemplateProcess(javax.servlet.http.HttpServletRequest request,
                                               javax.servlet.http.HttpServletResponse response,
                                               freemarker.template.Template template,
                                               freemarker.template.TemplateModel templateModel)
                                        throws javax.servlet.ServletException,
                                               IOException

      Called before the execution is passed to template.process(). This is a generic hook you might use in subclasses to perform a specific action before the template is processed. By default does nothing. A typical action to perform here is to inject application-specific objects into the model root

      Example: Expose the Serlvet context path as "baseDir" for all templates:

              ((SimpleHash) data).put("baseDir", request.getContextPath() + "/");
              return true;

      Overrides:
        `preTemplateProcess` in class `freemarker.ext.servlet.FreemarkerServlet`
      Parameters:
        `request` - the actual HTTP request
        `response` - the actual HTTP response
        `template` - the template that will get executed
      Returns:
        true to process the template, false to suppress template processing.
      Throws:
        `javax.servlet.ServletException`
        `IOException`
      See Also:
        `FreemarkerServlet.preTemplateProcess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, freemarker.template.Template, freemarker.template.TemplateModel)`

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.