org.apache.struts2.sitemesh
Class FreemarkerDecoratorServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by freemarker.ext.servlet.FreemarkerServlet
              extended by org.apache.struts2.sitemesh.FreemarkerDecoratorServlet
All Implemented Interfaces:
java.io.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
protected  freemarker.template.Configuration config
           
protected  boolean debug
           
protected  FreemarkerManager freemarkerManager
           
protected  boolean nocache
           
static long serialVersionUID
           
protected  java.lang.String templatePath
           
 
Fields inherited from class freemarker.ext.servlet.FreemarkerServlet
KEY_APPLICATION, KEY_APPLICATION_PRIVATE, KEY_INCLUDE, KEY_JSP_TAGLIBS, KEY_REQUEST, KEY_REQUEST_PARAMETERS, KEY_REQUEST_PRIVATE, KEY_SESSION
 
Constructor Summary
FreemarkerDecoratorServlet()
           
 
Method Summary
protected  freemarker.template.Configuration createConfiguration()
          Create the instance of the freemarker Configuration object.
protected  java.util.Locale deduceLocale(java.lang.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
createModel, createObjectWrapper, createRequestParametersHashModel, createTemplateLoader, getConfiguration, getObjectWrapper, getTemplatePath, initializeServletContext, initializeSession, postTemplateProcess, preprocessRequest, requestUrlToTemplatePath
 
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

freemarkerManager

protected FreemarkerManager freemarkerManager

serialVersionUID

public static final long serialVersionUID
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
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,
                  java.io.IOException
Overrides:
doGet in class freemarker.ext.servlet.FreemarkerServlet
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.IOException
Overrides:
doPost in class freemarker.ext.servlet.FreemarkerServlet
Throws:
javax.servlet.ServletException
java.io.IOException

deduceLocale

protected java.util.Locale deduceLocale(java.lang.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

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,
                                     java.io.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
java.io.IOException
See Also:
FreemarkerServlet.preTemplateProcess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, freemarker.template.Template, freemarker.template.TemplateModel)


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