* added regex extended blacklistengine

* removed my own engines

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4618 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
lulabad 2008-03-30 08:50:09 +00:00
parent 368593e449
commit c4c0d54b22
6 changed files with 116 additions and 636 deletions

View File

@ -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<String, Set<String>> cachedUrlHashs = null;
protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
//protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths_matchable = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
protected HashMap<String, HashMap<String, ArrayList<String>>> 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<String, HashMap<String, ArrayList<String>>>();
//this.hostpaths = new HashMap<String, HashMap<String, ArrayList<String>>>();
this.hostpaths_matchable = new HashMap<String, HashMap<String, ArrayList<String>>>();
this.hostpaths_notmatchable = new HashMap<String, HashMap<String, ArrayList<String>>>();
this.cachedUrlHashs = new HashMap<String, Set<String>>();
Iterator<String> iter = BLACKLIST_TYPES.iterator();
while (iter.hasNext()) {
String blacklistType = (String) iter.next();
this.hostpaths.put(blacklistType, new HashMap<String, ArrayList<String>>());
//this.hostpaths.put(blacklistType, new HashMap<String, ArrayList<String>>());
this.hostpaths_matchable.put(blacklistType, new HashMap<String, ArrayList<String>>());
this.hostpaths_notmatchable.put(blacklistType, new HashMap<String, ArrayList<String>>());
this.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet<String>()));
}
}
@ -84,11 +93,11 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB
this.blacklistRootPath = rootPath;
}
protected HashMap<String, ArrayList<String>> getBlacklistMap(String blacklistType) {
protected HashMap<String, ArrayList<String>> 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<String> getCacheUrlHashsSet(String blacklistType) {
@ -99,24 +108,28 @@ public abstract class indexAbstractReferenceBlacklist implements indexReferenceB
}
public void clear() {
Iterator<HashMap<String, ArrayList<String>>> iter = this.hostpaths.values().iterator();
Iterator<Set<String>> cIter = this.cachedUrlHashs.values().iterator();
while (iter.hasNext()) {
iter.next().clear();
for(HashMap<String, ArrayList<String>> 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<String, ArrayList<String>> entry: this.hostpaths_notmatchable.values()) {
entry.clear();
}
for(Set<String> entry: this.cachedUrlHashs.values()) {
entry.clear();
}
}
public int size() {
int size = 0;
Iterator<String> iter = this.hostpaths.keySet().iterator();
while (iter.hasNext()) {
Iterator<ArrayList<String>> blIter = this.hostpaths.get(iter.next()).values().iterator();
while (blIter.hasNext())
size += blIter.next().size();
for(String entry: this.hostpaths_matchable.keySet()) {
for(ArrayList<String> ientry: this.hostpaths_matchable.get(entry).values()) {
size += ientry.size();
}
}
for(String entry: this.hostpaths_notmatchable.keySet()) {
for(ArrayList<String> 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<String, ArrayList<String>> blacklistMap = getBlacklistMap(blFile.getType());
HashMap<String, ArrayList<String>> blacklistMapMatch = getBlacklistMap(blFile.getType(),true);
HashMap<String, ArrayList<String>> blacklistMapNotMatch = getBlacklistMap(blFile.getType(),false);
Set<Map.Entry<String, ArrayList<String>>> loadedBlacklist;
Map.Entry<String, ArrayList<String>> loadedEntry;
ArrayList<String> 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<String, ArrayList<String>> 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<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType);
HashMap<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType,true);
ArrayList<String> 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<String, ArrayList<String>> 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<String, ArrayList<String>> blacklistMap = getBlacklistMap(blacklistType);
HashMap<String, ArrayList<String>> blacklistMap;
blacklistMap = (isMatchable(host)) ? getBlacklistMap(blacklistType,true) : getBlacklistMap(blacklistType,false);
// avoid PatternSyntaxException e
if(!isMatchable(host) && host.startsWith("*"))
host = "." + host;
ArrayList<String> hostList = blacklistMap.get(host.toLowerCase());
if (hostList == null) blacklistMap.put(host.toLowerCase(), (hostList = new ArrayList<String>()));
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;
}
}

View File

@ -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<result.length; x++) {
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;
}
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;
}
}

View File

@ -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<result.length; x++) {
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;
}
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;
}
}

View File

@ -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<String, ArrayList<String>> blacklistMap = super.getBlacklistMap(blacklistType);
HashMap<String, ArrayList<String>> blacklistMapMatched = super.getBlacklistMap(blacklistType,true);
if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1);
ArrayList<String> 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<String, ArrayList<String>> 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<app.size(); i++) {
if(Pattern.matches(app.get(i), path))
return true;
}
}
} catch (PatternSyntaxException e) {
//System.out.println(e.toString());
}
}
}
return matched;
}
}

View File

@ -1,136 +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;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
import de.anomic.kelondro.kelondroMSetTools;
public class indexRegexReferenceBlacklist extends indexAbstractReferenceBlacklist implements indexReferenceBlacklist {
public indexRegexReferenceBlacklist(File rootPath) {
super(rootPath);
}
public String getEngineInfo() {
return "Regex 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);
ArrayList app;
if (path.length() > 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<app.size(); i++) {
Matcher pathregex = Pattern.compile((String)app.get(i)).matcher(path);
if ((domainregex.matches()) && (pathregex.matches())) return true;
}
} catch (PatternSyntaxException e) {}
}
return false;
}
public void add(String blacklistType, String host, String path) {
if (host == null) throw new NullPointerException();
if (path == null) throw new NullPointerException();
if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1);
StringBuffer sb = new StringBuffer(host);
if(sb.charAt(0) == '*') sb.insert(0,'.');
HashMap<String, ArrayList<String>> blacklistMap = super.getBlacklistMap(blacklistType);
ArrayList<String> hostList = blacklistMap.get(sb.toString().toLowerCase());
if (hostList == null)
blacklistMap.put(sb.toString().toLowerCase(), (hostList = new ArrayList<String>()));
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<String,ArrayList<String>> blacklistMapTmp = new HashMap<String,ArrayList<String>>();
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<app.size(); i++) {
this.add(blacklistType,(String) me.getKey(),(String) app.get(i));
}
}
}
}

View File

@ -1,135 +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;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
import de.anomic.kelondro.kelondroMSetTools;
public class indexRegexWhiteReferenceBlacklist extends indexAbstractReferenceBlacklist implements indexReferenceBlacklist {
public indexRegexWhiteReferenceBlacklist(File rootPath) {
super(rootPath);
}
public String getEngineInfo() {
return "Regex 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);
ArrayList app;
if (path.length() > 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<app.size(); i++) {
Matcher pathregex = Pattern.compile((String)app.get(i)).matcher(path);
if ((domainregex.matches()) && (pathregex.matches())) return false;
}
} catch (PatternSyntaxException e) {}
}
return true;
}
public void add(String blacklistType, String host, String path) {
if (host == null) throw new NullPointerException();
if (path == null) throw new NullPointerException();
if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1);
StringBuffer sb = new StringBuffer(host);
if(sb.charAt(0) == '*') sb.insert(0,'.');
HashMap<String, ArrayList<String>> blacklistMap = super.getBlacklistMap(blacklistType);
ArrayList<String> hostList = blacklistMap.get(sb.toString().toLowerCase());
if (hostList == null)
blacklistMap.put(sb.toString().toLowerCase(), (hostList = new ArrayList<String>()));
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<String,ArrayList<String>> blacklistMapTmp = new HashMap<String,ArrayList<String>>();
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<app.size(); i++) {
this.add(blacklistType,(String) me.getKey(),(String) app.get(i));
}
}
}
}