Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../../img/srcFileCovDistChart8.png 29% of files have more coverage
58   189   23   14,5
26   102   0,4   4
4     5,75  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  FeedAction       Line # 54 58 0% 23 18 79,5% 0.79545456
 
  (10)
 
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.action;
33   
34    import net.sourceforge.pebble.Constants;
35    import net.sourceforge.pebble.comparator.BlogEntryComparator;
36    import net.sourceforge.pebble.domain.*;
37    import net.sourceforge.pebble.web.view.NotModifiedView;
38    import net.sourceforge.pebble.web.view.View;
39    import net.sourceforge.pebble.web.view.impl.AtomView;
40    import net.sourceforge.pebble.web.view.impl.RdfView;
41    import net.sourceforge.pebble.web.view.impl.RssView;
42   
43    import javax.servlet.ServletException;
44    import javax.servlet.http.HttpServletRequest;
45    import javax.servlet.http.HttpServletResponse;
46    import java.text.SimpleDateFormat;
47    import java.util.*;
48   
49    /**
50    * Gets the RSS for a blog.
51    *
52    * @author Simon Brown
53    */
 
54    public class FeedAction extends Action {
55   
56    /**
57    * Peforms the processing associated with this action.
58    *
59    * @param request the HttpServletRequest instance
60    * @param response the HttpServletResponse instance
61    * @return the name of the next view
62    */
 
63  14 toggle public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
64  14 AbstractBlog blog = (AbstractBlog)getModel().get(Constants.BLOG_KEY);
65  14 String flavor = request.getParameter("flavor");
66   
67  14 SimpleDateFormat httpFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
68  14 httpFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
69   
70  14 String ifModifiedSince = request.getHeader("If-Modified-Since");
71  14 String ifNoneMatch = request.getHeader("If-None-Match");
72   
73  14 if (flavor != null && flavor.equalsIgnoreCase("atom")) {
74  0 response.setContentType("application/atom+xml; charset=" + blog.getCharacterEncoding());
75    } else {
76  14 response.setContentType("application/xml; charset=" + blog.getCharacterEncoding());
77    }
78   
79  14 Date lastModified = blog.getLastModified();
80  14 response.setDateHeader("Last-Modified", lastModified.getTime());
81  14 response.setHeader("ETag", "\"" + httpFormat.format(lastModified) + "\"");
82   
83  14 if (ifModifiedSince != null && ifModifiedSince.equals(httpFormat.format(lastModified))) {
84  2 return new NotModifiedView();
85  12 } else if (ifNoneMatch != null && ifNoneMatch.equals("\"" + httpFormat.format(lastModified) + "\"")) {
86  2 return new NotModifiedView();
87    } else {
88  10 List blogEntries;
89  10 String s = request.getParameter("includeAggregatedContent");
90  10 boolean includeAggregatedContent = (s == null || s.equalsIgnoreCase("true"));
91   
92  10 if (blog instanceof Blog) {
93  10 Tag tag = getTag((Blog)blog, request);
94  10 Category category = getCategory((Blog)blog, request);
95  10 String author = getAuthor(request);
96   
97  10 if (tag != null) {
98  0 blogEntries = ((Blog)blog).getRecentPublishedBlogEntries(tag);
99  0 getModel().put("tag", tag);
100  10 } else if (category != null) {
101  2 blogEntries = ((Blog)blog).getRecentPublishedBlogEntries(category);
102  2 getModel().put("category", category);
103  8 } else if (author != null) {
104  0 blogEntries = ((Blog)blog).getRecentPublishedBlogEntries(author);
105  0 getModel().put("author", author);
106    } else {
107  8 blogEntries = ((Blog)blog).getRecentPublishedBlogEntries();
108    }
109    } else {
110  0 blogEntries = blog.getRecentBlogEntries();
111    }
112   
113  10 List blogEntriesForFeed = new ArrayList();
114  10 Iterator it = blogEntries.iterator();
115  12 while (it.hasNext()) {
116  2 BlogEntry entry = (BlogEntry)it.next();
117   
118  2 if (!includeAggregatedContent && entry.isAggregated()) {
119  0 continue;
120    } else {
121  2 blogEntriesForFeed.add(entry);
122    }
123    }
124   
125  10 Collections.sort(blogEntriesForFeed, new BlogEntryComparator());
126   
127  10 getModel().put(Constants.BLOG_ENTRIES, blogEntriesForFeed);
128   
129    // set the locale of this feed request to be English
130  10 javax.servlet.jsp.jstl.core.Config.set(
131    request,
132    javax.servlet.jsp.jstl.core.Config.FMT_LOCALE,
133    Locale.ENGLISH);
134   
135  10 if (flavor != null && flavor.equalsIgnoreCase("atom")) {
136  0 return new AtomView();
137  10 } else if (flavor != null && flavor.equalsIgnoreCase("rdf")) {
138  0 return new RdfView();
139    } else {
140  10 return new RssView();
141    }
142    }
143    }
144   
145    /**
146    * Helper method to find a named tag from a request parameter.
147    *
148    * @param blog the blog for which the feed is for
149    * @param request the HTTP request containing the tag parameter
150    * @return a Tag instance, or null if the tag isn't
151    * specified or can't be found
152    */
 
153  10 toggle private Tag getTag(Blog blog, HttpServletRequest request) {
154  10 String tag = request.getParameter("tag");
155  10 if (tag != null) {
156  0 return new Tag(tag, blog);
157    } else {
158  10 return null;
159    }
160    }
161   
162    /**
163    * Helper method to find a named category from a request parameter.
164    *
165    * @param blog the blog for which the feed is for
166    * @param request the HTTP request containing the category parameter
167    * @return a Category instance, or null if the category isn't
168    * specified or can't be found
169    */
 
170  10 toggle private Category getCategory(Blog blog, HttpServletRequest request) {
171  10 String categoryId = request.getParameter("category");
172  10 if (categoryId != null) {
173  2 return blog.getCategory(categoryId);
174    } else {
175  8 return null;
176    }
177    }
178   
179    /**
180    * Helper method to find a named author from a request parameter.
181    *
182    * @param request the HTTP request containing the tag parameter
183    * @return a String username, or null if the author isn't specified
184    */
 
185  10 toggle private String getAuthor(HttpServletRequest request) {
186  10 return request.getParameter("author");
187    }
188   
189    }