Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) adding missing classes
theli95a84ae469c6
diff --git a/source/de/anomic/plasma/parser/sevenZip/sevenZipParser.java b/source/de/anomic/plasma/parser/sevenZip/sevenZipParser.javanew file mode 100644index 000000000..9d42e114f--- /dev/null+++ b/source/de/anomic/plasma/parser/sevenZip/sevenZipParser.java@@ -0,0 +1,126 @@+//gzipParser.java+//------------------------+//part of YaCy+//(C) by Michael Peter Christen; [email protected]+//first published on http://www.anomic.de+//Frankfurt, Germany, 2005+//+//this file is contributed by Martin Thelian+//last major change: 24.04.2005+//+//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.plasma.parser.sevenZip;++import java.io.File;+import java.io.FileOutputStream;+import java.io.InputStream;+import java.net.URL;+import java.util.Hashtable;++import LZMA.LzmaInputStream;++import de.anomic.plasma.plasmaParser;+import de.anomic.plasma.plasmaParserDocument;+import de.anomic.plasma.parser.AbstractParser;+import de.anomic.plasma.parser.Parser;+import de.anomic.plasma.parser.ParserException;++public class sevenZipParser extends AbstractParser implements Parser {++ /**+ * a list of mime types that are supported by this parser class+ * @see #getSupportedMimeTypes()+ */+ public static final Hashtable SUPPORTED_MIME_TYPES = new Hashtable();+ static {+ SUPPORTED_MIME_TYPES.put("application/x-7z-compressed","7z,t7z");+ }++ /**+ * a list of library names that are needed by this parser+ * @see Parser#getLibxDependences()+ */+ private static final String[] LIBX_DEPENDENCIES = new String[] {"JLzma.jar"};++ public sevenZipParser() {+ super(LIBX_DEPENDENCIES);+ parserName = "7-Zip Compressed Archive Parser";+ }++ public Hashtable getSupportedMimeTypes() {+ return SUPPORTED_MIME_TYPES;+ }++ public plasmaParserDocument parse(URL location, String mimeType, InputStream source) throws ParserException {++ File tempFile = null;+ try {+ int read = 0;+ byte[] data = new byte[1024];+++ LzmaInputStream zippedContent = new LzmaInputStream(source);++ tempFile = File.createTempFile("sevenzip","tmp");+ tempFile.deleteOnExit();++ // creating a temp file to store the uncompressed data+ FileOutputStream out = new FileOutputStream(tempFile);++ // reading gzip file and store it uncompressed+ while((read = zippedContent.read(data, 0, 1024)) != -1) {+ out.write(data, 0, read);+ }+ zippedContent.close();+ out.close();++ // creating a new parser class to parse the unzipped content+ plasmaParser theParser = new plasmaParser();+ return theParser.parseSource(location,null,tempFile);+ } catch (Exception e) {+ throw new ParserException("Unable to parse the 7Zip content. " + e.getMessage());+ } catch (Error e) {+ e.printStackTrace();+ throw new ParserException("Unable to parse the 7Zip content. " + e.getMessage());+ } finally {+ if (tempFile != null) tempFile.delete();+ }+ }++ public void reset() {+ // Nothing todo here at the moment++ }+}diff --git a/source/de/anomic/plasma/urlPattern/abstractURLPattern.java b/source/de/anomic/plasma/urlPattern/abstractURLPattern.javanew file mode 100644index 000000000..f9345a8fd--- /dev/null+++ b/source/de/anomic/plasma/urlPattern/abstractURLPattern.java@@ -0,0 +1,157 @@+package de.anomic.plasma.urlPattern;++import java.io.File;+import java.util.Arrays;+import java.util.Collections;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Iterator;+import java.util.Set;++import de.anomic.kelondro.kelondroMSetTools;+import de.anomic.net.URL;++public abstract class abstractURLPattern implements plasmaURLPattern {++ protected static final HashSet BLACKLIST_TYPES = new HashSet(Arrays.asList(new String[]{+ plasmaURLPattern.BLACKLIST_CRAWLER,+ plasmaURLPattern.BLACKLIST_PROXY,+ plasmaURLPattern.BLACKLIST_DHT,+ plasmaURLPattern.BLACKLIST_SEARCH+ }));++ 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+++ public abstractURLPattern(File rootPath) {+ this.setRootPath(rootPath);++ this.blacklistRootPath = rootPath;++ // prepare the data structure+ this.hostpaths = 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.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet()));+ }+ }++ public void setRootPath(File rootPath) {+ if (rootPath == null)+ throw new NullPointerException("The blacklist root path must not be null.");+ if (!rootPath.isDirectory())+ throw new IllegalArgumentException("The blacklist root path is not a directory.");+ if (!rootPath.canRead())+ throw new IllegalArgumentException("The blacklist root path is not readable.");++ this.blacklistRootPath = rootPath;+ }++ protected HashMap geBlacklistMap(String blacklistType) {+ if (blacklistType == null) throw new IllegalArgumentException();+ if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown backlist type.");++ return (HashMap) this.hostpaths.get(blacklistType);+ }++ protected Set getCacheUrlHashsSet(String blacklistType) {+ if (blacklistType == null) throw new IllegalArgumentException();+ if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown backlist type.");++ return (Set) this.cachedUrlHashs.get(blacklistType);+ }++ public void clear() {+ Iterator iter = this.hostpaths.keySet().iterator();+ while (iter.hasNext()) {+ HashMap blacklistMap = (HashMap) this.hostpaths.get(iter.next());+ blacklistMap.clear();+ }+ }++ public int size() {+ int size = 0;+ Iterator iter = this.hostpaths.keySet().iterator();+ while (iter.hasNext()) {+ HashMap blacklistMap = (HashMap) this.hostpaths.get(iter.next());+ size += blacklistMap.size();+ }+ return size;+ }++ public void loadList(String[][] filenames, String sep) {+ for (int j = 0; j < filenames.length; j++) {+ String[] nextFile = filenames[j];+ String blacklistType = nextFile[0];+ String fileName = nextFile[1];+ this.loadList(blacklistType, fileName, sep);+ }+ }++ public void loadList(String blacklistType, String filenames, String sep) {++ HashMap blacklistMap = geBlacklistMap(blacklistType);+ String[] filenamesarray = filenames.split(",");++ if( filenamesarray.length > 0) {+ for (int i = 0; i < filenamesarray.length; i++) {+ blacklistMap.putAll(kelondroMSetTools.loadMap(new File(this.blacklistRootPath, filenamesarray[i]).toString(), sep));+ }+ }+ }++ public void remove(String blacklistType, String host) {++ HashMap blacklistMap = geBlacklistMap(blacklistType);+ blacklistMap.remove(host);+ }++ 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);++ HashMap blacklistMap = geBlacklistMap(blacklistType);+ blacklistMap.put(host.toLowerCase(), path);+ }++ public int blacklistCacheSize() {+ int size = 0;+ Iterator iter = this.cachedUrlHashs.keySet().iterator();+ while (iter.hasNext()) {+ Set blacklistMap = (Set) this.cachedUrlHashs.get(iter.next());+ size += blacklistMap.size();+ }+ return size;+ }++ public boolean hashInBlacklistedCache(String blacklistType, String urlHash) {+ Set urlHashCache = getCacheUrlHashsSet(blacklistType);+ return urlHashCache.contains(urlHash);+ }++ public boolean isListed(String blacklistType, String urlHash, URL url) {++ Set urlHashCache = getCacheUrlHashsSet(blacklistType);+ if (!urlHashCache.contains(urlHash)) {+ boolean temp = isListed(blacklistType, url.getHost().toLowerCase(), url.getFile());+ if (temp) {+ urlHashCache.add(urlHash);+ }+ return temp;+ }+ return true;+ }++ public boolean isListed(String blacklistType, URL url) {+ return isListed(blacklistType, url.getHost().toLowerCase(), url.getFile());+ }++}diff --git a/source/de/anomic/plasma/urlPattern/defaultURLPattern.java b/source/de/anomic/plasma/urlPattern/defaultURLPattern.javanew file mode 100644index 000000000..c1c61b5da--- /dev/null+++ b/source/de/anomic/plasma/urlPattern/defaultURLPattern.java@@ -0,0 +1,87 @@+// plasmaURLPattern.java+// -----------------------+// part of YaCy+// (C) by Michael Peter Christen; [email protected]+// first published on http://www.anomic.de+// Frankfurt, Germany, 2005+// last major change: 11.07.2005+//+// 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.plasma.urlPattern;++import java.io.File;+import java.util.HashMap;+++public class defaultURLPattern extends abstractURLPattern implements plasmaURLPattern {++ public defaultURLPattern(File rootPath) {+ super(rootPath);+ }++ public String getEngineInfo() {+ return "Default YaCy Blacklist Engine";+ }++ 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.geBlacklistMap(blacklistType);++ if (path.length() > 0 && path.charAt(0) == '/') path = path.substring(1);+ String pp = ""; // path-pattern++ // first try to match the domain with wildcard '*'+ // [TL] While "." are found within the string+ int index = 0;+ while ((index = hostlow.indexOf('.', index + 1)) != -1) {+ if ((pp = (String) blacklistMap.get(hostlow.substring(0, index + 1) + "*")) != null) {+ return ((pp.equals("*")) || (path.matches(pp)));+ }+ }+ index = hostlow.length();+ while ((index = hostlow.lastIndexOf('.', index - 1)) != -1) {+ if ((pp = (String) blacklistMap.get("*" + hostlow.substring(index, hostlow.length()))) != null) {+ return ((pp.equals("*")) || (path.matches(pp)));+ }+ }++ // try to match without wildcard in domain+ return (((pp = (String) blacklistMap.get(hostlow)) != null) &&+ ((pp.equals("*")) || (path.matches(pp))));+ }+}diff --git a/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java b/source/de/anomic/plasma/urlPattern/plasmaURLPattern.javanew file mode 100644index 000000000..fcacb1e3f--- /dev/null+++ b/source/de/anomic/plasma/urlPattern/plasmaURLPattern.java@@ -0,0 +1,40 @@+package de.anomic.plasma.urlPattern;++import java.io.File;++import de.anomic.net.URL;++public interface plasmaURLPattern {++ public static final String BLACKLIST_DHT = "dht";+ public static final String BLACKLIST_CRAWLER = "crawler";+ public static final String BLACKLIST_PROXY = "proxy";+ public static final String BLACKLIST_SEARCH = "search";+++ public String getEngineInfo();++ public void setRootPath(File rootPath);++ public int blacklistCacheSize();++ public int size();++ public void clear();+ public void remove(String blacklistType, String host);+ public void add(String blacklistType, String host, String path);+++ public void loadList(String blacklistType, String filenames, String sep);+ public void loadList(String[][] filenames, String sep);+++ public boolean hashInBlacklistedCache(String blacklistType, String urlHash);++ public boolean isListed(String blacklistType, String urlHash, URL url);++ public boolean isListed(String blacklistType, URL url);++ public boolean isListed(String blacklistType, String hostlow, String path);++}