1 package org.jahia.services.htmlcache; 2 3 11 12 import java.util.Iterator ; 13 import java.util.Set ; 14 import java.util.TreeSet ; 15 16 import org.apache.regexp.RE; 17 import org.apache.regexp.RESyntaxException; 18 import java.util.ArrayList ; 19 20 26 public class UserAgentGroup { 27 28 private static org.apache.log4j.Logger logger = 29 org.apache.log4j.Logger.getLogger (UserAgentGroup.class); 30 31 private String name; 32 private ArrayList regexpList = new ArrayList (); 33 private ArrayList regexpStrings = new ArrayList (); 34 private Set userAgentSet = new TreeSet (); 35 36 49 public UserAgentGroup(String name, ArrayList regexpStrings, Set userAgentSet) { 50 this.name = name; 51 Iterator regexpIter = regexpStrings.iterator(); 52 while (regexpIter.hasNext()) { 53 Object curRegExpObj = regexpIter.next(); 54 if (curRegExpObj instanceof String ) { 55 String curRegExpStr = (String ) curRegExpObj; 56 try { 57 RE curRE = new RE(curRegExpStr); 58 this.regexpList.add(curRE); 59 this.regexpStrings.add(curRegExpStr); 60 } catch (RESyntaxException res) { 61 logger.error("Invalid regular expression syntax : " + 62 curRegExpStr + ", ignoring it..."); 63 } 64 } 65 } 66 Iterator userAgentIter = userAgentSet.iterator(); 67 while (userAgentIter.hasNext()) { 68 Object userAgentObj = userAgentIter.next(); 69 if (userAgentObj instanceof String ) { 70 String userAgentStr = (String ) userAgentObj; 71 this.userAgentSet.add(userAgentStr); 72 } 73 } 74 } 75 76 84 public boolean matchesInsertCriterias(String newUserAgent) { 85 Iterator regexpIter = regexpList.iterator(); 86 while (regexpIter.hasNext()) { 87 RE curRE = (RE) regexpIter.next(); 88 if (curRE.match(newUserAgent)) { 89 return true; 90 } 91 } 92 return false; 93 } 94 95 99 public String getName() { 100 return name; 101 } 102 103 111 public Iterator getRegExpStrings() { 112 return regexpStrings.iterator(); 113 } 114 115 121 public Iterator getUserAgentSetIterator() { 122 return userAgentSet.iterator(); 123 } 124 125 134 public boolean setUserAgent(String newUserAgent) { 135 return userAgentSet.add(newUserAgent); 136 } 137 138 } 139 | Popular Tags |