org.apache.struts2.views.freemarker

## Class PortletFreemarkerResult

- java.lang.Object
- - org.apache.struts2.result.StrutsResultSupport
  - - org.apache.struts2.views.freemarker.PortletFreemarkerResult

- All Implemented Interfaces:
    Result, Serializable, StrutsStatics

      public class PortletFreemarkerResult
      extends StrutsResultSupport

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected freemarker.template.Configuration` | `configuration`
    `protected FreemarkerManager` | `freemarkerManager`
    `protected ActionInvocation` | `invocation`
    `protected String` | `location`
    `protected freemarker.template.ObjectWrapper` | `wrapper`

    - ### Fields inherited from class org.apache.struts2.result.StrutsResultSupport

      `DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation`

    - ### Fields inherited from interface org.apache.struts2.StrutsStatics

      `HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PortletFreemarkerResult()`
    `PortletFreemarkerResult(String location)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected freemarker.template.TemplateModel` | `createModel()` Build the instance of the ScopesHashModel, including JspTagLib support
    `protected Locale` | `deduceLocale()`
    `void` | `doExecute(String location, ActionInvocation invocation)` Execute this result, using the specified template location.
    `protected freemarker.template.Configuration` | `getConfiguration()` This method is called from `doExecute(String, ActionInvocation)` to obtain the FreeMarker configuration object that this result will use for template loading.
    `String` | `getContentType()` allow parameterization of the contentType the default being text/html
    `protected freemarker.template.ObjectWrapper` | `getObjectWrapper()` This method is called from `doExecute(String, ActionInvocation)` to obtain the FreeMarker object wrapper object that this result will use for adapting objects into template models.
    `protected Writer` | `getWriter()` The default writer writes directly to the response writer.
    `protected void` | `postTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel data)` the default implementation of postTemplateProcess applies the contentType parameter
    `protected boolean` | `preTemplateProcess(freemarker.template.Template template, freemarker.template.TemplateModel model)` Called before the execution is passed to template.process().
    `void` | `setContentType(String aContentType)`
    `void` | `setFreemarkerManager(FreemarkerManager mgr)`

    - ### Methods inherited from class org.apache.struts2.result.StrutsResultSupport

      `conditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse`

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

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

- - ### Field Detail

    - #### invocation

          protected ActionInvocation invocation

    - #### configuration

          protected freemarker.template.Configuration configuration

    - #### wrapper

          protected freemarker.template.ObjectWrapper wrapper

    - #### freemarkerManager

          protected FreemarkerManager freemarkerManager

    - #### location

          protected String location

  - ### Constructor Detail

    - #### PortletFreemarkerResult

          public PortletFreemarkerResult()

    - #### PortletFreemarkerResult

          public PortletFreemarkerResult(String location)

  - ### Method Detail

    - #### setFreemarkerManager

          public void setFreemarkerManager(FreemarkerManager mgr)

    - #### setContentType

          public void setContentType(String aContentType)

    - #### getContentType

          public String getContentType()

      allow parameterization of the contentType the default being text/html
      Returns:
        content type

    - #### doExecute

          public void doExecute(String location,
                       ActionInvocation invocation)
                         throws IOException,
                                freemarker.template.TemplateException,
                                javax.portlet.PortletException

      Execute this result, using the specified template location.
      The template location has already been interpolated for any variable substitutions
      this method obtains the freemarker configuration and the object wrapper from the provided hooks. It them implements the template processing workflow by calling the hooks for preTemplateProcess and postTemplateProcess

      Specified by:
        `doExecute` in class `StrutsResultSupport`
      Parameters:
        `location` - template location
        `invocation` - the action invocation
      Throws:
        `IOException` - in case of I/O related errors
        `freemarker.template.TemplateException` - in case of freemarker templates related errors
        `javax.portlet.PortletException` - in case of portlet related errors

    - #### getConfiguration

          protected freemarker.template.Configuration getConfiguration()
                                                                throws freemarker.template.TemplateException

      This method is called from `doExecute(String, ActionInvocation)` to obtain the FreeMarker configuration object that this result will use for template loading. This is a hook that allows you to custom-configure the configuration object in a subclass, or to fetch it from an IoC container.
      The default implementation obtains the configuration from the ConfigurationManager instance.
      Returns:
        configuration
      Throws:
        `freemarker.template.TemplateException` - in case of freemarker templates related errors

    - #### getObjectWrapper

          protected freemarker.template.ObjectWrapper getObjectWrapper()

      This method is called from `doExecute(String, ActionInvocation)` to obtain the FreeMarker object wrapper object that this result will use for adapting objects into template models. This is a hook that allows you to custom-configure the wrapper object in a subclass.
      The default implementation returns `Configurable.getObjectWrapper()`
      Returns:
        object wrapper

    - #### getWriter

          protected Writer getWriter()
                              throws IOException

      The default writer writes directly to the response writer.
      Returns:
        response writer
      Throws:
        `IOException` - in case of I/O related errors

    - #### createModel

          protected freemarker.template.TemplateModel createModel()
                                                           throws freemarker.template.TemplateModelException

      Build the instance of the ScopesHashModel, including JspTagLib support

      Objects added to the model are:

      - Application - servlet context attributes hash model
      - JspTaglibs - jsp tag lib factory model
      - Request - request attributes hash model
      - Session - session attributes hash model
      - request - the HttpServletRequst object for direct access
      - response - the HttpServletResponse object for direct access
      - stack - the OgnLValueStack instance for direct access
      - ognl - the instance of the OgnlTool
      - action - the action itself
      - exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)
      - struts - instance of the StrutsUtil class
      Returns:
        freemarker template model
      Throws:
        `freemarker.template.TemplateModelException` - in case of template model errors

    - #### deduceLocale

          protected Locale deduceLocale()

      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,

    - #### postTemplateProcess

          protected void postTemplateProcess(freemarker.template.Template template,
                                 freemarker.template.TemplateModel data)
                                      throws IOException

      the default implementation of postTemplateProcess applies the contentType parameter
      Parameters:
        `template` - freemarker template
        `data` - model data
      Throws:
        `IOException` - in case of I/O related errors

    - #### preTemplateProcess

          protected boolean preTemplateProcess(freemarker.template.Template template,
                                   freemarker.template.TemplateModel model)
                                        throws 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
      Parameters:
        `template` - freemarker template
        `model` - model data
      Returns:
        true to process the template, false to suppress template processing.
      Throws:
        `IOException` - in case of I/O related errors

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