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
6   45   2   6
2   18   0,33   1
1     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  UserAgentConsolidator       Line # 12 6 0% 2 0 100% 1.0
 
  (2)
 
1    package net.sourceforge.pebble.logging;
2   
3   
4    /**
5    * Consolidate UserAgent String to a short name. This explicitly checks for a
6    * few known snippets from the UserAgent that a browser reports. There's a
7    * number of them missing - these are some of the most common as well as some
8    * ancient ones.
9    *
10    * Extracted from {@link net.sourceforge.pebble.web.action.ViewUserAgentsAction}
11    */
 
12    public class UserAgentConsolidator {
13   
14    /**
15    * UserAgent identifications that are known. Be careful when you add more: they are
16    * supposed to be checked for matches in the order they appear here. So place more
17    * specific names (e.g. containing a version number) at the beginning, more generic
18    * ones at the end.
19    */
20    private static final String[] KNOWN_AGENTS = new String[] { "MSIE 5.0",
21    "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0", "Firefox/1.",
22    "Firefox/2.", "Firefox/3.0", "Firefox/3.5", "Firefox/3.6", "Safari",
23    "Opera", "Chrome", "Bloglines", "Googlebot", "Feedfetcher-Google",
24    "Yahoo! Slurp", "Bing"}; // Are all of these real? Should we remove old ones?
25   
26    /**
27    * Consolidate given user agent to a short name if the agent is recognized,
28    * UserAgentConsolidator.OTHER otherwise.
29    *
30    * @param userAgent
31    * Name that the useragent identifies as
32    * @return short name or UserAgentConsolidator.OTHER
33    */
 
34  22 toggle public static String consolidate(String userAgent) {
35  22 String consolidatedUserAgent = "Other"; // not localized...
36  22 for(String knownAgent : KNOWN_AGENTS) {
37  258 if (userAgent.contains(knownAgent)) {
38  16 consolidatedUserAgent = knownAgent;
39  16 break;
40    }
41    }
42  22 return consolidatedUserAgent;
43    }
44   
45    }