com.opensymphony.module.sitemesh.filter
Class PageFilter

java.lang.Object
  extended by com.opensymphony.module.sitemesh.filter.PageFilter
All Implemented Interfaces:
RequestConstants, Filter

public class PageFilter
extends Object
implements Filter, RequestConstants

Main SiteMesh filter for applying Decorators to entire Pages.

Version:
$Revision: 1.6 $
Author:
Joe Walnes, Scott Farquhar

Field Summary
private  Factory factory
           
private  FilterConfig filterConfig
           
 
Fields inherited from interface com.opensymphony.module.sitemesh.RequestConstants
DECORATOR, FILTER_APPLIED, PAGE, ROBOT, USING_STREAM
 
Constructor Summary
PageFilter()
           
 
Method Summary
protected  void applyDecorator(Page page, Decorator decorator, HttpServletRequest request, HttpServletResponse response)
          Apply Decorator to Page and write to the response.
 void destroy()
          Shutdown filter.
 void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain)
          Main method of the Filter.
private  String extractRequestPath(HttpServletRequest request)
           
 FilterConfig getFilterConfig()
          Deprecated. Not needed in final version of Servlet 2.3 API - replaced by init().
 void init(FilterConfig filterConfig)
          Set FilterConfig, and get instance of DecoratorMapper.
protected  Page parsePage(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
          Continue in filter-chain, writing all content to buffer and parsing into returned Page object.
 void setFilterConfig(FilterConfig filterConfig)
          Deprecated. Not needed in final version of Servlet 2.3 API - replaced by init().
private  void writeOriginal(HttpServletRequest request, HttpServletResponse response, Page page)
          Write the original page data to the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filterConfig

private FilterConfig filterConfig

factory

private Factory factory
Constructor Detail

PageFilter

public PageFilter()
Method Detail

doFilter

public void doFilter(ServletRequest rq,
                     ServletResponse rs,
                     FilterChain chain)
              throws IOException,
                     ServletException
Main method of the Filter.

Checks if the Filter has been applied this request. If not, parses the page and applies Decorator (if found).

Specified by:
doFilter in interface Filter
Throws:
IOException
ServletException

extractRequestPath

private String extractRequestPath(HttpServletRequest request)

init

public void init(FilterConfig filterConfig)
Set FilterConfig, and get instance of DecoratorMapper.

Specified by:
init in interface Filter

getFilterConfig

public FilterConfig getFilterConfig()
Deprecated. Not needed in final version of Servlet 2.3 API - replaced by init().


setFilterConfig

public void setFilterConfig(FilterConfig filterConfig)
Deprecated. Not needed in final version of Servlet 2.3 API - replaced by init().


destroy

public void destroy()
Shutdown filter.

Specified by:
destroy in interface Filter

parsePage

protected Page parsePage(HttpServletRequest request,
                         HttpServletResponse response,
                         FilterChain chain)
                  throws IOException,
                         ServletException
Continue in filter-chain, writing all content to buffer and parsing into returned Page object. If Page is not parseable, null is returned.

To debug the PageWriter, add the following to the servlet configuration:

 <init-param>
     <param-name>debug.pagewriter</param-name>
     <param-value>true</param-value>
 </init-param>
 

Throws:
IOException
ServletException

applyDecorator

protected void applyDecorator(Page page,
                              Decorator decorator,
                              HttpServletRequest request,
                              HttpServletResponse response)
                       throws ServletException,
                              IOException
Apply Decorator to Page and write to the response.

Throws:
ServletException
IOException

writeOriginal

private void writeOriginal(HttpServletRequest request,
                           HttpServletResponse response,
                           Page page)
                    throws IOException
Write the original page data to the response.

Throws:
IOException

www.opensymphony.com/sitemesh/