| 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.web.action; |
| 33 |
|
|
| 34 |
|
import net.sourceforge.pebble.Constants; |
| 35 |
|
import net.sourceforge.pebble.domain.Blog; |
| 36 |
|
import net.sourceforge.pebble.logging.Log; |
| 37 |
|
import net.sourceforge.pebble.logging.LogEntry; |
| 38 |
|
import net.sourceforge.pebble.logging.UserAgentConsolidator; |
| 39 |
|
import net.sourceforge.pebble.web.view.View; |
| 40 |
|
import net.sourceforge.pebble.web.view.impl.UserAgentsView; |
| 41 |
|
|
| 42 |
|
import javax.servlet.ServletException; |
| 43 |
|
import javax.servlet.http.HttpServletRequest; |
| 44 |
|
import javax.servlet.http.HttpServletResponse; |
| 45 |
|
import java.util.Comparator; |
| 46 |
|
import java.util.Map; |
| 47 |
|
import java.util.TreeMap; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@author |
| 53 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 8 |
Complexity Density: 0,32 |
|
| 54 |
|
public class ViewUserAgentsAction extends AbstractLogAction { |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
@param |
| 60 |
|
@param |
| 61 |
|
@return |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 4 |
Complexity Density: 0,17 |
|
| 63 |
0
|
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {... |
| 64 |
0
|
Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); |
| 65 |
0
|
Log log = getLog(request, response); |
| 66 |
|
|
| 67 |
0
|
Map<String, Integer> userAgents = new TreeMap<String, Integer>(new Comparator<String>() { |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 68 |
0
|
public int compare(String s1, String s2) {... |
| 69 |
0
|
return s1 != null ? s1.compareToIgnoreCase(s2) : -1; |
| 70 |
|
} |
| 71 |
|
}); |
| 72 |
|
|
| 73 |
0
|
Map<String, Integer> consolidatedUserAgents = new TreeMap<String, Integer>(new Comparator<String>() { |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 74 |
0
|
public int compare(String s1, String s2) {... |
| 75 |
0
|
return s1 != null ? s1.compareToIgnoreCase(s2) : -1; |
| 76 |
|
} |
| 77 |
|
}); |
| 78 |
|
|
| 79 |
0
|
for (LogEntry logEntry : log.getLogEntries()) { |
| 80 |
0
|
String userAgent = logEntry.getAgent(); |
| 81 |
0
|
if (userAgent == null) { |
| 82 |
0
|
userAgent = ""; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
0
|
Integer count = userAgents.get(userAgent); |
| 86 |
0
|
if (count == null) { |
| 87 |
0
|
count = 0; |
| 88 |
|
} |
| 89 |
0
|
count = count+1; |
| 90 |
0
|
userAgents.put(userAgent, count); |
| 91 |
|
|
| 92 |
0
|
String consolidatedUserAgent = UserAgentConsolidator.consolidate(userAgent); |
| 93 |
0
|
Integer consolidatedCount = consolidatedUserAgents.get(consolidatedUserAgent); |
| 94 |
0
|
if (consolidatedCount == null) { |
| 95 |
0
|
consolidatedCount = 0; |
| 96 |
|
} |
| 97 |
0
|
consolidatedCount = consolidatedCount+1; |
| 98 |
0
|
consolidatedUserAgents.put(consolidatedUserAgent, consolidatedCount); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
0
|
getModel().put("logAction", "viewUserAgents"); |
| 102 |
0
|
getModel().put("userAgents", userAgents); |
| 103 |
0
|
getModel().put("consolidatedUserAgents", consolidatedUserAgents); |
| 104 |
|
|
| 105 |
0
|
return new UserAgentsView(); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
} |