|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cocoon.servlet.CocoonFilterGeneratorImpl
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.
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 |
public static final String COCOON_SERVLET_CLASS_NAME_PARAM
cocoon-servlet-class-name
public static final String COCOON_SERVLET_CLASS_NAME_DEFAULT
org.apache.cocoon.servlet.CocoonServlet
.
Constructor Detail |
public CocoonFilterGeneratorImpl()
Method Detail |
public void init(FilterConfig cfg) throws ServletException
init
in interface Filter
ServletException
public void setFilterConfig(FilterConfig cfg)
cfg
- The new filterConfig valuepublic FilterConfig getFilterConfig()
public void destroy()
If cocoon servlet is defined, destroy it.
destroy
in interface Filter
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException
The sequence of this filter:
doFilter
in interface Filter
req
- the http requestres
- the final http responsefc
- the filter chain
IOException
- reading/writing failed
ServletException
- processing failedprotected String getCocoonServletClassName()
The cocoon servlet class name can be configured in the filter configurarion.
COCOON_SERVLET_CLASS_NAME_PARAM
,
COCOON_SERVLET_CLASS_NAME_DEFAULT
protected boolean isVerbose()
protected Servlet createCocoonInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException
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
failedprotected void log(String s)
s
- message to logprotected void logFilterConfig()
protected void logServletContext()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |