Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
46   188   18   15,33
16   103   0,39   3
3     6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PreProcessingFilter       Line # 67 46 0% 18 65 0% 0.0
 
No Tests
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.web.filter;
33   
34    import net.sourceforge.pebble.Configuration;
35    import net.sourceforge.pebble.Constants;
36    import net.sourceforge.pebble.PebbleContext;
37    import net.sourceforge.pebble.security.PebbleUserDetails;
38    import net.sourceforge.pebble.util.HttpsURLRewriter;
39    import net.sourceforge.pebble.util.SecurityUtils;
40    import net.sourceforge.pebble.util.CookieUtils;
41    import net.sourceforge.pebble.util.UrlRewriter;
42    import net.sourceforge.pebble.util.Utilities;
43    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
44    import net.sourceforge.pebble.comparator.BlogEntryComparator;
45    import net.sourceforge.pebble.comparator.BlogByLastModifiedDateComparator;
46    import net.sourceforge.pebble.decorator.ContentDecoratorChain;
47    import net.sourceforge.pebble.domain.*;
48    import org.apache.commons.logging.Log;
49    import org.apache.commons.logging.LogFactory;
50   
51    import javax.servlet.*;
52    import javax.servlet.http.HttpServletRequest;
53    import javax.servlet.http.Cookie;
54    import javax.servlet.http.HttpServletResponse;
55    import javax.servlet.jsp.jstl.core.Config;
56    import java.io.IOException;
57    import java.net.URLDecoder;
58    import java.util.Collections;
59    import java.util.List;
60    import java.util.Locale;
61   
62    /**
63    * A filter respsonsible for setting up common objects.
64    *
65    * @author Simon Brown
66    */
 
67    public class PreProcessingFilter implements Filter {
68   
69    /** the log used by this class */
70    private static Log log = LogFactory.getLog(PreProcessingFilter.class);
71   
72    /** the config of this filter */
73    private FilterConfig filterConfig;
74   
75    /**
76    * Initialises this instance.
77    *
78    * @param config a FilterConfig instance
79    */
 
80  0 toggle public void init(FilterConfig config) {
81  0 this.filterConfig = config;
82    }
83   
84    /**
85    * Called when this filter is taken out of service.
86    */
 
87  0 toggle public void destroy() {
88    }
89   
90    /**
91    * Contains the processing associated with this filter.
92    */
 
93  0 toggle public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
94    throws ServletException, IOException {
95   
96  0 HttpServletRequest httpRequest = (HttpServletRequest)request;
97   
98    // log.info("Session is " + httpRequest.getSession().getId());
99    // HttpServletResponse httpResponse = (HttpServletResponse)response;
100    // Cookie cookie = CookieUtils.getCookie(httpRequest.getCookies(), "JSESSIONID");
101    // if (cookie != null) {
102    // log.info("Domain is " + cookie.getDomain());
103    // log.info("Path is " + cookie.getPath());
104    // cookie.setDomain(".example.com");
105    // cookie.setPath("/");
106    // httpResponse.addCookie(cookie);
107    // }
108   
109  0 String externalUri = (String)request.getAttribute(Constants.EXTERNAL_URI);
110  0 if (externalUri.startsWith("/common/") ||
111    externalUri.startsWith("/dwr/") ||
112    externalUri.startsWith("/FCKeditor/") ||
113    externalUri.startsWith("/scripts/") ||
114    externalUri.startsWith("/themes/") ||
115    externalUri.equals("/pebble.css") ||
116    externalUri.equals("/jckconfig_pebble.js") ||
117    externalUri.equals("/favicon.ico")
118    ) {
119    // do nothing
120    } else {
121  0 AbstractBlog blog = (AbstractBlog)request.getAttribute(Constants.BLOG_KEY);
122  0 if (blog instanceof Blog) {
123  0 Blog b = (Blog)blog;
124  0 ContentDecoratorContext context = new ContentDecoratorContext();
125  0 context.setView(ContentDecoratorContext.SUMMARY_VIEW);
126  0 context.setMedia(ContentDecoratorContext.HTML_PAGE);
127   
128  0 List blogEntries = b.getRecentPublishedBlogEntries();
129  0 ContentDecoratorChain.decorate(context, blogEntries);
130  0 Collections.sort(blogEntries, new BlogEntryComparator());
131  0 httpRequest.setAttribute(Constants.RECENT_BLOG_ENTRIES, blogEntries);
132   
133  0 List<Response> recentApprovedResponses = b.getRecentApprovedResponses();
134  0 for (Response r : recentApprovedResponses) {
135  0 if (r instanceof Comment) {
136  0 b.getContentDecoratorChain().decorate(context, (Comment)r);
137  0 } else if (r instanceof TrackBack){
138  0 b.getContentDecoratorChain().decorate(context, (TrackBack)r);
139    }
140    }
141  0 httpRequest.setAttribute(Constants.RECENT_RESPONSES, recentApprovedResponses);
142   
143  0 httpRequest.setAttribute(Constants.CATEGORIES, b.getCategories());
144  0 httpRequest.setAttribute(Constants.TAGS, b.getTags());
145  0 httpRequest.setAttribute(Constants.PLUGIN_PROPERTIES, b.getPluginProperties());
146  0 httpRequest.setAttribute(Constants.ARCHIVES, b.getArchives());
147  0 httpRequest.setAttribute(Constants.BLOG_TYPE, "singleblog");
148    } else {
149  0 httpRequest.setAttribute(Constants.BLOG_TYPE, "multiblog");
150    }
151   
152  0 if (PebbleContext.getInstance().getConfiguration().isMultiBlog()) {
153  0 httpRequest.setAttribute(Constants.MULTI_BLOG_KEY, BlogManager.getInstance().getMultiBlog());
154  0 httpRequest.setAttribute(Constants.MULTI_BLOG_URL, Utilities.calcBaseUrl(request.getScheme(), BlogManager.getInstance().getMultiBlog().getUrl()));
155   
156  0 List blogs = BlogManager.getInstance().getPublicBlogs();
157  0 Collections.sort(blogs, new BlogByLastModifiedDateComparator());
158  0 httpRequest.setAttribute(Constants.BLOGS, blogs);
159    }
160   
161    // change the character encoding so that we can successfully get
162    // international characters from the request when HTML forms are submitted
163    // ... but only if the browser doesn't send the character encoding back
164  0 if (request.getCharacterEncoding() == null) {
165  0 request.setCharacterEncoding(blog.getCharacterEncoding());
166    }
167   
168  0 PebbleUserDetails user = SecurityUtils.getUserDetails();
169  0 if (user != null) {
170  0 httpRequest.setAttribute(Constants.AUTHENTICATED_USER, user);
171    }
172   
173  0 Config.set(request, Config.FMT_LOCALE, blog.getLocale());
174  0 Config.set(request, Config.FMT_FALLBACK_LOCALE, Locale.ENGLISH);
175    }
176   
177  0 try {
178  0 Configuration configuration = PebbleContext.getInstance().getConfiguration();
179  0 if(configuration.getSecureUrl().startsWith("https")) {
180  0 UrlRewriter.useThisRewriter(new HttpsURLRewriter(request.getScheme()));
181    }
182   
183  0 chain.doFilter(request, response);
184    } finally {
185  0 UrlRewriter.clear();
186    }
187    }
188    }