org.apache.struts2.views.freemarker
Class FreemarkerManager

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

public class FreemarkerManager
extends java.lang.Object

Static Configuration Manager for the FreemarkerResult's configuration

Possible extension points are :-

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 Summary
protected  boolean altMapWrapper
           
static java.lang.String ATTR_TEMPLATE_MODEL
           
protected  boolean cacheBeanWrapper
           
protected  freemarker.template.Configuration config
           
static java.lang.String CONFIG_SERVLET_CONTEXT_KEY
           
protected  java.lang.String contentType
           
protected  boolean debug
           
static java.lang.String DEFAULT_CONTENT_TYPE
           
protected  java.lang.String encoding
           
static java.lang.String EXPIRATION_DATE
           
static java.lang.String INITPARAM_CONTENT_TYPE
           
static java.lang.String INITPARAM_DEBUG
           
static java.lang.String INITPARAM_NOCACHE
           
static java.lang.String INITPARAM_TEMPLATE_PATH
           
static java.lang.String KEY_APPLICATION
           
static java.lang.String KEY_APPLICATION_PRIVATE
           
static java.lang.String KEY_EXCEPTION
           
static java.lang.String KEY_HASHMODEL_PRIVATE
           
static java.lang.String KEY_INCLUDE
           
static java.lang.String KEY_JSP_TAGLIBS
           
static java.lang.String KEY_REQUEST
           
static java.lang.String KEY_REQUEST_PARAMETERS
           
static java.lang.String KEY_REQUEST_PARAMETERS_STRUTS
           
static java.lang.String KEY_REQUEST_PRIVATE
           
static java.lang.String KEY_SESSION
           
protected  int mruMaxStrongSize
           
protected  boolean nocache
           
protected  boolean noCharsetInContentType
           
protected  java.util.Map<java.lang.String,TagLibrary> tagLibraries
           
protected  java.lang.String templatePath
           
protected  java.lang.String templateUpdateDelay
           
protected  freemarker.template.ObjectWrapper wrapper
           
 
Constructor Summary
FreemarkerManager()
           
 
Method Summary
 void addSetting(java.lang.String name, java.lang.String value)
           
protected  ScopesHashModel buildScopesHashModel(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, freemarker.template.ObjectWrapper wrapper, ValueStack stack)
           
 ScopesHashModel buildTemplateModel(ValueStack stack, java.lang.Object action, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, freemarker.template.ObjectWrapper wrapper)
           
protected  freemarker.template.Configuration createConfiguration(javax.servlet.ServletContext servletContext)
          Create the instance of the freemarker Configuration object.
protected  freemarker.template.ObjectWrapper createObjectWrapper(javax.servlet.ServletContext servletContext)
           
protected  freemarker.cache.TemplateLoader createTemplateLoader(javax.servlet.ServletContext servletContext, java.lang.String templatePath)
          Create the template loader.
 freemarker.template.Configuration getConfig()
           
 freemarker.template.Configuration getConfiguration(javax.servlet.ServletContext servletContext)
           
 java.lang.String getContentType()
           
 boolean getDebug()
           
 boolean getNocache()
           
 boolean getNoCharsetInContentType()
           
 java.lang.String getTemplatePath()
           
 freemarker.template.ObjectWrapper getWrapper()
           
 void init(javax.servlet.ServletContext servletContext)
           
protected  void loadSettings(javax.servlet.ServletContext servletContext)
          Load the settings from the /freemarker.properties file on the classpath
