Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
105   215   45   26,25
62   152   0,43   4
4     11,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Request       Line # 51 105 0% 45 9 94,7% 0.94736844
 
  (46)
 
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.logging;
33   
34    import net.sourceforge.pebble.api.permalink.PermalinkProvider;
35    import net.sourceforge.pebble.domain.Blog;
36    import net.sourceforge.pebble.domain.BlogEntry;
37    import net.sourceforge.pebble.domain.Month;
38    import net.sourceforge.pebble.domain.Day;
39    import net.sourceforge.pebble.permalink.DefaultPermalinkProvider;
40   
41    import java.text.SimpleDateFormat;
42    import java.util.regex.Pattern;
43   
44   
45    /**
46    * Represents a requested URL along with a count of how many times it
47    * has been accessed.
48    *
49    * @author Simon Brown
50    */
 
51    public class Request extends CountedUrl {
52   
53    private static final Pattern RESPONSES_FEED_REGEX = Pattern.compile("\\/responses\\/.*.xml");
54    private static final Pattern CATEGORY_FEED_REGEX = Pattern.compile("\\/categories\\/.*\\/.*.xml");
55    private static final Pattern TAG_FEED_REGEX = Pattern.compile("\\/tags\\/.*\\/.*.xml");
56    private static final Pattern AUTHOR_FEED_REGEX = Pattern.compile("\\/authors\\/.*\\/.*.xml");
57   
58    /**
59    * Creates a new instance representing the specified url.
60    *
61    * @param url the url as a String
62    */
 
63  90 toggle public Request(String url) {
64  90 super(url);
65    }
66   
67    /**
68    * Creates a new instance representing the specified url.
69    *
70    * @param url the url as a String
71    * @param blog the owning Blog
72    */
 
73  68 toggle public Request(String url, Blog blog) {
74  68 super(url, blog);
75    }
76   
 
77  158 toggle protected void setUrl(String url) {
78  158 super.setUrl(url);
79   
80  158 if (url == null || url.length() == 0) {
81  10 setName("None");
82  148 } else if (RESPONSES_FEED_REGEX.matcher(url).matches()) {
83  4 setName("Feed : Responses");
84  4 setNewsFeed(true);
85  144 } else if (CATEGORY_FEED_REGEX.matcher(url).matches()) {
86  8 String categoryName = url.substring("/categories/".length(), url.lastIndexOf("/"));
87  8 setName("Feed : category=" + categoryName);
88  8 setNewsFeed(true);
89  136 } else if (TAG_FEED_REGEX.matcher(url).matches()) {
90  4 String tagName = url.substring("/tags/".length(), url.lastIndexOf("/"));
91  4 setName("Feed : tag=" + tagName);
92  4 setNewsFeed(true);
93  132 } else if (AUTHOR_FEED_REGEX.matcher(url).matches()) {
94  4 String authorName = url.substring("/authors/".length(), url.lastIndexOf("/"));
95  4 setName("Feed : author=" + authorName);
96  4 setNewsFeed(true);
97  128 } else if (url.indexOf("rss.xml") > -1 ||
98    url.indexOf("feed.xml") > -1 ||
99    url.indexOf("feed.action") > -1 ||
100    url.indexOf("rdf.xml") > -1 ||
101    url.indexOf("atom.xml") > -1
102    ) {
103  20 setName("Feed : Blog Entries");
104  20 setNewsFeed(true);
105  108 } else if (blog != null) {
106  48 if (url.equals("/")) {
107  2 setName("Home");
108  2 setPageView(true);
109  46 } else if (url.equals("/categories/") || url.equals("/categories")) {
110  4 setName("Categories");
111  4 setPageView(true);
112  42 } else if (url.equals("/tags/") || url.equals("/tags")) {
113  4 setName("Tags");
114  4 setPageView(true);
115  38 } else if (url.equals("/files") || (url.startsWith("/files/") && url.endsWith("/"))) {
116  4 setName("Files");
117  4 setPageView(true);
118  34 } else if (url.startsWith("/categories/")) {
119  4 String categoryName = url.substring("/categories/".length());
120  4 if (categoryName.endsWith("/")) {
121  2 categoryName = categoryName.substring(0, categoryName.length()-1);
122    }
123  4 setName("Category : " + categoryName);
124  4 setPageView(true);
125  30 } else if (url.startsWith("/tags/")) {
126  4 String tagName = url.substring("/tags/".length());
127  4 if (tagName.endsWith("/")) {
128  2 tagName = tagName.substring(0, tagName.length()-1);
129    }
130  4 setName("Tag : " + tagName);
131  4 setPageView(true);
132  26 } else if (url.startsWith("/authors/")) {
133  4 String authorName = url.substring("/authors/".length());
134  4 if (authorName.endsWith("/")) {
135  2 authorName = authorName.substring(0, authorName.length()-1);
136    }
137  4 setName("Author : " + authorName);
138  4 setPageView(true);
139  22 } else if (url.startsWith("/files/")) {
140  4 String fileName = url.substring("/files/".length());
141  4 if (fileName.endsWith("/")) {
142  0 fileName = fileName.substring(0, fileName.length()-1);
143    }
144  4 setName("File : " + fileName);
145  4 setFileDownload(true);
146  18 } else if (url.startsWith("/pages/")) {
147  4 String pageName = url.substring("/pages/".length());
148  4 setName("Static Page : " + pageName);
149  4 setPageView(true);
150  14 } else if (url.startsWith("/search.action")) {
151  4 setName("Search");
152  4 setPageView(true);
153  10 } else if (url.startsWith("/blogentries/")) {
154  2 String pageNumber = url.substring("/blogentries/".length());
155  2 if (pageNumber.indexOf(".") > -1) {
156  2 pageNumber = pageNumber.substring(0, pageNumber.indexOf("."));
157    } else {
158  0 pageNumber = "1";
159    }
160  2 setName("Blog Entries : Page " + pageNumber);
161  2 setPageView(true);
162    } else {
163  8 matchOnPermalinkProvider(url, blog.getPermalinkProvider());
164   
165  8 if (getName() == null) {
166    // try with the default permalink provider
167  2 DefaultPermalinkProvider defaultPermalinkProvider = new DefaultPermalinkProvider();
168  2 defaultPermalinkProvider.setBlog(blog);
169  2 matchOnPermalinkProvider(url, defaultPermalinkProvider);
170    }
171    }
172    }
173   
174  158 if (getName() == null) {
175  60 setName(url);
176  60 setPageView(true);
177    }
178    }
179   
 
180  10 toggle private void matchOnPermalinkProvider(String url,
181    PermalinkProvider permalinkProvider) {
182  10 try {
183  10 if (permalinkProvider.isBlogEntryPermalink(url)) {
184  6 BlogEntry blogEntry = permalinkProvider.getBlogEntry(url);
185  6 if (blogEntry != null) {
186  4 setName("Blog Entry : " + blogEntry.getTitle());
187  4 setPageView(true);
188    }
189  4 } else if (permalinkProvider.isMonthPermalink(url)) {
190  2 Month month = permalinkProvider.getMonth(url);
191  2 SimpleDateFormat formatter = new SimpleDateFormat("MMMM yyyy", blog
192    .getLocale());
193  2 formatter.setTimeZone(blog.getTimeZone());
194  2 if (month != null) {
195  2 setName("Month : " + formatter.format(month.getDate()));
196  2 setPageView(true);
197    }
198  2 } else if (permalinkProvider.isDayPermalink(url)) {
199  2 Day day = null;
200  2 day = permalinkProvider.getDay(url);
201  2 SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy", blog
202    .getLocale());
203  2 formatter.setTimeZone(blog.getTimeZone());
204  2 if (day != null) {
205  2 setName("Day : " + formatter.format(day.getDate()));
206  2 setPageView(true);
207    }
208    }
209    } catch (IllegalArgumentException e) {
210  0 setName("Error: " + url);
211  0 setPageView(false);
212    }
213    }
214   
215    }