org.apache.cocoon.servlet
Class CocoonFilterGeneratorImpl

java.lang.Object
  extended byorg.apache.cocoon.servlet.CocoonFilterGeneratorImpl
All Implemented Interfaces:
Filter

public class CocoonFilterGeneratorImpl
extends Object
implements Filter

This class implements a Servlet 2.3 Cocoon post-processing filter.

First all filters of the filter chain are processed. As a final filter processing step a Cocoon servlet processing is done. In most cases you may want to use this filter for JSP pre-processing, and Cocoon post-processing. You may use this filter not only for JSP pre-processing, but you can define any servlet/filter-chain for the pre-processing.

Xml-data of the filters are passed to cocoon via a request attribute. On Cocoon side the RequestAttributeGenerator will pick the xml-data, and normal cocoon pipeline processing is done.

Using this filter you have to setup a filter, and a filter mapping in the webapp deployment descriptor.

In the cocoon sitemap you have to setup the RequestAttributeGenerator . The pipeline setup should match the request URI, and it should use the RequestAttributeGenerator as its generator.

A sample web.xml snippet:


  <filter>
    <filter-name>CocoonFilterGenerator</filter-name>
    <display-name>CocoonFilterGenerator</display-name>
    <description>Run JSP/Servlet processing before feeding into Cocoon</description>
    <filter-class>org.apache.cocoon.servlet.CocoonFilterGeneratorImpl</filter-class>
    <init-param>
      <param-name>cocoon-servlet-class-name</param-name>
      <param-value>org.apache.cocoon.servlet.CocoonServlet</param-value>
    </init-param>
    <init-param>
      <param-name>verbose</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CocoonFilterGenerator</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
 

A simple sitemap snippet:


  <map:match pattern="docs/samples/jsp/*">
    <map:generate type="req-attr"/>
    <map:transform src="stylesheets/page/simple-page2html.xsl">
    <map:parameter name="view-source" value="docs/samples/jsp/{1}"/>
    <!--
    Run-time configuration is done through these
    <map:parameter/> elements. Again, let's have a look at the
    javadocs:
    "[...] All <map:parameter> declarations will be made
    available in the XSLT stylesheet as xsl:variables. [...]"
    -->
    </map:transform>
    <map:serialize/>
  </map:match>
 

Conclusion of this example: The request URI /cocoon/docs/samples/jsp/hello.jsp is processed by the filter CocoonFilterGenerator, due to the filter-mapping matching. The pipeline of the snippet matches the request, and the req-attr generator picks the xml-data of the filter-processing and sends it into the cocoon pipeline.

Version:
CVS $Id: CocoonFilterGeneratorImpl.java 156626 2005-03-09 09:43:39Z cziegeler $
Author:
Bernhard Huber

Field Summary
static String COCOON_SERVLET_CLASS_NAME_DEFAULT
          Specifies the Cocoon servlet class name default value, ie org.apache.cocoon.servlet.CocoonServlet.
static String COCOON_SERVLET_CLASS_NAME_PARAM
          Specifies the name of the filter configuration, definig the Cocoon servlet class name, ie cocoon-servlet-class-name
 
Constructor Summary
CocoonFilterGeneratorImpl()
           
 
Method Summary
protected  Servlet createCocoonInstance()
          create Cocoon servlet instance.
 void destroy()
          callback method, destroying the filter If cocoon servlet is defined, destroy it.
 void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
          do the filter processing.
protected  String getCocoonServletClassName()
          Gets the cocoonServletClassName The cocoon servlet class name can be configured in the filter configurarion.
 FilterConfig getFilterConfig()
          Gets the filterConfig attribute of the CocoonFilterGeneratorImpl object
 void init(FilterConfig cfg)
           
protected  boolean isVerbose()
          Gets the verbose attribute of the CocoonFilterGeneratorImpl object
protected  void log(String s)
          log message to servlet context log
protected  void logFilterConfig()
          Log all filter config parameter
protected  void logServletContext()
          Log all servlet attribute, and parameters.
 void setFilterConfig(FilterConfig cfg)
          Sets the filterConfig attribute of the CocoonFilterGeneratorImpl object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COCOON_SERVLET_CLASS_NAME_PARAM

public static final String COCOON_SERVLET_CLASS_NAME_PARAM
Specifies the name of the filter configuration, definig the Cocoon servlet class name, ie cocoon-servlet-class-name

Since:
1.0
See Also:
Constant Field Values

COCOON_SERVLET_CLASS_NAME_DEFAULT

public static final String COCOON_SERVLET_CLASS_NAME_DEFAULT
Specifies the Cocoon servlet class name default value, ie org.apache.cocoon.servlet.CocoonServlet.

Since:
1.0
See Also:
Constant Field Values
Constructor Detail

CocoonFilterGeneratorImpl

public CocoonFilterGeneratorImpl()
Method Detail

init

public void init(FilterConfig cfg)
          throws ServletException
Specified by:
init in interface Filter
Throws:
ServletException

setFilterConfig

public void setFilterConfig(FilterConfig cfg)
Sets the filterConfig attribute of the CocoonFilterGeneratorImpl object

Parameters:
cfg - The new filterConfig value
Since:
1.0

getFilterConfig

public FilterConfig getFilterConfig()
Gets the filterConfig attribute of the CocoonFilterGeneratorImpl object

Returns:
The filterConfig value
Since:
1.0

destroy

public void destroy()
callback method, destroying the filter

If cocoon servlet is defined, destroy it.

Specified by:
destroy in interface Filter
Since:
1.0

doFilter

public void doFilter(ServletRequest req,
                     ServletResponse res,
                     FilterChain fc)
              throws IOException,
                     ServletException
do the filter processing.

The sequence of this filter:

  1. Process filters defined in the filter chain
  2. Use cocoon as final processing step

Specified by:
doFilter in interface Filter
Parameters:
req - the http request
res - the final http response
fc - the filter chain
Throws:
IOException - reading/writing failed
ServletException - processing failed
Since:
1.0

getCocoonServletClassName

protected String getCocoonServletClassName()
Gets the cocoonServletClassName

The cocoon servlet class name can be configured in the filter configurarion.

Returns:
The cocoonServletClassName value
Since:
1.0
See Also:
COCOON_SERVLET_CLASS_NAME_PARAM, COCOON_SERVLET_CLASS_NAME_DEFAULT

isVerbose

protected boolean isVerbose()
Gets the verbose attribute of the CocoonFilterGeneratorImpl object

Returns:
The verbose value
Since:
1.0

createCocoonInstance

protected Servlet createCocoonInstance()
                                throws ClassNotFoundException,
                                       InstantiationException,
                                       IllegalAccessException,
                                       ServletException
create Cocoon servlet instance.

Returns:
The cocoonInstance value
Throws:
ClassNotFoundException - Cocoon servlet class is not available
InstantiationException - failed to instaniate Cocoon servlet class
IllegalAccessException - initializing of Cocoon servlet instance failed
ServletException - initializing of Cocoon servlet instance failed
Since:
1.0

log

protected void log(String s)
log message to servlet context log

Parameters:
s - message to log
Since:
1.0

logFilterConfig

protected void logFilterConfig()
Log all filter config parameter

Since:
1.0

logServletContext

protected void logServletContext()
Log all servlet attribute, and parameters.

Since:
1.0


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.