|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This report was generated with an evaluation server license. Purchase Clover or configure your license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Referer | Line # 44 | 51 | 0% | 27 | 12 | 85,9% |
0.85882354
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(32) | |||
Result | |||
0.42352942
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForBingSearchUrls
![]() |
1 PASS | |
0.42352942
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForBingSearchUrls
![]() |
1 PASS | |
0.3764706
|
net.sourceforge.pebble.domain.RefererFilterManagerTest.testFilter
![]() |
1 PASS | |
0.3764706
|
net.sourceforge.pebble.domain.RefererFilterManagerTest.testFilter
![]() |
1 PASS | |
0.3764706
|
net.sourceforge.pebble.comparator.CountedUrlComparatorTest.testCompare
![]() |
1 PASS | |
0.3764706
|
net.sourceforge.pebble.comparator.CountedUrlComparatorTest.testCompare
![]() |
1 PASS | |
0.3529412
|
net.sourceforge.pebble.logging.RefererTest.testFakeRefererDoesntBreak
![]() |
1 PASS | |
0.3529412
|
net.sourceforge.pebble.logging.RefererTest.testFakeRefererDoesntBreak
![]() |
1 PASS | |
0.3529412
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForYahooSearchUrls
![]() |
1 PASS | |
0.3529412
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForYahooSearchUrls
![]() |
1 PASS | |
0.32941177
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForGoogleImageSearchUrls
![]() |
1 PASS | |
0.32941177
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForGoogleImageSearchUrls
![]() |
1 PASS | |
0.30588236
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForGoogleSearchUrls
![]() |
1 PASS | |
0.30588236
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForGoogleSearchUrls
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testHashCode
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForJavaBlogsUrls
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testEquals
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testHashCode
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testFriendlyNamesForJavaBlogsUrls
![]() |
1 PASS | |
0.29411766
|
net.sourceforge.pebble.logging.RefererTest.testEquals
![]() |
1 PASS | |
0.28235295
|
net.sourceforge.pebble.logging.RefererTest.testRefererNotInUTF8
![]() |
1 PASS | |
0.28235295
|
net.sourceforge.pebble.logging.RefererTest.testRefererNotInUTF8
![]() |
1 PASS | |
0.27058825
|
net.sourceforge.pebble.logging.RefererTest.testShortUrlIsNotTruncated
![]() |
1 PASS | |
0.27058825
|
net.sourceforge.pebble.logging.RefererTest.testShortUrlIsNotTruncated
![]() |
1 PASS | |
0.27058825
|
net.sourceforge.pebble.logging.RefererTest.testLongUrlIsTruncated
![]() |
1 PASS | |
0.27058825
|
net.sourceforge.pebble.logging.RefererTest.testLongUrlIsTruncated
![]() |
1 PASS | |
0.15294118
|
net.sourceforge.pebble.logging.RefererTest.testDomainFilter
![]() |
1 PASS | |
0.15294118
|
net.sourceforge.pebble.logging.RefererTest.testDomainFilter
![]() |
1 PASS | |
0.08235294
|
net.sourceforge.pebble.logging.RefererTest.testNullUrl
![]() |
1 PASS | |
0.08235294
|
net.sourceforge.pebble.logging.RefererTest.testEmptyUrl
![]() |
1 PASS | |
0.08235294
|
net.sourceforge.pebble.logging.RefererTest.testNullUrl
![]() |
1 PASS | |
0.08235294
|
net.sourceforge.pebble.logging.RefererTest.testEmptyUrl
![]() |
1 PASS | |
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 java.net.URLDecoder; | |
35 | import java.util.regex.Matcher; | |
36 | import java.util.regex.Pattern; | |
37 | ||
38 | /** | |
39 | * Represents a referer URL along with a count of how many times | |
40 | * it has been refered from. | |
41 | * | |
42 | * @author Simon Brown | |
43 | */ | |
44 | public class Referer extends CountedUrl { | |
45 | ||
46 | /** regular expression to pull out the query from a Google referer */ | |
47 | private static final Pattern GOOGLE_QUERY_STRING_PATTERN = Pattern.compile("[?&]q=[^&]+&*"); | |
48 | ||
49 | /** the prefix for all Google referers */ | |
50 | private static final String GOOGLE_PREFIX = "http://www.google."; | |
51 | ||
52 | /** regular expression to pull out the query from a Google referer */ | |
53 | private static final Pattern GOOGLE_IMAGES_QUERY_STRING_PATTERN = Pattern.compile("[?&]prev=[^&]+&*"); | |
54 | ||
55 | /** the prefix for all Google imagesearch referers */ | |
56 | private static final String GOOGLE_IMAGES_PREFIX = "http://images.google."; | |
57 | ||
58 | /** regular expression to pull out the query from a Yahoo! referer */ | |
59 | private static final Pattern YAHOO_QUERY_STRING_PATTERN = Pattern.compile("[?&]p=[^&]+&*"); | |
60 | ||
61 | /** the prefix for all Yahoo! referers */ | |
62 | private static final String YAHOO_PREFIX = "http://search.yahoo."; | |
63 | ||
64 | /** regular expression to pull out the query from an MSN referer */ | |
65 | private static final Pattern MSN_QUERY_STRING_PATTERN = Pattern.compile("[?&]q=[^&]+&*"); | |
66 | ||
67 | /** the prefix for all MSN referers */ | |
68 | private static final String MSN_PREFIX = "http://search.msn."; | |
69 | ||
70 | /** the prefix for all MSN Beta referers */ | |
71 | private static final String MSN_BETA_PREFIX = "http://beta.search.msn."; | |
72 | ||
73 | /** regular expression to pull out the query from an BING referer */ | |
74 | private static final Pattern BING_QUERY_STRING_PATTERN = Pattern.compile("[?&]q=[^&]+&*"); | |
75 | ||
76 | /** the prefix for all BING referers */ | |
77 | private static final String BING_PREFIX = "http://www.bing.com"; | |
78 | ||
79 | /** pattern for java.blogs welcome page referers */ | |
80 | private static final Pattern JAVABLOGS_WELCOME_PATTERN = Pattern.compile(".*javablogs.com/Welcome.*"); | |
81 | ||
82 | /** pattern for java.blogs hot entries page referers */ | |
83 | private static final Pattern JAVABLOGS_HOT_ENTRIES_PATTERN = Pattern.compile(".*javablogs.com/ViewHotBlogEntries.*"); | |
84 | ||
85 | /** | |
86 | * Creates a new instance representing the specified url. | |
87 | * | |
88 | * @param url the url as a String | |
89 | */ | |
90 | 120 |
![]() |
91 | 120 | super(url); |
92 | } | |
93 | ||
94 | 120 |
![]() |
95 | 120 | super.setUrl(url); |
96 | ||
97 | 120 | if (url == null || url.length() == 0) { |
98 | 10 | setName("None"); |
99 | 110 | } else if (url.length() > GOOGLE_PREFIX.length() && |
100 | url.substring(0, GOOGLE_PREFIX.length()).equalsIgnoreCase(GOOGLE_PREFIX)) { | |
101 | ||
102 | 20 | String query = extractQuery(GOOGLE_QUERY_STRING_PATTERN, url); |
103 | 20 | setName("Google : " + query); |
104 | 90 | } else if (url.length() > GOOGLE_IMAGES_PREFIX.length() && |
105 | url.substring(0, GOOGLE_IMAGES_PREFIX.length()).equalsIgnoreCase(GOOGLE_IMAGES_PREFIX)) { | |
106 | ||
107 | 4 | String query = extractQuery(GOOGLE_IMAGES_QUERY_STRING_PATTERN, url); |
108 | 4 | query = extractQuery(GOOGLE_QUERY_STRING_PATTERN, query); |
109 | 4 | setName("Google Images : " + query); |
110 | 86 | } else if (url.length() > YAHOO_PREFIX.length() && |
111 | url.substring(0, YAHOO_PREFIX.length()).equalsIgnoreCase(YAHOO_PREFIX)) { | |
112 | ||
113 | 14 | String query = extractQuery(YAHOO_QUERY_STRING_PATTERN, url); |
114 | 14 | setName("Yahoo! : " + query); |
115 | 72 | } else if (url.length() > MSN_PREFIX.length() && |
116 | url.substring(0, MSN_PREFIX.length()).equalsIgnoreCase(MSN_PREFIX)) { | |
117 | ||
118 | 0 | String query = extractQuery(MSN_QUERY_STRING_PATTERN, url); |
119 | 0 | setName("MSN : " + query); |
120 | 72 | } else if (url.length() > MSN_BETA_PREFIX.length() && |
121 | url.substring(0, MSN_BETA_PREFIX.length()).equalsIgnoreCase(MSN_BETA_PREFIX)) { | |
122 | ||
123 | 0 | String query = extractQuery(MSN_QUERY_STRING_PATTERN, url); |
124 | 0 | setName("MSN beta : " + query); |
125 | 72 | } else if (url.length() >= BING_PREFIX.length() && |
126 | url.substring(0, BING_PREFIX.length()).equalsIgnoreCase(BING_PREFIX)) { | |
127 | ||
128 | 12 | String query = extractQuery(BING_QUERY_STRING_PATTERN, url); |
129 | 12 | setName("Bing : " + query); |
130 | 60 | } else if (JAVABLOGS_WELCOME_PATTERN.matcher(url).matches()) { |
131 | 8 | setName("java.blogs : Welcome"); |
132 | 52 | } else if (JAVABLOGS_HOT_ENTRIES_PATTERN.matcher(url).matches()) { |
133 | 2 | setName("java.blogs : Hot Entries"); |
134 | } else { | |
135 | 50 | setName(url); |
136 | } | |
137 | } | |
138 | ||
139 | 54 |
![]() |
140 | 54 | Matcher m = pattern.matcher(url); |
141 | 54 | String query = ""; |
142 | 54 | if (m.find()) { |
143 | 34 | int start = m.start(); |
144 | 34 | int end = m.end(); |
145 | 34 | query = url.substring(start+3, end); |
146 | 34 | if (query.endsWith("&")) { |
147 | 18 | query = query.substring(0, query.length()-1); |
148 | } | |
149 | 34 | try { |
150 | 34 | query = URLDecoder.decode(query, "UTF-8"); |
151 | } catch (Exception e) { | |
152 | } | |
153 | } | |
154 | ||
155 | 54 | return query; |
156 | } | |
157 | ||
158 | /** | |
159 | * Gets a regex expression that will filter out other referers with the same domain. | |
160 | * | |
161 | * @return a regex as a String | |
162 | */ | |
163 | 4 |
![]() |
164 | // and set the domain name | |
165 | 4 | if (getUrl() == null) { |
166 | 0 | return null; |
167 | } | |
168 | ||
169 | 4 | int index = getUrl().indexOf("://"); |
170 | 4 | if (index == -1) { |
171 | 2 | return getUrl(); |
172 | } | |
173 | ||
174 | 2 | String domainName = getUrl().substring(index+3); |
175 | 2 | index = domainName.indexOf("/"); |
176 | ||
177 | 2 | if (index > -1) { |
178 | 0 | domainName = domainName.substring(0, index); |
179 | } | |
180 | ||
181 | 2 | if (domainName.indexOf(":") > -1) { |
182 | // the domain name still has a port number so remove it | |
183 | 0 | domainName = domainName.substring(0, domainName.indexOf(":")); |
184 | } | |
185 | ||
186 | 2 | return ".*" + domainName + ".*"; |
187 | } | |
188 | ||
189 | } |
|