diff --git a/source/de/anomic/index/indexAbstractReferenceBlacklist.java b/source/de/anomic/index/indexAbstractReferenceBlacklist.java index 45e57ea46..8ecd1488e 100644 --- a/source/de/anomic/index/indexAbstractReferenceBlacklist.java +++ b/source/de/anomic/index/indexAbstractReferenceBlacklist.java @@ -37,6 +37,9 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + import de.anomic.kelondro.kelondroMSetTools; import de.anomic.yacy.yacyURL; @@ -54,7 +57,9 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB protected File blacklistRootPath = null; protected HashMap> cachedUrlHashs = null; - protected HashMap>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + //protected HashMap>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + protected HashMap>> hostpaths_matchable = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here + protected HashMap>> hostpaths_notmatchable = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here public indexAbstractReferenceBlacklist(File rootPath) { this.setRootPath(rootPath); @@ -62,13 +67,17 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB this.blacklistRootPath = rootPath; // prepare the data structure - this.hostpaths = new HashMap>>(); + //this.hostpaths = new HashMap>>(); + this.hostpaths_matchable = new HashMap>>(); + this.hostpaths_notmatchable = new HashMap>>(); this.cachedUrlHashs = new HashMap>(); Iterator iter = BLACKLIST_TYPES.iterator(); while (iter.hasNext()) { String blacklistType = (String) iter.next(); - this.hostpaths.put(blacklistType, new HashMap>()); + //this.hostpaths.put(blacklistType, new HashMap>()); + this.hostpaths_matchable.put(blacklistType, new HashMap>()); + this.hostpaths_notmatchable.put(blacklistType, new HashMap>()); this.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet())); } } @@ -84,11 +93,11 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB this.blacklistRootPath = rootPath; } - protected HashMap> getBlacklistMap(String blacklistType) { + protected HashMap> getBlacklistMap(String blacklistType,boolean matchable) { if (blacklistType == null) throw new IllegalArgumentException(); if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown blacklist type: "+blacklistType+"."); - return this.hostpaths.get(blacklistType); + return (matchable)? this.hostpaths_matchable.get(blacklistType) : this.hostpaths_notmatchable.get(blacklistType); } protected Set getCacheUrlHashsSet(String blacklistType) { @@ -99,24 +108,28 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB } public void clear() { - Iterator>> iter = this.hostpaths.values().iterator(); - Iterator> cIter = this.cachedUrlHashs.values().iterator(); - while (iter.hasNext()) { - iter.next().clear(); + for(HashMap> entry: this.hostpaths_matchable.values()) { + entry.clear(); } - while (cIter.hasNext()) { - // clear caches as well to avoid wrong/outdated matches after changing lists - cIter.next().clear(); + for(HashMap> entry: this.hostpaths_notmatchable.values()) { + entry.clear(); + } + for(Set entry: this.cachedUrlHashs.values()) { + entry.clear(); } } public int size() { int size = 0; - Iterator iter = this.hostpaths.keySet().iterator(); - while (iter.hasNext()) { - Iterator> blIter = this.hostpaths.get(iter.next()).values().iterator(); - while (blIter.hasNext()) - size += blIter.next().size(); + for(String entry: this.hostpaths_matchable.keySet()) { + for(ArrayList ientry: this.hostpaths_matchable.get(entry).values()) { + size += ientry.size(); + } + } + for(String entry: this.hostpaths_notmatchable.keySet()) { + for(ArrayList ientry: this.hostpaths_notmatchable.get(entry).values()) { + size += ientry.size(); + } } return size; } @@ -129,7 +142,8 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB } public void loadList(blacklistFile blFile, String sep) { - HashMap> blacklistMap = getBlacklistMap(blFile.getType()); + HashMap> blacklistMapMatch = getBlacklistMap(blFile.getType(),true); + HashMap> blacklistMapNotMatch = getBlacklistMap(blFile.getType(),false); Set>> loadedBlacklist; Map.Entry> loadedEntry; ArrayList paths; @@ -152,9 +166,12 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB // create new entry if host mask unknown, otherwise merge // existing one with path patterns from blacklist file - paths = blacklistMap.get(loadedEntry.getKey()); + paths = (isMatchable(loadedEntry.getKey())) ? blacklistMapMatch.get(loadedEntry.getKey()) : blacklistMapNotMatch.get(loadedEntry.getKey()); if (paths == null) { - blacklistMap.put(loadedEntry.getKey(), loadedPaths); + if(isMatchable(loadedEntry.getKey())) + blacklistMapMatch.put(loadedEntry.getKey(), loadedPaths); + else + blacklistMapNotMatch.put(loadedEntry.getKey(), loadedPaths); } else { // TODO check for duplicates? (refactor List -> Set) paths.addAll(loadedPaths); @@ -172,17 +189,27 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB } public void removeAll(String blacklistType, String host) { - HashMap> blacklistMap = getBlacklistMap(blacklistType); - blacklistMap.remove(host); + getBlacklistMap(blacklistType,true).remove(host); + getBlacklistMap(blacklistType,false).remove(host); } public void remove(String blacklistType, String host, String path) { - HashMap> blacklistMap = getBlacklistMap(blacklistType); + + HashMap> blacklistMap = getBlacklistMap(blacklistType,true); ArrayList hostList = blacklistMap.get(host); - hostList.remove(path); - if (hostList.size() == 0) - blacklistMap.remove(host); - } + if(hostList != null) { + hostList.remove(path); + if (hostList.size() == 0) + blacklistMap.remove(host); + } + HashMap> blacklistMapNotMatch = getBlacklistMap(blacklistType,false); + hostList = blacklistMapNotMatch.get(host); + if(hostList != null) { + hostList.remove(path); + if (hostList.size() == 0) + blacklistMapNotMatch.remove(host); + } +} public void add(String blacklistType, String host, String path) { if (host == null) throw new NullPointerException(); @@ -190,7 +217,13 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); - HashMap> blacklistMap = getBlacklistMap(blacklistType); + HashMap> blacklistMap; + blacklistMap = (isMatchable(host)) ? getBlacklistMap(blacklistType,true) : getBlacklistMap(blacklistType,false); + + // avoid PatternSyntaxException e + if(!isMatchable(host) && host.startsWith("*")) + host = "." + host; + ArrayList hostList = blacklistMap.get(host.toLowerCase()); if (hostList == null) blacklistMap.put(host.toLowerCase(), (hostList = new ArrayList())); hostList.add(path); @@ -223,5 +256,19 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB } return true; } + public static boolean isMatchable (String host) { + try { + if(Pattern.matches("^[a-z0-9.-]*$", host)) // simple Domain (yacy.net or www.yacy.net) + return true; + if(Pattern.matches("^\\*\\.[a-z0-9-.]*$", host)) // start with *. (not .* and * must follow a dot) + return true; + if(Pattern.matches("^[a-z0-9-.]*\\.\\*$", host)) // ends with .* (not *. and befor * must be a dot) + return true; + } catch (PatternSyntaxException e) { + //System.out.println(e.toString()); + return false; + } + return false; + } } diff --git a/source/de/anomic/index/indexAdvancedDefaultReferenceBlacklist.java b/source/de/anomic/index/indexAdvancedDefaultReferenceBlacklist.java deleted file mode 100644 index cbafab195..000000000 --- a/source/de/anomic/index/indexAdvancedDefaultReferenceBlacklist.java +++ /dev/null @@ -1,164 +0,0 @@ -// advancedURLPattern.java -// ----------------------- -// part of YaCy -// (C) by Alexander Fieger webmaster@lulabad.de -// first published on http://www.lulabad.de -// Ingolstadt, Germany, 2006 -// last major change: 12.08.2006 -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Using this software in any meaning (reading, learning, copying, compiling, -// running) means that you agree that the Author(s) is (are) not responsible -// for cost, loss of data or any harm that may be caused directly or indirectly -// by usage of this softare or this documentation. The usage of this software -// is on your own risk. The installation and usage (starting/running) of this -// software may allow other people or application to access your computer and -// any attached devices and is highly dependent on the configuration of the -// software which must be done by the user of the software; the author(s) is -// (are) also not responsible for proper configuration and usage of the -// software, even if provoked by documentation provided together with -// the software. -// -// Any changes to this file according to the GPL as documented in the file -// gpl.txt aside this file in the shipment you received can be done to the -// lines that follows this copyright notice here, but changes must not be -// done inside the copyright notive above. A re-distribution must contain -// the intact and unchanged copyright notice. -// Contributions and changes to the program code must be marked as such. -package de.anomic.index; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - - -public class indexAdvancedDefaultReferenceBlacklist extends indexAbstractReferenceBlacklist implements indexReferenceBlacklist { - - public indexAdvancedDefaultReferenceBlacklist(File rootPath) { - super(rootPath); - } - - public String getEngineInfo() { - return "Advanced YaCy Blacklist Engine by lulabad"; - } - - public boolean isListed(String blacklistType, String hostlow, String path) { - if (hostlow == null) throw new NullPointerException(); - if (path == null) throw new NullPointerException(); - - // getting the proper blacklist - HashMap blacklistMap = super.getBlacklistMap(blacklistType); - if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); - String pp = ""; // path-pattern - - String tmp1 = ""; - String tmp2 = ""; - - ArrayList app; - boolean matched = false; - - String[] result = hostlow.split("\\."); - - for (int x=0; x-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get(result[x] + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + result[x] + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - - tmp1 = tmp1.concat("." + result[x]); - tmp2 = result[result.length-1-x].concat("."+ tmp2); - - - if ((app = (ArrayList) blacklistMap.get(tmp1.substring(1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get("*" + tmp1)) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get(tmp1.substring(1) + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get("*" + tmp1 + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - - - if ((app = (ArrayList) blacklistMap.get(tmp2.substring(0,tmp2.length()-1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + tmp2.substring(0,tmp2.length()-1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get(tmp2 + "*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + tmp2 + "*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return matched; - } - } - return false; - } - -} diff --git a/source/de/anomic/index/indexAdvancedDefaultWhiteReferenceBlacklist.java b/source/de/anomic/index/indexAdvancedDefaultWhiteReferenceBlacklist.java deleted file mode 100644 index 2b3c7d365..000000000 --- a/source/de/anomic/index/indexAdvancedDefaultWhiteReferenceBlacklist.java +++ /dev/null @@ -1,164 +0,0 @@ -// advancedURLPattern.java -// ----------------------- -// part of YaCy -// (C) by Alexander Fieger webmaster@lulabad.de -// first published on http://www.lulabad.de -// Ingolstadt, Germany, 2006 -// last major change: 12.08.2006 -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Using this software in any meaning (reading, learning, copying, compiling, -// running) means that you agree that the Author(s) is (are) not responsible -// for cost, loss of data or any harm that may be caused directly or indirectly -// by usage of this softare or this documentation. The usage of this software -// is on your own risk. The installation and usage (starting/running) of this -// software may allow other people or application to access your computer and -// any attached devices and is highly dependent on the configuration of the -// software which must be done by the user of the software; the author(s) is -// (are) also not responsible for proper configuration and usage of the -// software, even if provoked by documentation provided together with -// the software. -// -// Any changes to this file according to the GPL as documented in the file -// gpl.txt aside this file in the shipment you received can be done to the -// lines that follows this copyright notice here, but changes must not be -// done inside the copyright notive above. A re-distribution must contain -// the intact and unchanged copyright notice. -// Contributions and changes to the program code must be marked as such. -package de.anomic.index; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - - -public class indexAdvancedDefaultWhiteReferenceBlacklist extends indexAbstractReferenceBlacklist implements indexReferenceBlacklist { - - public indexAdvancedDefaultWhiteReferenceBlacklist(File rootPath) { - super(rootPath); - } - - public String getEngineInfo() { - return "Advanced YaCy Whitelist Engine by lulabad"; - } - - public boolean isListed(String blacklistType, String hostlow, String path) { - if (hostlow == null) throw new NullPointerException(); - if (path == null) throw new NullPointerException(); - - // getting the proper blacklist - HashMap blacklistMap = super.getBlacklistMap(blacklistType); - if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); - String pp = ""; // path-pattern - - String tmp1 = ""; - String tmp2 = ""; - - ArrayList app; - boolean matched = true; - - String[] result = hostlow.split("\\."); - - for (int x=0; x-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get(result[x] + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + result[x] + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - - tmp1 = tmp1.concat("." + result[x]); - tmp2 = result[result.length-1-x].concat("."+ tmp2); - - - if ((app = (ArrayList) blacklistMap.get(tmp1.substring(1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get("*" + tmp1)) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get(tmp1.substring(1) + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get("*" + tmp1 + ".*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - - - if ((app = (ArrayList) blacklistMap.get(tmp2.substring(0,tmp2.length()-1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + tmp2.substring(0,tmp2.length()-1))) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get(tmp2 + "*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - if ((app = (ArrayList) blacklistMap.get("*." + tmp2 + "*")) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched ^= ((pp.equals("*")) || (path.matches(pp))); - } - return !matched; - } - } - return true; - } - -} diff --git a/source/de/anomic/index/indexDefaultReferenceBlacklist.java b/source/de/anomic/index/indexDefaultReferenceBlacklist.java index 46d5f03b1..a603ad1dc 100644 --- a/source/de/anomic/index/indexDefaultReferenceBlacklist.java +++ b/source/de/anomic/index/indexDefaultReferenceBlacklist.java @@ -29,6 +29,8 @@ package de.anomic.index; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; public class indexDefaultReferenceBlacklist extends indexAbstractReferenceBlacklist implements indexReferenceBlacklist { @@ -46,18 +48,31 @@ public class indexDefaultReferenceBlacklist extends indexAbstractReferenceBlackl if (path == null) throw new NullPointerException(); // getting the proper blacklist - HashMap> blacklistMap = super.getBlacklistMap(blacklistType); + HashMap> blacklistMapMatched = super.getBlacklistMap(blacklistType,true); if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1); ArrayList app; boolean matched = false; String pp = ""; // path-pattern + // try to match complete domain + if (!matched && (app = blacklistMapMatched.get(hostlow)) != null) { + for (int i=app.size()-1; !matched && i>-1; i--) { + pp = (String)app.get(i); + matched |= ((pp.equals("*")) || (path.matches(pp))); + } + } // first try to match the domain with wildcard '*' // [TL] While "." are found within the string int index = 0; while (!matched && (index = hostlow.indexOf('.', index + 1)) != -1) { - if ((app = blacklistMap.get(hostlow.substring(0, index + 1) + "*")) != null) { + if ((app = blacklistMapMatched.get(hostlow.substring(0, index + 1) + "*")) != null) { + for (int i=app.size()-1; !matched && i>-1; i--) { + pp = (String)app.get(i); + matched |= ((pp.equals("*")) || (path.matches(pp))); + } + } + if ((app = blacklistMapMatched.get(hostlow.substring(0, index))) != null) { for (int i=app.size()-1; !matched && i>-1; i--) { pp = (String)app.get(i); matched |= ((pp.equals("*")) || (path.matches(pp))); @@ -66,7 +81,13 @@ public class indexDefaultReferenceBlacklist extends indexAbstractReferenceBlackl } index = hostlow.length(); while (!matched && (index = hostlow.lastIndexOf('.', index - 1)) != -1) { - if ((app = blacklistMap.get("*" + hostlow.substring(index, hostlow.length()))) != null) { + if ((app = blacklistMapMatched.get("*" + hostlow.substring(index, hostlow.length()))) != null) { + for (int i=app.size()-1; !matched && i>-1; i--) { + pp = (String)app.get(i); + matched |= ((pp.equals("*")) || (path.matches(pp))); + } + } + if ((app = blacklistMapMatched.get(hostlow.substring(index +1, hostlow.length()))) != null) { for (int i=app.size()-1; !matched && i>-1; i--) { pp = (String)app.get(i); matched |= ((pp.equals("*")) || (path.matches(pp))); @@ -74,14 +95,25 @@ public class indexDefaultReferenceBlacklist extends indexAbstractReferenceBlackl } } - // try to match without wildcard in domain - if (!matched && (app = blacklistMap.get(hostlow)) != null) { - for (int i=app.size()-1; !matched && i>-1; i--) { - pp = (String)app.get(i); - matched |= ((pp.equals("*")) || (path.matches(pp))); + + // loop over all Regexentrys + if(!matched) { + HashMap> blacklistMapNotMatched = super.getBlacklistMap(blacklistType,false); + for(String key: blacklistMapNotMatched.keySet()) { + try { + + if(Pattern.matches(key, hostlow)) { + app = blacklistMapNotMatched.get(key); + for (int i=0; i 0 && path.charAt(0) == '/') path = path.substring(1); - - Iterator it = blacklistMap.entrySet().iterator(); - while( it.hasNext() ) { - Map.Entry me = (Map.Entry)it.next(); - try { - Matcher domainregex = Pattern.compile((String)me.getKey()).matcher(hostlow); - app = (ArrayList) me.getValue(); - for (int i=0; i 0 && path.charAt(0) == '/') path = path.substring(1); - - StringBuffer sb = new StringBuffer(host); - if(sb.charAt(0) == '*') sb.insert(0,'.'); - - - HashMap> blacklistMap = super.getBlacklistMap(blacklistType); - ArrayList hostList = blacklistMap.get(sb.toString().toLowerCase()); - if (hostList == null) - blacklistMap.put(sb.toString().toLowerCase(), (hostList = new ArrayList())); - hostList.add(path); - - - } - public void remove(String blacklistType, String host, String path) { - StringBuffer sb = new StringBuffer(host); - if(sb.charAt(0) == '*') sb.insert(0,'.'); - - HashMap blacklistMap = getBlacklistMap(blacklistType); - ArrayList hostList = (ArrayList)blacklistMap.get(sb.toString()); - hostList.remove(path); - if (hostList.size() == 0) - blacklistMap.remove(sb.toString()); - } - public void loadList(String blacklistType, String filenames, String sep) { - - HashMap> blacklistMapTmp = new HashMap>(); - String[] filenamesarray = filenames.split(","); - - if( filenamesarray.length > 0) { - for (int i = 0; i < filenamesarray.length; i++) { - blacklistMapTmp.putAll(kelondroMSetTools.loadMapMultiValsPerKey(new File(this.blacklistRootPath, filenamesarray[i]).toString(), sep)); - } - } - Iterator it = blacklistMapTmp.entrySet().iterator(); - ArrayList app; - while( it.hasNext() ) { - Map.Entry me = (Map.Entry)it.next(); - app = (ArrayList) me.getValue(); - for (int i=0; i 0 && path.charAt(0) == '/') path = path.substring(1); - - Iterator it = blacklistMap.entrySet().iterator(); - while( it.hasNext() ) { - Map.Entry me = (Map.Entry)it.next(); - try { - Matcher domainregex = Pattern.compile((String)me.getKey()).matcher(hostlow); - app = (ArrayList) me.getValue(); - for (int i=0; i 0 && path.charAt(0) == '/') path = path.substring(1); - - StringBuffer sb = new StringBuffer(host); - if(sb.charAt(0) == '*') sb.insert(0,'.'); - - - HashMap> blacklistMap = super.getBlacklistMap(blacklistType); - ArrayList hostList = blacklistMap.get(sb.toString().toLowerCase()); - if (hostList == null) - blacklistMap.put(sb.toString().toLowerCase(), (hostList = new ArrayList())); - hostList.add(path); - } - public void remove(String blacklistType, String host, String path) { - StringBuffer sb = new StringBuffer(host); - if(sb.charAt(0) == '*') sb.insert(0,'.'); - - HashMap blacklistMap = getBlacklistMap(blacklistType); - ArrayList hostList = (ArrayList)blacklistMap.get(sb.toString()); - if(hostList != null) - hostList.remove(path); - if (hostList.size() == 0) - blacklistMap.remove(sb.toString()); - } - public void loadList(String blacklistType, String filenames, String sep) { - - HashMap> blacklistMapTmp = new HashMap>(); - String[] filenamesarray = filenames.split(","); - - if( filenamesarray.length > 0) { - for (int i = 0; i < filenamesarray.length; i++) { - blacklistMapTmp.putAll(kelondroMSetTools.loadMapMultiValsPerKey(new File(this.blacklistRootPath, filenamesarray[i]).toString(), sep)); - } - } - Iterator it = blacklistMapTmp.entrySet().iterator(); - ArrayList app; - while( it.hasNext() ) { - Map.Entry me = (Map.Entry)it.next(); - app = (ArrayList) me.getValue(); - for (int i=0; i