1 22 23 33 package org.cofax.cds; 34 35 import java.io.*; 36 import java.util.*; 37 38 import javax.servlet.http.*; 39 40 52 53 public class WebBrowser { 54 55 static String dbLocation; 56 57 String userAgent; 58 59 String userAgentToCompare; 60 61 static HashSet searchRobots; 62 63 public WebBrowser(HttpServletRequest req) { 64 65 userAgent = req.getHeader("user-agent"); 66 67 if (userAgent == null) { 68 userAgent = ""; 69 } 70 71 userAgentToCompare = userAgent.toLowerCase().trim(); 72 73 int positionOfSlash = userAgentToCompare.indexOf('/'); 74 if (positionOfSlash > -1) { 75 userAgentToCompare = userAgentToCompare.substring(0, positionOfSlash); 76 } 77 } 78 79 public static void init(String db) { 80 81 dbLocation = db; 82 83 searchRobots = new HashSet(); 84 85 try { 86 BufferedReader r = new BufferedReader(new FileReader(dbLocation)); 87 String l; 88 while ((l = r.readLine()) != null) { 89 90 if (l.length() > 0) { 91 searchRobots.add(l); 92 } 93 } 94 } catch (IOException e) { 95 } 96 97 } 98 99 public boolean isCrawler() { 100 101 if (searchRobots.contains(userAgentToCompare)) { 102 return true; 103 } else { 104 return false; 105 } 106 } 107 108 } 110 | Popular Tags |