| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 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 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public class Request extends CountedUrl { |
| 52 | |
|
| 53 | 4 | private static final Pattern RESPONSES_FEED_REGEX = Pattern.compile("\\/responses\\/.*.xml"); |
| 54 | 4 | private static final Pattern CATEGORY_FEED_REGEX = Pattern.compile("\\/categories\\/.*\\/.*.xml"); |
| 55 | 4 | private static final Pattern TAG_FEED_REGEX = Pattern.compile("\\/tags\\/.*\\/.*.xml"); |
| 56 | 4 | private static final Pattern AUTHOR_FEED_REGEX = Pattern.compile("\\/authors\\/.*\\/.*.xml"); |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public Request(String url) { |
| 64 | 180 | super(url); |
| 65 | 180 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public Request(String url, Blog blog) { |
| 74 | 136 | super(url, blog); |
| 75 | 136 | } |
| 76 | |
|
| 77 | |
protected void setUrl(String url) { |
| 78 | 316 | super.setUrl(url); |
| 79 | |
|
| 80 | 316 | if (url == null || url.length() == 0) { |
| 81 | 20 | setName("None"); |
| 82 | 296 | } else if (RESPONSES_FEED_REGEX.matcher(url).matches()) { |
| 83 | 8 | setName("Feed : Responses"); |
| 84 | 8 | setNewsFeed(true); |
| 85 | 288 | } else if (CATEGORY_FEED_REGEX.matcher(url).matches()) { |
| 86 | 16 | String categoryName = url.substring("/categories/".length(), url.lastIndexOf("/")); |
| 87 | 16 | setName("Feed : category=" + categoryName); |
| 88 | 16 | setNewsFeed(true); |
| 89 | 16 | } else if (TAG_FEED_REGEX.matcher(url).matches()) { |
| 90 | 8 | String tagName = url.substring("/tags/".length(), url.lastIndexOf("/")); |
| 91 | 8 | setName("Feed : tag=" + tagName); |
| 92 | 8 | setNewsFeed(true); |
| 93 | 8 | } else if (AUTHOR_FEED_REGEX.matcher(url).matches()) { |
| 94 | 8 | String authorName = url.substring("/authors/".length(), url.lastIndexOf("/")); |
| 95 | 8 | setName("Feed : author=" + authorName); |
| 96 | 8 | setNewsFeed(true); |
| 97 | 8 | } 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 | 40 | setName("Feed : Blog Entries"); |
| 104 | 40 | setNewsFeed(true); |
| 105 | 216 | } else if (blog != null) { |
| 106 | 96 | if (url.equals("/")) { |
| 107 | 4 | setName("Home"); |
| 108 | 4 | setPageView(true); |
| 109 | 92 | } else if (url.equals("/categories/") || url.equals("/categories")) { |
| 110 | 8 | setName("Categories"); |
| 111 | 8 | setPageView(true); |
| 112 | 84 | } else if (url.equals("/tags/") || url.equals("/tags")) { |
| 113 | 8 | setName("Tags"); |
| 114 | 8 | setPageView(true); |
| 115 | 76 | } else if (url.equals("/files") || (url.startsWith("/files/") && url.endsWith("/"))) { |
| 116 | 8 | setName("Files"); |
| 117 | 8 | setPageView(true); |
| 118 | 68 | } else if (url.startsWith("/categories/")) { |
| 119 | 8 | String categoryName = url.substring("/categories/".length()); |
| 120 | 8 | if (categoryName.endsWith("/")) { |
| 121 | 4 | categoryName = categoryName.substring(0, categoryName.length()-1); |
| 122 | |
} |
| 123 | 8 | setName("Category : " + categoryName); |
| 124 | 8 | setPageView(true); |
| 125 | 8 | } else if (url.startsWith("/tags/")) { |
| 126 | 8 | String tagName = url.substring("/tags/".length()); |
| 127 | 8 | if (tagName.endsWith("/")) { |
| 128 | 4 | tagName = tagName.substring(0, tagName.length()-1); |
| 129 | |
} |
| 130 | 8 | setName("Tag : " + tagName); |
| 131 | 8 | setPageView(true); |
| 132 | 8 | } else if (url.startsWith("/authors/")) { |
| 133 | 8 | String authorName = url.substring("/authors/".length()); |
| 134 | 8 | if (authorName.endsWith("/")) { |
| 135 | 4 | authorName = authorName.substring(0, authorName.length()-1); |
| 136 | |
} |
| 137 | 8 | setName("Author : " + authorName); |
| 138 | 8 | setPageView(true); |
| 139 | 8 | } else if (url.startsWith("/files/")) { |
| 140 | 8 | String fileName = url.substring("/files/".length()); |
| 141 | 8 | if (fileName.endsWith("/")) { |
| 142 | 0 | fileName = fileName.substring(0, fileName.length()-1); |
| 143 | |
} |
| 144 | 8 | setName("File : " + fileName); |
| 145 | 8 | setFileDownload(true); |
| 146 | 8 | } else if (url.startsWith("/pages/")) { |
| 147 | 8 | String pageName = url.substring("/pages/".length()); |
| 148 | 8 | setName("Static Page : " + pageName); |
| 149 | 8 | setPageView(true); |
| 150 | 8 | } else if (url.startsWith("/search.action")) { |
| 151 | 8 | setName("Search"); |
| 152 | 8 | setPageView(true); |
| 153 | 20 | } else if (url.startsWith("/blogentries/")) { |
| 154 | 4 | String pageNumber = url.substring("/blogentries/".length()); |
| 155 | 4 | if (pageNumber.indexOf(".") > -1) { |
| 156 | 4 | pageNumber = pageNumber.substring(0, pageNumber.indexOf(".")); |
| 157 | |
} else { |
| 158 | 0 | pageNumber = "1"; |
| 159 | |
} |
| 160 | 4 | setName("Blog Entries : Page " + pageNumber); |
| 161 | 4 | setPageView(true); |
| 162 | 4 | } else { |
| 163 | 16 | matchOnPermalinkProvider(url, blog.getPermalinkProvider()); |
| 164 | |
|
| 165 | 16 | if (getName() == null) { |
| 166 | |
|
| 167 | 4 | DefaultPermalinkProvider defaultPermalinkProvider = new DefaultPermalinkProvider(); |
| 168 | 4 | defaultPermalinkProvider.setBlog(blog); |
| 169 | 4 | matchOnPermalinkProvider(url, defaultPermalinkProvider); |
| 170 | |
} |
| 171 | |
} |
| 172 | |
} |
| 173 | |
|
| 174 | 316 | if (getName() == null) { |
| 175 | 120 | setName(url); |
| 176 | 120 | setPageView(true); |
| 177 | |
} |
| 178 | 316 | } |
| 179 | |
|
| 180 | |
private void matchOnPermalinkProvider(String url, |
| 181 | |
PermalinkProvider permalinkProvider) { |
| 182 | |
try { |
| 183 | 20 | if (permalinkProvider.isBlogEntryPermalink(url)) { |
| 184 | 12 | BlogEntry blogEntry = permalinkProvider.getBlogEntry(url); |
| 185 | 12 | if (blogEntry != null) { |
| 186 | 8 | setName("Blog Entry : " + blogEntry.getTitle()); |
| 187 | 8 | setPageView(true); |
| 188 | |
} |
| 189 | 12 | } else if (permalinkProvider.isMonthPermalink(url)) { |
| 190 | 4 | Month month = permalinkProvider.getMonth(url); |
| 191 | 4 | SimpleDateFormat formatter = new SimpleDateFormat("MMMM yyyy", blog |
| 192 | |
.getLocale()); |
| 193 | 4 | formatter.setTimeZone(blog.getTimeZone()); |
| 194 | 4 | if (month != null) { |
| 195 | 4 | setName("Month : " + formatter.format(month.getDate())); |
| 196 | 4 | setPageView(true); |
| 197 | |
} |
| 198 | 4 | } else if (permalinkProvider.isDayPermalink(url)) { |
| 199 | 4 | Day day = null; |
| 200 | 4 | day = permalinkProvider.getDay(url); |
| 201 | 4 | SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy", blog |
| 202 | |
.getLocale()); |
| 203 | 4 | formatter.setTimeZone(blog.getTimeZone()); |
| 204 | 4 | if (day != null) { |
| 205 | 4 | setName("Day : " + formatter.format(day.getDate())); |
| 206 | 4 | setPageView(true); |
| 207 | |
} |
| 208 | |
} |
| 209 | 0 | } catch (IllegalArgumentException e) { |
| 210 | 0 | setName("Error: " + url); |
| 211 | 0 | setPageView(false); |
| 212 | 20 | } |
| 213 | 20 | } |
| 214 | |
|
| 215 | |
} |