Coverage details for org.chwf.servlet.view.TemplateFilter

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.servlet.view;
34  
35 import java.io.IOException;
36  
37 import javax.servlet.FilterChain;
38 import javax.servlet.ServletException;
39 import javax.servlet.ServletRequest;
40 import javax.servlet.ServletResponse;
41 import javax.servlet.http.HttpServletRequest;
42  
43 import org.chwf.servlet.ServletUtils;
44 import org.chwf.servlet.filter.FilterSupport;
45 import org.chwf.servlet.filter.ResourceMapper;
46  
47 /**
48  * <p>A filter that invokes a template, passing in the chain to the target
49  * URI. The template can insert the target page (body uri) using the
50  * <code>&lt;ji18n:includeBody></code> tag.</p>
51  *
52  * <p>The target page is embedded into the template using an include rather
53  * than the <code>doChain()</code> method. This means that once the
54  * <code>TemplateFilter</code> is invoked, no further filters will be called.
55  * The <code>TemplateFilter</code> should be the last filter in the chain.
56  * The only filter that can follow the <code>TemplateFilter</code> is the
57  * {@link org.chwf.servlet.filter.ResourceMapper}</code>.</p>
58  *
59  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
60  */
6110public class TemplateFilter extends FilterSupport {
62  
63   /**
64    * Request attribute caching the body URI
65    */
661  public static final String BODY_URI =
67     TemplateFilter.class.getName() + ".BODY_URI";
68  
69   /**
70    * Invokes the page template, or the page itself if there is no template.
71    *
72    * @param request The request.
73    * @param response The response.
74    * @param chain The filter chain.
75    * @throws ServletException For servlet exceptions.
76    * @throws IOException For IO exceptions.
77    */
78   public void doFilter(
79     ServletRequest request,
80     ServletResponse response,
81     FilterChain chain)
82     throws IOException, ServletException {
83  
844    PageConfig config = PageConfig.getPageConfig(request);
854    String template = config.getPageTemplate();
864    if (template == null) {
872      chain.doFilter(request, response);
88     } else {
892      getBodyURI((HttpServletRequest) request);
902      ServletUtils.forward(request, response, template);
91     }
924  }
93  
94   /**
95    * Get the template body URI (the included page) for this request.
96    *
97    * @param request The request.
98    * @return The body URI
99    */
100   public static String getBodyURI(HttpServletRequest request) {
1017    return ResourceMapper.getMappedURI(request);
102   }
103 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.