com.opensymphony.webwork.views.sitemesh
Class ApplyDecoratorBean

java.lang.Object
  extended by com.opensymphony.webwork.components.Component
      extended by com.opensymphony.webwork.views.sitemesh.ApplyDecoratorBean

public class ApplyDecoratorBean
extends Component

This is the WebWork component that implements Freemarker's ApplyDecorator Transform. To use this Freemarker Transform, it needs to be enabled in webwork.properties (which is enabled by default)

 webwork.freemarker.sitemesh.applyDecoratorTransform = true
 
An example of usage would be as follows:-

In Sitemesh's decorators.xml

   <decorators defaultdir="/WEB-INF/decorators">
        ....
      <decorator name="panel" page="/panelDecorator.ftl" />
   </decorators*gt;
 
Decorator (panelDecorator.ftl)

  <table border="1">
    <tr>
        <td>${title}</td>
    </tr>
    <tr>
      <td>${body}</td>
    </tr>
  </table>
 
Freemarker page that uses decorator

         <html> 
    <head>
       <title>some title</title>
    </head>
    <body>
      <h1>some body title</h1>
      <@sitemesh.applydecorator name="panel" page="/pages/pageToBeDecorated.ftl" />
    </body>
   </html>
 
An example of pageToBeDecorated.ftl

  <html>
    <head>
       <title>Panel Title</title>
    </head>
    <body>
       Panel Content
    </body>
  </html>
 
The nett outcome would be:-
   <html>
     <title>some title&l/title>
   <body>
     <h1>some body title</h1>
     <table border="1">
       <tr>
        <td>Panel Title</td>
       </tr>
       <tr>
          <td>Panel Content</td>
       </tr>
     </table>
   </body>
   </html>
 
The following are method hooks available to ApplyDecoratorBean and its subclass

Version:
$Date$ $Id$
Author:
tmjee
See Also:
SitemeshModel, FreemarkerManager.buildTemplateModel(OgnlValueStack, Object, ServletContext, HttpServletRequest, HttpServletResponse, ObjectWrapper)

Field Summary
 
Fields inherited from class com.opensymphony.webwork.components.Component
COMPONENT_STACK, id, parameters, stack
 
Constructor Summary
ApplyDecoratorBean(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response)
           
 
Method Summary
protected  freemarker.template.SimpleHash createModel()
          Create a Freemarker's Model through FreemarkerManager.buildTemplateModel(OgnlValueStack, Object, ServletContext, HttpServletRequest, HttpServletResponse, ObjectWrapper).
protected  Locale deduceLocale(ActionInvocation invocation, freemarker.template.Configuration configuration)
          Attempt to deduce the Locale, based on invocation and Freemarker's configuration.
protected  boolean end(Writer writer, String body, boolean popComponentStack)
          Callback for the start tag of this component.
protected  void endAllowingExceptionThrowing(Writer writer, String body)
          Render the page specified with the decorator
 String getContentType()
          The content type, default to "text/html".
protected  com.opensymphony.module.sitemesh.Decorator getDecorator(HttpServletRequest request, String decoratorName)
          Returns a Sitemesh Decorator object with the decoratorName specified.
 String getEncoding()
          Set the encoding eg.
protected  freemarker.template.Template getFreemarkerTemplate(String templatePath)
          Method Hook:

Returns a Freemarker's Template bsaed on the templatePath supplied.

 String getName()
          Set the name of the Sitemesh decorator to be used.
 String getPage()
          Set the page to be decorated.
protected  com.opensymphony.module.sitemesh.PageParser getPageParser(String contentType)
          Returns a Sitemesh PageParser object with the contentType specified, which by default is "text/html".
protected  com.opensymphony.module.sitemesh.Factory getSitemeshFactory()
          Returns a Sitemesh Factory object.
protected  com.opensymphony.module.sitemesh.Page parsePageObjectFromAbsoluteUrl(String absoluteUrl)
          Returns back a Sitemesh Page object assuming that the absoluteUrl is the content of the "to-be-decorated" page.
protected  com.opensymphony.module.sitemesh.Page parsePageObjectFromContent(String content)
          Returns back a Sitemesh Page object assuming that the content is the content of the "to-be-decorated" page.
protected  com.opensymphony.module.sitemesh.Page parsePageObjectFromRelativeUrlPath(String relativeUrl)
          Returns a Sitemesh Page object assuming the relativeUrl is the freemarker page that is "to-be-decorated".
 void setContentType(String contentType)
           
 void setEncoding(String encoding)
           
 void setName(String name)
           
 void setPage(String page)
           
 boolean start(Writer writer)
          Callback for the start tag of this component.
 
Methods inherited from class com.opensymphony.webwork.components.Component
addAllParameters, addParameter, altSyntax, copyParams, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setId, toString, usesBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplyDecoratorBean

public ApplyDecoratorBean(OgnlValueStack stack,
                          HttpServletRequest request,
                          HttpServletResponse response)
Parameters:
stack -
Method Detail

getName

public String getName()
Set the name of the Sitemesh decorator to be used.

Returns:
String

setName

public void setName(String name)

getPage

public String getPage()
Set the page to be decorated. This could be either an

Returns:
String

setPage

public void setPage(String page)

getContentType

public String getContentType()
The content type, default to "text/html".

Returns:
String

setContentType

public void setContentType(String contentType)

getEncoding

public String getEncoding()
Set the encoding eg. "UTF-8".

Returns:
String

setEncoding

public void setEncoding(String encoding)

start

public boolean start(Writer writer)
Description copied from class: Component
Callback for the start tag of this component. Should the body be evaluated?

Overrides:
start in class Component
Parameters:
writer - the output writer.
Returns:
true if the body should be evaluated
See Also:
Component.start(java.io.Writer)

end

protected boolean end(Writer writer,
                      String body,
                      boolean popComponentStack)
Description copied from class: Component
Callback for the start tag of this component. Should the body be evaluated again?

NOTE: has a parameter to determine to pop the component stack.

Overrides:
end in class Component
Parameters:
writer - the output writer.
body - the rendered body.
popComponentStack - should the component stack be popped?
Returns:
true if the body should be evaluated again
See Also:
Component.end(java.io.Writer, java.lang.String, boolean)

endAllowingExceptionThrowing

protected void endAllowingExceptionThrowing(Writer writer,
                                            String body)
                                     throws IOException,
                                            ServletException,
                                            freemarker.template.TemplateException
Render the page specified with the decorator

Parameters:
writer -
body -
Throws:
IOException
ServletException
freemarker.template.TemplateException

getFreemarkerTemplate

protected freemarker.template.Template getFreemarkerTemplate(String templatePath)
                                                      throws IOException,
                                                             freemarker.template.TemplateException
Method Hook:

Returns a Freemarker's Template bsaed on the templatePath supplied.

Parameters:
templatePath -
Returns:
Throws:
IOException
freemarker.template.TemplateException

parsePageObjectFromContent

protected com.opensymphony.module.sitemesh.Page parsePageObjectFromContent(String content)
                                                                    throws IOException
Returns back a Sitemesh Page object assuming that the content is the content of the "to-be-decorated" page.

Parameters:
content -
Returns:
Throws:
IOException

parsePageObjectFromAbsoluteUrl

protected com.opensymphony.module.sitemesh.Page parsePageObjectFromAbsoluteUrl(String absoluteUrl)
                                                                        throws IOException
Returns back a Sitemesh Page object assuming that the absoluteUrl is the content of the "to-be-decorated" page.

Parameters:
absoluteUrl -
Returns:
Throws:
IOException

parsePageObjectFromRelativeUrlPath

protected com.opensymphony.module.sitemesh.Page parsePageObjectFromRelativeUrlPath(String relativeUrl)
                                                                            throws freemarker.template.TemplateException,
                                                                                   IOException
Returns a Sitemesh Page object assuming the relativeUrl is the freemarker page that is "to-be-decorated".

Parameters:
relativeUrl -
Returns:
Throws:
freemarker.template.TemplateException
IOException

getSitemeshFactory

protected com.opensymphony.module.sitemesh.Factory getSitemeshFactory()
Returns a Sitemesh Factory object.

Returns:

getPageParser

protected com.opensymphony.module.sitemesh.PageParser getPageParser(String contentType)
Returns a Sitemesh PageParser object with the contentType specified, which by default is "text/html".

Parameters:
contentType -
Returns:

getDecorator

protected com.opensymphony.module.sitemesh.Decorator getDecorator(HttpServletRequest request,
                                                                  String decoratorName)
Returns a Sitemesh Decorator object with the decoratorName specified.

Parameters:
request -
decoratorName -
Returns:

deduceLocale

protected Locale deduceLocale(ActionInvocation invocation,
                              freemarker.template.Configuration configuration)
Attempt to deduce the Locale, based on invocation and Freemarker's configuration.

Parameters:
invocation -
configuration -
Returns:

createModel

protected freemarker.template.SimpleHash createModel()
                                              throws freemarker.template.TemplateException
Create a Freemarker's Model through FreemarkerManager.buildTemplateModel(OgnlValueStack, Object, ServletContext, HttpServletRequest, HttpServletResponse, ObjectWrapper).

Returns:
Throws:
freemarker.template.TemplateException

WebWork Project Page