Map<String,Integer> consolidatedCountries = new HashMap<String,Integer>();
Map<String,Integer> countriesForNewsFeeds = new HashMap<String,Integer>();
Map<String,Integer> countriesForPageViews = new HashMap<String,Integer>();
Map<String,Integer> countriesForFileDownloads = new HashMap<String,Integer>();
LookupService lookupService = null;
try {
String filename = getClass().getResource("/geo-ip.dat").toExternalForm().substring(5);
lookupService = new LookupService(filename, LookupService.GEOIP_MEMORY_CACHE);
for (LogEntry logEntry : log.getLogEntries()) {
String country = lookupService.getCountry(logEntry.getHost()).getName();
countries.add(country);
register(country, countriesForNewsFeeds);
register(country, countriesForPageViews);
register(country, countriesForFileDownloads);
register(country, consolidatedCountries);
Request req = new Request(logEntry.getRequestUri(), blog);
if (req.isNewsFeed()) {
increment(country, countriesForNewsFeeds);
increment(country, consolidatedCountries);
} else if (req.isPageView()) {
increment(country, countriesForPageViews);
increment(country, consolidatedCountries);
} else if (req.isFileDownload()) {
increment(country, countriesForFileDownloads);
increment(country, consolidatedCountries);
}
}
} catch (IOException ioe) {
throw new ServletException(ioe);
} finally {
if (lookupService != null) {
lookupService.close();
}
}
getModel().put("logAction", "viewCountries");
getModel().put("countries", countries);