protected  void populateContext(ScopesHashModel model, ValueStack stack, java.lang.Object action, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void setCacheBeanWrapper(java.lang.String val)
           
 void setContainer(Container container)
           
 void setEncoding(java.lang.String encoding)
           
 void setMruMaxStrongSize(java.lang.String size)
           
 void setTemplateUpdateDelay(java.lang.String delay)
           
 void setWrapperAltMap(java.lang.String val)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITPARAM_TEMPLATE_PATH

public static final java.lang.String INITPARAM_TEMPLATE_PATH
See Also:
Constant Field Values

INITPARAM_NOCACHE

public static final java.lang.String INITPARAM_NOCACHE
See Also:
Constant Field Values

INITPARAM_CONTENT_TYPE

public static final java.lang.String INITPARAM_CONTENT_TYPE
See Also:
Constant Field Values

DEFAULT_CONTENT_TYPE

public static final java.lang.String DEFAULT_CONTENT_TYPE
See Also:
Constant Field Values

INITPARAM_DEBUG

public static final java.lang.String INITPARAM_DEBUG
See Also:
Constant Field Values

KEY_REQUEST

public static final java.lang.String KEY_REQUEST
See Also:
Constant Field Values

KEY_INCLUDE

public static final java.lang.String KEY_INCLUDE
See Also:
Constant Field Values

KEY_REQUEST_PRIVATE

public static final java.lang.String KEY_REQUEST_PRIVATE
See Also:
Constant Field Values

KEY_REQUEST_PARAMETERS

public static final java.lang.String KEY_REQUEST_PARAMETERS
See Also:
Constant Field Values

KEY_SESSION

public static final java.lang.String KEY_SESSION
See Also:
Constant Field Values

KEY_APPLICATION

public static final java.lang.String KEY_APPLICATION
See Also:
Constant Field Values

KEY_APPLICATION_PRIVATE

public static final java.lang.String KEY_APPLICATION_PRIVATE
See Also:
Constant Field Values

KEY_JSP_TAGLIBS

public static final java.lang.String KEY_JSP_TAGLIBS
See Also:
Constant Field Values

ATTR_TEMPLATE_MODEL

public static final java.lang.String ATTR_TEMPLATE_MODEL
See Also:
Constant Field Values

KEY_REQUEST_PARAMETERS_STRUTS

public static final java.lang.String KEY_REQUEST_PARAMETERS_STRUTS
See Also:
Constant Field Values

KEY_HASHMODEL_PRIVATE

public static final java.lang.String KEY_HASHMODEL_PRIVATE
See Also:
Constant Field Values

EXPIRATION_DATE

public static final java.lang.String EXPIRATION_DATE

CONFIG_SERVLET_CONTEXT_KEY

public static final java.lang.String CONFIG_SERVLET_CONTEXT_KEY
See Also:
Constant Field Values

KEY_EXCEPTION

public static final java.lang.String KEY_EXCEPTION
See Also:
Constant Field Values

templatePath

protected java.lang.String templatePath

nocache

protected boolean nocache

debug

protected boolean debug

config

protected freemarker.template.Configuration config

wrapper

protected freemarker.template.ObjectWrapper wrapper

contentType

protected java.lang.String contentType

noCharsetInContentType

protected boolean noCharsetInContentType

encoding

protected java.lang.String encoding

altMapWrapper

protected boolean altMapWrapper

cacheBeanWrapper

protected boolean cacheBeanWrapper

mruMaxStrongSize

protected int mruMaxStrongSize

templateUpdateDelay

protected java.lang.String templateUpdateDelay

tagLibraries

protected java.util.Map<java.lang.String,TagLibrary> tagLibraries
Constructor Detail

FreemarkerManager

public FreemarkerManager()
Method Detail

setEncoding

public void setEncoding(java.lang.String encoding)

setWrapperAltMap

public void setWrapperAltMap(java.lang.String val)

setCacheBeanWrapper

public void setCacheBeanWrapper(java.lang.String val)

setMruMaxStrongSize

public void setMruMaxStrongSize(java.lang.String size)

setTemplateUpdateDelay

public void setTemplateUpdateDelay(java.lang.String delay)

setContainer

public void setContainer(Container container)

getNoCharsetInContentType

public boolean getNoCharsetInContentType()

getTemplatePath

public java.lang.String getTemplatePath()

getNocache

public boolean getNocache()

getDebug

public boolean getDebug()

getConfig

public freemarker.template.Configuration getConfig()

getWrapper

public freemarker.template.ObjectWrapper getWrapper()

getContentType

public java.lang.String getContentType()

getConfiguration

public freemarker.template.Configuration getConfiguration(javax.servlet.ServletContext servletContext)

init

public void init(javax.servlet.ServletContext servletContext)
          throws freemarker.template.TemplateException
Throws:
freemarker.template.TemplateException

createConfiguration

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

this implementation

Parameters:
servletContext -
Throws:
freemarker.template.TemplateException

buildScopesHashModel

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

createObjectWrapper

protected freemarker.template.ObjectWrapper createObjectWrapper(javax.servlet.ServletContext servletContext)

createTemplateLoader

protected freemarker.cache.TemplateLoader createTemplateLoader(javax.servlet.ServletContext servletContext,
                                                               java.lang.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:
templatePath - the template path to create a loader for
Returns:
a newly created template loader
Throws:
java.io.IOException

loadSettings

protected void loadSettings(javax.servlet.ServletContext servletContext)
Load the settings from the /freemarker.properties file on the classpath

See Also:
for the definition of valid settings

addSetting

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

buildTemplateModel

public ScopesHashModel buildTemplateModel(ValueStack stack,
                                          java.lang.Object action,
                                          javax.servlet.ServletContext servletContext,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          freemarker.template.ObjectWrapper wrapper)

populateContext

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


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.