Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
refactoring of parsers and document processing
orbiterdafffd0153dd
diff --git a/debian/changelog b/debian/changelogindex a507b234d..fc54839a7 100644--- a/debian/changelog+++ b/debian/changelog@@ -1,4 +1,4 @@-yacy (*auto-svn-version*) unstable; urgency=low+yacy (0.91svn6172) unstable; urgency=low* SVN Updatediff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.javaindex 9907adecd..f8ac12866 100644--- a/htroot/Bookmarks.java+++ b/htroot/Bookmarks.java@@ -40,10 +40,10 @@ import de.anomic.data.bookmarksDB;import de.anomic.data.listManager;import de.anomic.data.userDB;import de.anomic.data.bookmarksDB.Tag;+import de.anomic.document.Document;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;import de.anomic.kelondro.util.DateFormatter;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaSnippetCache;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverObjects;@@ -184,7 +184,7 @@ public class Bookmarks {if (bookmark == null) {// try to get the bookmark from the LURL databasefinal URLMetadataRow urlentry = sb.indexSegment.urlMetadata().load(urlHash, null, 0);- plasmaParserDocument document = null;+ Document document = null;if (urlentry != null) {final URLMetadataRow.Components metadata = urlentry.metadata();document = plasmaSnippetCache.retrieveDocument(metadata.url(), true, 5000, true, false);diff --git a/htroot/Connections_p.java b/htroot/Connections_p.javaindex 4969dc41d..66f871c02 100644--- a/htroot/Connections_p.java+++ b/htroot/Connections_p.java@@ -45,8 +45,8 @@ import de.anomic.server.serverHandler;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.server.serverThread;+import de.anomic.server.urlRedirectord;import de.anomic.server.serverCore.Session;-import de.anomic.urlRedirector.urlRedirectord;import de.anomic.yacy.yacySeed;public final class Connections_p {diff --git a/htroot/FeedReader_p.java b/htroot/FeedReader_p.javaindex 45cc1defa..99122866a 100644--- a/htroot/FeedReader_p.java+++ b/htroot/FeedReader_p.java@@ -25,12 +25,12 @@ import java.io.IOException;import java.net.MalformedURLException;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;+import de.anomic.document.parser.xml.RSSReader;import de.anomic.http.httpRequestHeader;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.server.servletProperties;-import de.anomic.xml.RSSFeed;-import de.anomic.xml.RSSReader;import de.anomic.yacy.yacyURL;// test url:diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.javaindex 90b5d9150..0b114645a 100644--- a/htroot/IndexControlRWIs_p.java+++ b/htroot/IndexControlRWIs_p.java@@ -39,6 +39,8 @@ import java.util.Set;import de.anomic.data.AbstractBlacklist;import de.anomic.data.Blacklist;import de.anomic.data.listManager;+import de.anomic.document.Condenser;+import de.anomic.document.Word;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.text.Reference;@@ -52,8 +54,6 @@ import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSearchEvent;import de.anomic.plasma.plasmaSearchRankingProcess;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Condenser;-import de.anomic.plasma.parser.Word;import de.anomic.search.Query;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;diff --git a/htroot/LogStatistics_p.java b/htroot/LogStatistics_p.javaindex 190d5f8df..b4e3f4df6 100644--- a/htroot/LogStatistics_p.java+++ b/htroot/LogStatistics_p.java@@ -28,14 +28,11 @@import java.util.HashSet;import java.util.Hashtable;-import java.util.logging.Handler;-import java.util.logging.Logger;import de.anomic.http.httpRequestHeader;-import de.anomic.plasma.LogParser;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.yacy.logging.LogalizerHandler;+import de.anomic.yacy.logging.LogParser;public class LogStatistics_p {@@ -45,21 +42,9 @@ public class LogStatistics_p {public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch env) {final serverObjects prop = new serverObjects();- final Logger logger = Logger.getLogger("");---- final Handler[] handlers = logger.getHandlers();+Hashtable<String, Object> r = null;boolean displaySubmenu = false;- for (int i=0; i<handlers.length; i++) {- if (handlers[i] instanceof LogalizerHandler) {- displaySubmenu = true;- final LogalizerHandler h = ((LogalizerHandler)handlers[i]);- r = h.getParserResults(h.getParser(0));- if (r != null) break;- }- }prop.put("submenu", displaySubmenu ? "1" : "0");diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.javaindex d0996bc6a..d995e9e53 100644--- a/htroot/SettingsAck_p.java+++ b/htroot/SettingsAck_p.java@@ -38,6 +38,7 @@ import java.util.StringTokenizer;import java.util.regex.Pattern;import java.util.regex.PatternSyntaxException;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpRemoteProxyConfig;import de.anomic.http.httpd;@@ -45,7 +46,6 @@ import de.anomic.http.httpdProxyHandler;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.Digest;import de.anomic.kelondro.util.DateFormatter;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;@@ -458,8 +458,8 @@ public class SettingsAck_p {*/if (post.containsKey("parserSettings")) {post.remove("parserSettings");-- final Set<String> parserModes = plasmaParser.getParserConfigList().keySet();+ /*+ final Set<String> parserModes = ParserDispatcher.getParserConfigList().keySet();final HashMap<String, HashSet<String>> newConfigList = new HashMap<String, HashSet<String>>();Iterator<String> parserModeIter = parserModes.iterator();while (parserModeIter.hasNext()) {@@ -489,7 +489,7 @@ public class SettingsAck_p {parserModeIter = newConfigList.keySet().iterator();while (parserModeIter.hasNext()) {final String currParserMode = parserModeIter.next();- final String[] enabledMimes = plasmaParser.setEnabledParserList(currParserMode, newConfigList.get(currParserMode));+ final String[] enabledMimes = ParserDispatcher.setEnabledParserList(newConfigList.get(currParserMode));Arrays.sort(enabledMimes);currEnabledMimesTxt.setLength(0);@@ -505,7 +505,7 @@ public class SettingsAck_p {prop.put("info_parser",enabledMimesCount);prop.put("info", "18");return prop;-+ */}// Crawler settingsdiff --git a/htroot/Settings_p.java b/htroot/Settings_p.javaindex 493685a57..2dbf77d95 100644--- a/htroot/Settings_p.java+++ b/htroot/Settings_p.java@@ -29,12 +29,11 @@ import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserConfig;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;-import de.anomic.plasma.plasmaParser;-import de.anomic.plasma.plasmaParserConfig;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.ParserInfo;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.yacy.yacyCore;@@ -218,11 +217,11 @@ public final class Settings_p {/** Parser Configuration*/-- final HashMap<String, plasmaParserConfig> configList = plasmaParser.getParserConfigList();+ /*+ final HashMap<String, plasmaParserConfig> configList = ParserDispatcher.getParserConfigList();final plasmaParserConfig[] configArray = configList.values().toArray(new plasmaParserConfig[configList.size()]);- final HashSet<ParserInfo> parserInfos = new HashSet<ParserInfo>(sb.parser.getAvailableParserList().values());+ final HashSet<ParserInfo> parserInfos = new HashSet<ParserInfo>(ParserDispatcher.getAvailableParserList().values());// // fetching a list of all available mimetypes// List availableParserKeys = Arrays.asList(availableParsers.entrySet().toArray(new ParserInfo[availableParsers.size()]));@@ -273,7 +272,7 @@ public final class Settings_p {prop.put("parserMode",configArray.length);prop.put("parser", parserIdx);prop.put("parser.colspan", configArray.length+2);-+ */// Crawler settingsprop.putHTML("crawler.clientTimeout",sb.getConfig("crawler.clientTimeout", "10000"));prop.putHTML("crawler.http.maxFileSize",sb.getConfig("crawler.http.maxFileSize", "-1"));diff --git a/htroot/Threaddump_p.java b/htroot/Threaddump_p.javaindex 4ecbfab6c..c687b5518 100644--- a/htroot/Threaddump_p.java+++ b/htroot/Threaddump_p.java@@ -37,7 +37,7 @@ import java.util.Map.Entry;import java.util.ArrayList;import java.util.HashMap;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;@@ -202,7 +202,7 @@ public class Threaddump_p {className = ste.getClassName();if (cutcore && (className.startsWith("java.") || className.startsWith("sun."))) {sb.setLength(0);- bufferappend(sb, plain, tracename + "at " + htmlFilterCharacterCoding.unicode2html(ste.toString(), true));+ bufferappend(sb, plain, tracename + "at " + CharacterCoding.unicode2html(ste.toString(), true));} else {cutcore = false;if (i == 0) {@@ -211,9 +211,9 @@ public class Threaddump_p {line = null;}if ((line != null) && (line.length() > 0)) {- bufferappend(sb, plain, tracename + "at " + htmlFilterCharacterCoding.unicode2html(ste.toString(), true) + " [" + line.trim() + "]");+ bufferappend(sb, plain, tracename + "at " + CharacterCoding.unicode2html(ste.toString(), true) + " [" + line.trim() + "]");} else {- bufferappend(sb, plain, tracename + "at " + htmlFilterCharacterCoding.unicode2html(ste.toString(), true));+ bufferappend(sb, plain, tracename + "at " + CharacterCoding.unicode2html(ste.toString(), true));}}}diff --git a/htroot/ViewFile.java b/htroot/ViewFile.javaindex fb184d434..5e37ff69c 100644--- a/htroot/ViewFile.java+++ b/htroot/ViewFile.java@@ -34,20 +34,20 @@ import java.util.HashMap;import java.util.Iterator;import java.util.Map;-import de.anomic.htmlFilter.htmlFilterImageEntry;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.Condenser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.document.parser.html.CharacterCoding;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.http.httpClient;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpResponseHeader;+import de.anomic.http.httpDocument;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaSnippetCache;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;-import de.anomic.plasma.parser.ParserException;-import de.anomic.plasma.parser.Condenser;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.yacy.yacyURL;@@ -152,7 +152,7 @@ public class ViewFile {// if the resource body was not cached we try to load it from webif (resource == null) {- Document entry = null;+ httpDocument entry = null;try {entry = sb.crawlQueues.loadResourceFromWeb(url, true, false);} catch (final Exception e) {@@ -239,7 +239,7 @@ public class ViewFile {} else if (viewMode.equals("parsed") || viewMode.equals("sentences") || viewMode.equals("words") || viewMode.equals("links")) {// parsing the resource content- plasmaParserDocument document = null;+ Document document = null;try {document = plasmaSnippetCache.parseDocument(url, resourceLength, resource);if (document == null) {@@ -329,9 +329,9 @@ public class ViewFile {i += putMediaInfo(prop, wordArray, i, document.getAudiolinks(), "audio", (i % 2 == 0));dark = (i % 2 == 0);- final HashMap<String, htmlFilterImageEntry> ts = document.getImages();- final Iterator<htmlFilterImageEntry> tsi = ts.values().iterator();- htmlFilterImageEntry entry;+ final HashMap<String, ImageEntry> ts = document.getImages();+ final Iterator<ImageEntry> tsi = ts.values().iterator();+ ImageEntry entry;while (tsi.hasNext()) {entry = tsi.next();prop.put("viewMode_links_" + i + "_nr", i);@@ -376,7 +376,7 @@ public class ViewFile {}private static final String markup(final String[] wordArray, String message) {- message = htmlFilterCharacterCoding.unicode2html(message, true);+ message = CharacterCoding.unicode2html(message, true);if (wordArray != null)for (int j = 0; j < wordArray.length; j++) {final String currentWord = wordArray[j].trim();diff --git a/htroot/WatchCrawler_p.java b/htroot/WatchCrawler_p.javaindex 792034c92..43dafe1ec 100644--- a/htroot/WatchCrawler_p.java+++ b/htroot/WatchCrawler_p.java@@ -42,8 +42,8 @@ import de.anomic.crawler.SitemapImporter;import de.anomic.crawler.ZURL;import de.anomic.data.bookmarksDB;import de.anomic.data.listManager;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterWriter;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.TransformerWriter;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaSwitchboard;@@ -325,9 +325,9 @@ public class WatchCrawler_p {final String fileString = post.get("crawlingFile$file");// parsing the bookmark file and fetching the headline and contained links- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL(file));+ final ContentScraper scraper = new ContentScraper(new yacyURL(file));//OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- final Writer writer = new htmlFilterWriter(null,null,scraper,null,false);+ final Writer writer = new TransformerWriter(null,null,scraper,null,false);FileUtils.copy(fileString, writer);writer.close();diff --git a/htroot/api/bookmarks/get_bookmarks.java b/htroot/api/bookmarks/get_bookmarks.javaindex 6595c6aae..46f0300d3 100644--- a/htroot/api/bookmarks/get_bookmarks.java+++ b/htroot/api/bookmarks/get_bookmarks.java@@ -5,7 +5,7 @@ import java.util.Iterator;import de.anomic.data.bookmarksDB;import de.anomic.data.userDB;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;@@ -205,7 +205,7 @@ public class get_bookmarks {count++;final String title = fn; // just to make sure fn stays untouched- prop.put("display_xbel_"+count+"_elements", "<title>" + htmlFilterCharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");+ prop.put("display_xbel_"+count+"_elements", "<title>" + CharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");count++;final Iterator<String> bit=sb.bookmarksDB.getBookmarksIterator(fn, isAdmin);count = print_XBEL(bit, count);@@ -231,8 +231,8 @@ public class get_bookmarks {bookmark=sb.bookmarksDB.getBookmark(bit.next());date=new Date(bookmark.getTimeStamp());prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()- + "\" href=\"" + htmlFilterCharacterCoding.unicode2xml(bookmark.getUrl(), true)- + "\" added=\"" + htmlFilterCharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");+ + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)+ + "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");count++;prop.put("display_xbel_"+count+"_elements", "<title>");count++;@@ -243,7 +243,7 @@ public class get_bookmarks {prop.put("display_xbel_"+count+"_elements", "<info>");count++;prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""- + htmlFilterCharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ "\"/>");count++;prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");diff --git a/htroot/api/bookmarks/xbel/xbel.java b/htroot/api/bookmarks/xbel/xbel.javaindex 7b1174e64..515b1ed72 100755--- a/htroot/api/bookmarks/xbel/xbel.java+++ b/htroot/api/bookmarks/xbel/xbel.java@@ -4,7 +4,7 @@ import java.util.Date;import java.util.Iterator;import de.anomic.data.bookmarksDB;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;@@ -83,7 +83,7 @@ public class xbel {count++;final String title = fn; // just to make sure fn stays untouched- prop.put("xbel_"+count+"_elements", "<title>" + htmlFilterCharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");+ prop.put("xbel_"+count+"_elements", "<title>" + CharacterCoding.unicode2xml(title.replaceAll("(/.[^/]*)*/", ""), true) + "</title>");count++;final Iterator<String> bit=switchboard.bookmarksDB.getBookmarksIterator(fn, isAdmin);count = print_XBEL(bit, count);@@ -108,8 +108,8 @@ public class xbel {bookmark=switchboard.bookmarksDB.getBookmark(bit.next());date=new Date(bookmark.getTimeStamp());prop.put("xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()- + "\" href=\"" + htmlFilterCharacterCoding.unicode2xml(bookmark.getUrl(), true)- + "\" added=\"" + htmlFilterCharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");+ + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)+ + "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");count++;prop.put("xbel_"+count+"_elements", "<title>");count++;@@ -120,7 +120,7 @@ public class xbel {prop.put("xbel_"+count+"_elements", "<info>");count++;prop.put("xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""- + htmlFilterCharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ "\"/>");count++;prop.put("xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");diff --git a/htroot/api/feed.java b/htroot/api/feed.javaindex c1bfdefb0..9b354221a 100755--- a/htroot/api/feed.java+++ b/htroot/api/feed.java@@ -3,11 +3,11 @@import java.util.Date;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpRequestHeader;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.xml.RSSFeed;public class feed {diff --git a/htroot/api/timeline.java b/htroot/api/timeline.javaindex 553f5ff84..a5b7c653e 100644--- a/htroot/api/timeline.java+++ b/htroot/api/timeline.java@@ -28,6 +28,7 @@ import java.util.Date;import java.util.Iterator;import java.util.TreeSet;+import de.anomic.document.Word;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.text.ReferenceContainer;import de.anomic.kelondro.text.Segment;@@ -35,7 +36,6 @@ import de.anomic.kelondro.text.TermSearch;import de.anomic.kelondro.text.referencePrototype.WordReference;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Word;import de.anomic.search.Query;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;diff --git a/htroot/api/util/getpageinfo_p.java b/htroot/api/util/getpageinfo_p.javaindex 976adb8a2..cf191a7b4 100755--- a/htroot/api/util/getpageinfo_p.java+++ b/htroot/api/util/getpageinfo_p.java@@ -4,7 +4,7 @@ import java.net.MalformedURLException;import java.util.Set;import de.anomic.crawler.HTTPLoader;-import de.anomic.htmlFilter.htmlFilterContentScraper;+import de.anomic.document.parser.html.ContentScraper;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.plasma.plasmaSwitchboard;@@ -45,7 +45,7 @@ public class getpageinfo_p {final yacyURL u = new yacyURL(url, null);final httpRequestHeader reqHeader = new httpRequestHeader();reqHeader.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent); // do not set the crawler user agent, because this page was loaded by manual entering of the url- final htmlFilterContentScraper scraper = htmlFilterContentScraper.parseResource(u, reqHeader);+ final ContentScraper scraper = ContentScraper.parseResource(u, reqHeader);// put the document titleprop.putXML("title", scraper.getTitle());diff --git a/htroot/cytag.java b/htroot/cytag.javaindex 2bb7d3929..75c07de2d 100644--- a/htroot/cytag.java+++ b/htroot/cytag.java@@ -30,7 +30,7 @@ import java.io.File;import java.io.IOException;import java.util.Date;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;@@ -83,7 +83,7 @@ public class cytag {sb.append('\"');sb.append(k);sb.append("\":\"");- sb.append(htmlFilterCharacterCoding.unicode2xml(v, true));+ sb.append(CharacterCoding.unicode2xml(v, true));sb.append('\"');}}diff --git a/htroot/rct_p.java b/htroot/rct_p.javaindex 0fcf276c8..81b809e10 100644--- a/htroot/rct_p.java+++ b/htroot/rct_p.java@@ -32,12 +32,12 @@ import java.util.Iterator;import de.anomic.content.RSSMessage;import de.anomic.crawler.CrawlEntry;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyClient;import de.anomic.yacy.yacySeed;import de.anomic.yacy.yacyURL;diff --git a/htroot/sharedBlacklist_p.java b/htroot/sharedBlacklist_p.javaindex 0be0655e3..31bdef145 100644--- a/htroot/sharedBlacklist_p.java+++ b/htroot/sharedBlacklist_p.java@@ -43,7 +43,7 @@ import de.anomic.data.AbstractBlacklist;import de.anomic.data.listManager;import de.anomic.data.list.ListAccumulator;import de.anomic.data.list.XMLBlacklistImporter;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;@@ -269,7 +269,7 @@ public class sharedBlacklist_p {* turn the ampersand into & which renders the parameters* useless (at least when using Opera 9.53, haven't tested other browsers)*/- prop.put("LOCATION","Blacklist_p.html?selectedListName=" + htmlFilterCharacterCoding.unicode2html(selectedBlacklistName, true) + "&selectList=select");+ prop.put("LOCATION","Blacklist_p.html?selectedListName=" + CharacterCoding.unicode2html(selectedBlacklistName, true) + "&selectList=select");return prop;}diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex 6c041b1ed..22938d19a 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -35,6 +35,7 @@ import java.util.Map;import java.util.TreeSet;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.order.Base64Order;@@ -56,7 +57,6 @@ import de.anomic.server.serverProfiling;import de.anomic.server.serverSwitch;import de.anomic.tools.crypt;import de.anomic.tools.iso639;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacyNetwork;import de.anomic.yacy.yacySeed;diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.javaindex 8817222f3..79bc8bf5e 100644--- a/htroot/yacy/transferRWI.java+++ b/htroot/yacy/transferRWI.java@@ -34,6 +34,7 @@ import java.util.List;import de.anomic.content.RSSMessage;import de.anomic.data.Blacklist;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.text.referencePrototype.WordReferenceRow;import de.anomic.kelondro.util.FileUtils;@@ -42,7 +43,6 @@ import de.anomic.plasma.plasmaSwitchboardConstants;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacyNetwork;import de.anomic.yacy.yacySeed;diff --git a/htroot/yacy/transferURL.java b/htroot/yacy/transferURL.javaindex 4f56b9041..69097aa77 100644--- a/htroot/yacy/transferURL.java+++ b/htroot/yacy/transferURL.java@@ -31,6 +31,7 @@ import java.text.ParseException;import de.anomic.content.RSSMessage;import de.anomic.data.Blacklist;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;import de.anomic.kelondro.util.DateFormatter;@@ -38,7 +39,6 @@ import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacyNetwork;import de.anomic.yacy.yacySeed;diff --git a/htroot/yacysearch.java b/htroot/yacysearch.javaindex 240bbaa1b..72cc7d96b 100644--- a/htroot/yacysearch.java+++ b/htroot/yacysearch.java@@ -33,20 +33,21 @@ import java.util.Iterator;import java.util.TreeSet;import de.anomic.content.RSSMessage;+import de.anomic.document.Condenser;+import de.anomic.document.Word;+import de.anomic.document.Document;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;import de.anomic.kelondro.util.MemoryControl;import de.anomic.kelondro.util.SetTools;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaProfiling;import de.anomic.plasma.plasmaSearchEvent;import de.anomic.plasma.plasmaSnippetCache;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.Query;import de.anomic.search.RankingProfile;import de.anomic.server.serverCore;@@ -57,7 +58,6 @@ import de.anomic.server.serverSwitch;import de.anomic.tools.DidYouMean;import de.anomic.tools.iso639;import de.anomic.tools.Formatter;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyNewsPool;import de.anomic.yacy.yacyNewsRecord;import de.anomic.yacy.yacyURL;@@ -388,7 +388,7 @@ public class yacysearch {final URLMetadataRow urlentry = sb.indexSegment.urlMetadata().load(recommendHash, null, 0);if (urlentry != null) {final URLMetadataRow.Components metadata = urlentry.metadata();- plasmaParserDocument document;+ Document document;document = plasmaSnippetCache.retrieveDocument(metadata.url(), true, 5000, true, false);if (document != null) {// create a news messagediff --git a/source/de/anomic/content/DCEntry.java b/source/de/anomic/content/DCEntry.javaindex 90a67b94b..9439269da 100644--- a/source/de/anomic/content/DCEntry.java+++ b/source/de/anomic/content/DCEntry.java@@ -36,8 +36,8 @@ import java.util.HashSet;import java.util.Locale;import java.util.TreeMap;+import de.anomic.document.Document;import de.anomic.kelondro.util.DateFormatter;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.yacy.yacyURL;public class DCEntry extends TreeMap<String, String> {@@ -162,12 +162,12 @@ public class DCEntry extends TreeMap<String, String> {return s;}- public plasmaParserDocument document() {+ public Document document() {HashSet<String> languages = new HashSet<String>();languages.add(language());try {- return new plasmaParserDocument(+ return new Document(url(),"text/html","UTF-8",@@ -187,7 +187,7 @@ public class DCEntry extends TreeMap<String, String> {}public void writeXML(OutputStreamWriter os) throws IOException {- plasmaParserDocument doc = document();+ Document doc = document();if (doc != null) {doc.writeXML(os, this.date());}diff --git a/source/de/anomic/crawler/CrawlQueues.java b/source/de/anomic/crawler/CrawlQueues.javaindex 610a3e6d6..bedbd8bbc 100644--- a/source/de/anomic/crawler/CrawlQueues.java+++ b/source/de/anomic/crawler/CrawlQueues.java@@ -37,16 +37,15 @@ import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpClient;+import de.anomic.http.httpDocument;import de.anomic.kelondro.table.SplitTable;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;-import de.anomic.plasma.parser.Document;import de.anomic.server.serverProcessorJob;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyClient;import de.anomic.yacy.yacySeed;import de.anomic.yacy.yacyURL;@@ -504,7 +503,7 @@ public class CrawlQueues {}}- public Document loadResourceFromWeb(+ public httpDocument loadResourceFromWeb(final yacyURL url,final boolean forText,final boolean global@@ -529,7 +528,7 @@ public class CrawlQueues {0,0);- return loader.load(centry, (forText) ? plasmaParser.PARSER_MODE_CRAWLER : plasmaParser.PARSER_MODE_IMAGE);+ return loader.load(centry);}public int size() {@@ -575,7 +574,7 @@ public class CrawlQueues {} else {// starting a load from the internetthis.entry.setStatus("worker-loading", serverProcessorJob.STATUS_RUNNING);- final String result = loader.process(this.entry, plasmaParser.PARSER_MODE_CRAWLER);+ final String result = loader.process(this.entry);if (result != null) {final ZURL.Entry eentry = errorURL.newEntry(this.entry,diff --git a/source/de/anomic/crawler/CrawlSwitchboard.java b/source/de/anomic/crawler/CrawlSwitchboard.javaindex e93d0bf6d..12f5bf87c 100644--- a/source/de/anomic/crawler/CrawlSwitchboard.java+++ b/source/de/anomic/crawler/CrawlSwitchboard.java@@ -31,9 +31,9 @@ import java.io.IOException;import java.util.Iterator;import de.anomic.crawler.CrawlProfile.entry;+import de.anomic.document.Word;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.kelondroException;-import de.anomic.plasma.parser.Word;import de.anomic.yacy.yacySeedDB;import de.anomic.yacy.logging.Log;diff --git a/source/de/anomic/crawler/FTPLoader.java b/source/de/anomic/crawler/FTPLoader.javaindex 8b566761a..0bcd1c22e 100644--- a/source/de/anomic/crawler/FTPLoader.java+++ b/source/de/anomic/crawler/FTPLoader.java@@ -32,16 +32,15 @@ import java.io.IOException;import java.io.PrintStream;import java.util.Date;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpResponseHeader;-import de.anomic.http.httpdProxyCacheEntry;+import de.anomic.http.httpDocument;import de.anomic.kelondro.util.DateFormatter;import de.anomic.net.ftpc;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -57,14 +56,14 @@ public class FTPLoader {maxFileSize = (int) sb.getConfigLong("crawler.ftp.maxFileSize", -1l);}- protected Document createCacheEntry(final CrawlEntry entry, final String mimeType, final Date fileDate) {+ protected httpDocument createCacheEntry(final CrawlEntry entry, final String mimeType, final Date fileDate) {if (entry == null) return null;httpRequestHeader requestHeader = new httpRequestHeader();if (entry.referrerhash() != null) requestHeader.put(httpRequestHeader.REFERER, sb.getURL(entry.referrerhash()).toNormalform(true, false));httpResponseHeader responseHeader = new httpResponseHeader();responseHeader.put(httpHeader.LAST_MODIFIED, DateFormatter.formatRFC1123(fileDate));responseHeader.put(httpHeader.CONTENT_TYPE, mimeType);- Document metadata = new httpdProxyCacheEntry(+ httpDocument metadata = new httpDocument(entry.depth(), entry.url(), entry.name(), "OK",requestHeader, responseHeader,entry.initiator(), sb.crawler.profilesActiveCrawls.getEntry(entry.profileHandle()));@@ -78,14 +77,14 @@ public class FTPLoader {* @param entry* @return*/- public Document load(final CrawlEntry entry) throws IOException {+ public httpDocument load(final CrawlEntry entry) throws IOException {long start = System.currentTimeMillis();final yacyURL entryUrl = entry.url();final String fullPath = getPath(entryUrl);// the return value- Document htCache = null;+ httpDocument htCache = null;// determine filename and pathString file, path;@@ -216,17 +215,17 @@ public class FTPLoader {* @return* @throws Exception*/- private Document getFile(final ftpc ftpClient, final CrawlEntry entry) throws Exception {+ private httpDocument getFile(final ftpc ftpClient, final CrawlEntry entry) throws Exception {// determine the mimetype of the resourcefinal yacyURL entryUrl = entry.url();- final String extension = plasmaParser.getFileExt(entryUrl);- final String mimeType = plasmaParser.getMimeTypeByFileExt(extension);+ final String extension = ParserDispatcher.getFileExt(entryUrl);+ final String mimeType = ParserDispatcher.getMimeTypeByFileExt(extension);final String path = getPath(entryUrl);// if the mimetype and file extension is supported we start to download// the file- Document htCache = null;- if (plasmaParser.supportedContent(plasmaParser.PARSER_MODE_CRAWLER, entryUrl, mimeType)) {+ httpDocument htCache = null;+ if (ParserDispatcher.supportedContent(entryUrl, mimeType)) {// aborting download if content is too longfinal int size = ftpClient.fileSize(path);if (size <= maxFileSize || maxFileSize == -1) {diff --git a/source/de/anomic/crawler/HTTPLoader.java b/source/de/anomic/crawler/HTTPLoader.javaindex 4939a20ba..8b07d17a6 100644--- a/source/de/anomic/crawler/HTTPLoader.java+++ b/source/de/anomic/crawler/HTTPLoader.java@@ -29,16 +29,15 @@ import java.io.IOException;import java.util.Date;import de.anomic.data.Blacklist;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpResponse;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpResponseHeader;-import de.anomic.http.httpdProxyCacheEntry;+import de.anomic.http.httpDocument;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -84,8 +83,8 @@ public final class HTTPLoader {* @param responseStatus Status-Code SPACE Reason-Phrase* @return*/- protected Document createCacheEntry(final CrawlEntry entry, final Date requestDate, final httpRequestHeader requestHeader, final httpResponseHeader responseHeader, final String responseStatus) {- Document metadata = new httpdProxyCacheEntry(+ protected httpDocument createCacheEntry(final CrawlEntry entry, final Date requestDate, final httpRequestHeader requestHeader, final httpResponseHeader responseHeader, final String responseStatus) {+ httpDocument metadata = new httpDocument(entry.depth(),entry.url(),entry.name(),@@ -99,14 +98,14 @@ public final class HTTPLoader {return metadata;}- public Document load(final CrawlEntry entry, final String parserMode) throws IOException {+ public httpDocument load(final CrawlEntry entry) throws IOException {long start = System.currentTimeMillis();- Document doc = load(entry, parserMode, DEFAULT_CRAWLING_RETRY_COUNT);+ httpDocument doc = load(entry, DEFAULT_CRAWLING_RETRY_COUNT);Latency.update(entry.url().hash().substring(6), entry.url().getHost(), System.currentTimeMillis() - start);return doc;}- private Document load(final CrawlEntry entry, final String parserMode, final int retryCount) throws IOException {+ private httpDocument load(final CrawlEntry entry, final int retryCount) throws IOException {if (retryCount < 0) {sb.crawlQueues.errorURL.newEntry(entry, sb.peers.mySeed().hash, new Date(), 1, "redirection counter exceeded").store();@@ -128,7 +127,7 @@ public final class HTTPLoader {}// take a file from the net- Document htCache = null;+ httpDocument htCache = null;final long maxFileSize = sb.getConfigLong("crawler.http.maxFileSize", DEFAULT_MAXFILESIZE);//try {// create a request header@@ -157,7 +156,7 @@ public final class HTTPLoader {// request has been placed and result has been returned. work off response//try {- if (plasmaParser.supportedContent(parserMode, entry.url(), res.getResponseHeader().mime())) {+ if (ParserDispatcher.supportedContent(entry.url(), res.getResponseHeader().mime())) {// get the content length and check if the length is allowedlong contentLength = res.getResponseHeader().getContentLength();@@ -231,7 +230,7 @@ public final class HTTPLoader {// retry crawling with new urlentry.redirectURL(redirectionUrl);- return load(entry, plasmaParser.PARSER_MODE_URLREDIRECTOR, retryCount - 1);+ return load(entry, retryCount - 1);}} else {// if the response has not the right response type then reject filediff --git a/source/de/anomic/crawler/LoaderMessage.java b/source/de/anomic/crawler/LoaderMessage.javaindex 77ec51bdd..b63236ad1 100644--- a/source/de/anomic/crawler/LoaderMessage.java+++ b/source/de/anomic/crawler/LoaderMessage.java@@ -23,7 +23,7 @@package de.anomic.crawler;-import de.anomic.plasma.parser.Document;+import de.anomic.http.httpDocument;import de.anomic.server.serverSemaphore;import de.anomic.yacy.yacyURL;@@ -41,7 +41,7 @@ public final class LoaderMessage {public final boolean keepInMemory;private serverSemaphore resultSync = null;- private Document result;+ private httpDocument result;private String errorMessage;// loadParallel(URL url, String referer, String initiator, int depth, plasmaCrawlProfile.entry profile) {@@ -80,7 +80,7 @@ public final class LoaderMessage {return this.errorMessage;}- public void setResult(final Document theResult) {+ public void setResult(final httpDocument theResult) {// store the resultthis.result = theResult;@@ -88,8 +88,8 @@ public final class LoaderMessage {this.resultSync.V();}- public Document waitForResult() throws InterruptedException {- Document theResult = null;+ public httpDocument waitForResult() throws InterruptedException {+ httpDocument theResult = null;this.resultSync.P();/* =====> CRITICAL SECTION <======== */diff --git a/source/de/anomic/crawler/ProtocolLoader.java b/source/de/anomic/crawler/ProtocolLoader.javaindex 7412f7b66..6b9f8c87a 100644--- a/source/de/anomic/crawler/ProtocolLoader.java+++ b/source/de/anomic/crawler/ProtocolLoader.java@@ -33,8 +33,8 @@ import java.util.Iterator;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;+import de.anomic.http.httpDocument;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;import de.anomic.server.serverCore;import de.anomic.server.serverProcessorJob;import de.anomic.yacy.logging.Log;@@ -70,7 +70,7 @@ public final class ProtocolLoader {return (HashSet<String>) this.supportedProtocols.clone();}- public Document load(final CrawlEntry entry, final String parserMode) throws IOException {+ public httpDocument load(final CrawlEntry entry) throws IOException {// getting the protocol of the next URLfinal String protocol = entry.url().getProtocol();final String host = entry.url().getHost();@@ -95,7 +95,7 @@ public final class ProtocolLoader {accessTime.put(host, System.currentTimeMillis());// load resource- if ((protocol.equals("http") || (protocol.equals("https")))) return httpLoader.load(entry, parserMode);+ if ((protocol.equals("http") || (protocol.equals("https")))) return httpLoader.load(entry);if (protocol.equals("ftp")) return ftpLoader.load(entry);throw new IOException("Unsupported protocol '" + protocol + "' in url " + entry.url());@@ -111,13 +111,13 @@ public final class ProtocolLoader {}}- public String process(final CrawlEntry entry, final String parserMode) {+ public String process(final CrawlEntry entry) {// load a resource, store it to htcache and push queue entry to switchboard queue// returns null if everything went fine, a fail reason string if a problem occurred- Document h;+ httpDocument h;try {entry.setStatus("loading", serverProcessorJob.STATUS_RUNNING);- h = load(entry, parserMode);+ h = load(entry);assert h != null;entry.setStatus("loaded", serverProcessorJob.STATUS_RUNNING);final boolean stored = sb.htEntryStoreProcess(h);diff --git a/source/de/anomic/crawler/ResultImages.java b/source/de/anomic/crawler/ResultImages.javaindex fed45b8ad..d630dc724 100755--- a/source/de/anomic/crawler/ResultImages.java+++ b/source/de/anomic/crawler/ResultImages.java@@ -30,8 +30,8 @@ import java.util.HashMap;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.ConcurrentLinkedQueue;-import de.anomic.htmlFilter.htmlFilterImageEntry;-import de.anomic.plasma.plasmaParserDocument;+import de.anomic.document.Document;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.yacy.yacyURL;public class ResultImages {@@ -49,12 +49,12 @@ public class ResultImages {// the same images may be linked from different pagesprivate static final ConcurrentHashMap<String, Long> doubleCheck = new ConcurrentHashMap<String, Long>(); // (url-hash, time) when the url appeared first- public static void registerImages(final plasmaParserDocument document, final boolean privateEntry) {+ public static void registerImages(final Document document, final boolean privateEntry) {if (document == null) return;if (document.dc_source() == null) return;- final HashMap<String, htmlFilterImageEntry> images = document.getImages();- for (final htmlFilterImageEntry image: images.values()) {+ final HashMap<String, ImageEntry> images = document.getImages();+ for (final ImageEntry image: images.values()) {// do a double-check; attention: this can be time-consuming since this possibly needs a DNS-lookupif (doubleCheck.containsKey(image.url().hash())) continue;doubleCheck.put(image.url().hash(), System.currentTimeMillis());@@ -141,9 +141,9 @@ public class ResultImages {}public static class OriginEntry {- public htmlFilterImageEntry imageEntry;+ public ImageEntry imageEntry;public yacyURL baseURL;- public OriginEntry(final htmlFilterImageEntry imageEntry, final yacyURL baseURL) {+ public OriginEntry(final ImageEntry imageEntry, final yacyURL baseURL) {this.imageEntry = imageEntry;this.baseURL = baseURL;}diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.javaindex 8f60e7b50..690dbd096 100644--- a/source/de/anomic/data/bookmarksDB.java+++ b/source/de/anomic/data/bookmarksDB.java@@ -63,8 +63,9 @@ import org.xml.sax.SAXException;import de.anomic.crawler.CrawlEntry;import de.anomic.crawler.CrawlProfile;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterWriter;+import de.anomic.document.Word;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.TransformerWriter;import de.anomic.kelondro.blob.Heap;import de.anomic.kelondro.blob.MapView;import de.anomic.kelondro.order.CloneableIterator;@@ -73,7 +74,6 @@ import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.kelondroException;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Word;import de.anomic.server.serverBusyThread;import de.anomic.server.serverInstantBusyThread;import de.anomic.yacy.yacyNewsPool;@@ -782,9 +782,9 @@ public class bookmarksDB {final Set<String> tags=listManager.string2set(tag); //this allow multiple default tagstry {//load the links- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);+ final ContentScraper scraper = new ContentScraper(baseURL);//OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- final Writer writer= new htmlFilterWriter(null,null,scraper, null, false);+ final Writer writer= new TransformerWriter(null,null,scraper, null, false);FileUtils.copy(input,writer);writer.close();links = scraper.getAnchors();diff --git a/source/de/anomic/data/diff.java b/source/de/anomic/data/diff.javaindex 9222dd9a1..af904c2d6 100644--- a/source/de/anomic/data/diff.java+++ b/source/de/anomic/data/diff.java@@ -30,7 +30,7 @@ package de.anomic.data;import java.util.ArrayList;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;/*** This class provides a diff-functionality.@@ -255,7 +255,7 @@ public class diff {case diff.Part.ADDED: sb.append("added"); break;case diff.Part.DELETED: sb.append("deleted"); break;}- sb.append("\">").append(htmlFilterCharacterCoding.unicode2html(ps[j].getString(), true).replaceAll("\n", "<br />"));+ sb.append("\">").append(CharacterCoding.unicode2html(ps[j].getString(), true).replaceAll("\n", "<br />"));sb.append("</span>");}sb.append("</p>");diff --git a/source/de/anomic/data/wiki/wikiCode.java b/source/de/anomic/data/wiki/wikiCode.javaindex 3ca1e349d..951ef98a8 100644--- a/source/de/anomic/data/wiki/wikiCode.java+++ b/source/de/anomic/data/wiki/wikiCode.java@@ -32,7 +32,7 @@ import java.util.HashMap;import java.util.List;import java.util.Map;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.server.serverCore;/** This class provides methods to handle texts that have been posted in the yacyWiki or other@@ -698,7 +698,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {public String transformLine(String result) {//If HTML has not bee replaced yet (can happen if method gets called in recursion), replace now!if (!replacedHTML || preformattedSpan) {- result = htmlFilterCharacterCoding.unicode2html(result, true);+ result = CharacterCoding.unicode2html(result, true);replacedHTML = true;}diff --git a/source/de/anomic/plasma/parser/AbstractParser.java b/source/de/anomic/document/AbstractParser.javasimilarity index 80%rename from source/de/anomic/plasma/parser/AbstractParser.javarename to source/de/anomic/document/AbstractParser.javaindex 3140ab047..fd90f1b00 100644--- a/source/de/anomic/plasma/parser/AbstractParser.java+++ b/source/de/anomic/document/AbstractParser.java@@ -23,7 +23,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser;+package de.anomic.document;import java.io.BufferedInputStream;import java.io.ByteArrayInputStream;@@ -33,19 +33,17 @@ import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;-import de.anomic.plasma.plasmaParser;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.server.serverThread;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;/**- * New classes implementing the {@link de.anomic.plasma.parser.Parser} interface+ * New classes implementing the {@link de.anomic.document.Parser} interface* can extend this class to inherit all functions already implemented in this class.* @author Martin Thelian* @version $LastChangedRevision$ / $LastChangedDate$*/-public abstract class AbstractParser implements Parser{+public abstract class AbstractParser implements Parser {/*** a list of library names that are needed by this parser@@ -56,12 +54,7 @@ public abstract class AbstractParser implements Parser{* the logger class that should be used by the parser module for logging* purposes.*/- protected Log theLogger = null;-- /**- * Version number of the parser- */- protected String parserVersionNr = "0.1";+ protected final Log theLogger = new Log("PARSER");/*** Parser name@@ -120,7 +113,7 @@ public abstract class AbstractParser implements Parser{return tempFile;}- public int parseDir(final yacyURL location, final String prefix, final File dir, final plasmaParserDocument doc)+ public int parseDir(final yacyURL location, final String prefix, final File dir, final Document doc)throws ParserException, InterruptedException, IOException {if (!dir.isDirectory())throw new ParserException("tried to parse ordinary file " + dir + " as directory", location);@@ -138,9 +131,9 @@ public abstract class AbstractParser implements Parser{// XXX: workaround for relative paths within document+ file.getPath().substring(file.getPath().indexOf(File.separatorChar) + 1)+ "/" + file.getName());- final plasmaParserDocument subdoc = new plasmaParser().parseSource(+ final Document subdoc = ParserDispatcher.parseSource(url,- plasmaParser.getMimeTypeByFileExt(files[i].substring(files[i].indexOf('.') + 1)),+ ParserDispatcher.getMimeTypeByFileExt(files[i].substring(files[i].indexOf('.') + 1)),null, file);// TODO: change anchors back to use '#' after archive namedoc.addSubDocument(subdoc);@@ -159,13 +152,13 @@ public abstract class AbstractParser implements Parser{* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param source the content byte array- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.* @throws ParserException if the content could not be parsed properly*- * @see de.anomic.plasma.parser.Parser#parse(de.anomic.net.URL, java.lang.String, byte[])+ * @see de.anomic.document.Parser#parse(de.anomic.net.URL, java.lang.String, byte[])*/- public plasmaParserDocument parse(+ public Document parse(final yacyURL location,final String mimeType,final String charset,@@ -194,13 +187,13 @@ public abstract class AbstractParser implements Parser{* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param sourceFile the file containing the content of the document- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.* @throws ParserException if the content could not be parsed properly*- * @see de.anomic.plasma.parser.Parser#parse(de.anomic.net.URL, java.lang.String, java.io.File)+ * @see de.anomic.document.Parser#parse(de.anomic.net.URL, java.lang.String, java.io.File)*/- public plasmaParserDocument parse(+ public Document parse(final yacyURL location,final String mimeType,final String charset,@@ -229,37 +222,22 @@ public abstract class AbstractParser implements Parser{* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param source the {@link InputStream} containing the document content- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.* @throws ParserException if the content could not be parsed properly*- * @see de.anomic.plasma.parser.Parser#parse(de.anomic.net.URL, java.lang.String, java.io.InputStream)+ * @see de.anomic.document.Parser#parse(de.anomic.net.URL, java.lang.String, java.io.InputStream)*/- public abstract plasmaParserDocument parse(yacyURL location, String mimeType, String charset, InputStream source) throws ParserException, InterruptedException;+ public abstract Document parse(yacyURL location, String mimeType, String charset, InputStream source) throws ParserException, InterruptedException;/*** @return Returns a list of library names that are needed by this parser- * @see de.anomic.plasma.parser.Parser#getLibxDependences()+ * @see de.anomic.document.Parser#getLibxDependences()*/public String[] getLibxDependences() {return this.libxDependencies;}- /**- * Setting the logger that should be used by this parser class ...- */- public void setLogger(final Log log) {- this.theLogger = log;- }-- /**- * Returns the version number of the parser- * @return parser version number- */- public String getVersion() {- return this.parserVersionNr;- }-/*** Return the name of the parser*/diff --git a/source/de/anomic/plasma/parser/Condenser.java b/source/de/anomic/document/Condenser.javasimilarity index 95%rename from source/de/anomic/plasma/parser/Condenser.javarename to source/de/anomic/document/Condenser.javaindex defdb96e8..b13467d64 100644--- a/source/de/anomic/plasma/parser/Condenser.java+++ b/source/de/anomic/document/Condenser.java@@ -23,7 +23,7 @@// compile with javac -sourcepath source source/de/anomic/plasma/plasmaCondenser.java// execute with java -cp source de.anomic.plasma.plasmaCondenser-package de.anomic.plasma.parser;+package de.anomic.document;import java.io.BufferedReader;import java.io.ByteArrayInputStream;@@ -46,13 +46,12 @@ import java.util.Properties;import java.util.TreeMap;import java.util.TreeSet;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.language.Identificator;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.text.referencePrototype.WordReferenceRow;import de.anomic.kelondro.util.SetTools;-import de.anomic.language.identification.Identificator;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.yacy.yacyURL;public final class Condenser {@@ -101,7 +100,7 @@ public final class Condenser {Identificator languageIdentificator;public Condenser(- final plasmaParserDocument document,+ final Document document,final boolean indexText,final boolean indexMedia) throws UnsupportedEncodingException {@@ -196,8 +195,8 @@ public final class Condenser {}// images- final Iterator<htmlFilterImageEntry> j = document.getImages().values().iterator();- htmlFilterImageEntry ientry;+ final Iterator<ImageEntry> j = document.getImages().values().iterator();+ ImageEntry ientry;while (j.hasNext()) {ientry = j.next();insertTextToWords(ientry.url().toNormalform(false, false), 99, flag_cat_hasimage, RESULT_FLAGS, false);@@ -327,7 +326,7 @@ public final class Condenser {// distinguish punctuation and wordswordlen = word.length();Iterator<String> it;- if ((wordlen == 1) && (htmlFilterContentScraper.punctuation(word.charAt(0)))) {+ if ((wordlen == 1) && (ContentScraper.punctuation(word.charAt(0)))) {// store sentenceif (sentence.length() > 0) {// we store the punctuation symbol as first element of the sentence vector@@ -488,7 +487,7 @@ public final class Condenser {|| (type == Character.MODIFIER_LETTER)|| (type == Character.OTHER_LETTER)|| (type == Character.TITLECASE_LETTER)- || (htmlFilterContentScraper.punctuation(c))) {+ || (ContentScraper.punctuation(c))) {return false;}return true;@@ -521,7 +520,7 @@ public final class Condenser {StringBuilder s;loop: while (e.hasMoreElements()) {s = e.nextElement();- if ((s.length() == 1) && (htmlFilterContentScraper.punctuation(s.charAt(0)))) return s;+ if ((s.length() == 1) && (ContentScraper.punctuation(s.charAt(0)))) return s;for (int i = 0; i < s.length(); i++) {if (invisible(s.charAt(i))) continue loop;}@@ -639,7 +638,7 @@ public final class Condenser {for (int i = 0; i < r.length(); i++) {c = r.charAt(i);if (invisible(c)) sb = sb.append(' '); // TODO: Bugfix needed for UTF-8- else if (htmlFilterContentScraper.punctuation(c)) sb = sb.append(' ').append(c).append(' ');+ else if (ContentScraper.punctuation(c)) sb = sb.append(' ').append(c).append(' ');else sb = sb.append(c);}s = trim(sb);@@ -768,7 +767,7 @@ public final class Condenser {if (c < ' ') c = ' ';if ((lc == ' ') && (c == ' ')) continue; // ignore double spacess.append(c);- if (htmlFilterContentScraper.punctuation(lc) && invisible(c)) break;+ if (ContentScraper.punctuation(lc) && invisible(c)) break;lc = c;}diff --git a/source/de/anomic/plasma/plasmaParserDocument.java b/source/de/anomic/document/Document.javasimilarity index 87%rename from source/de/anomic/plasma/plasmaParserDocument.javarename to source/de/anomic/document/Document.javaindex 0d7de3639..5274da9f4 100644--- a/source/de/anomic/plasma/plasmaParserDocument.java+++ b/source/de/anomic/document/Document.java@@ -21,7 +21,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma;+package de.anomic.document;import java.io.BufferedInputStream;import java.io.ByteArrayInputStream;@@ -40,16 +40,15 @@ import java.util.Map;import java.util.Set;import java.util.TreeSet;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.Condenser;+import de.anomic.plasma.plasmaWebStructure;import de.anomic.server.serverCachedFileOutputStream;import de.anomic.yacy.yacyURL;-public class plasmaParserDocument {+public class Document {private final yacyURL source; // the source urlprivate final String mimeType; // mimeType as taken from http header@@ -61,7 +60,7 @@ public class plasmaParserDocument {private final StringBuilder description; // an abstract, if present: short content descriptionprivate Object text; // the clear text, all that is visibleprivate final Map<yacyURL, String> anchors; // all links embedded as clickeable entities (anchor tags)- private final HashMap<String, htmlFilterImageEntry> images; // all visible pictures in document+ private final HashMap<String, ImageEntry> images; // all visible pictures in document// the anchors and images - Maps are URL-to-EntityDescription mappings.// The EntityDescription appear either as visible text in anchors or as alternative// text in image tags.@@ -73,10 +72,10 @@ public class plasmaParserDocument {private int inboundLinks, outboundLinks; // counters for inbound and outbound links, are counted after calling notifyWebStructureprivate Set<String> languages;- protected plasmaParserDocument(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,+ protected Document(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,final String[] keywords, final String title, final String author,final String[] sections, final String abstrct,- final Object text, final Map<yacyURL, String> anchors, final HashMap<String, htmlFilterImageEntry> images) {+ final Object text, final Map<yacyURL, String> anchors, final HashMap<String, ImageEntry> images) {this.source = location;this.mimeType = (mimeType == null) ? "application/octet-stream" : mimeType;this.charset = charset;@@ -86,7 +85,7 @@ public class plasmaParserDocument {this.sections = (sections == null) ? new LinkedList<String>() : Arrays.asList(sections);this.description = (abstrct == null) ? new StringBuilder(0) : new StringBuilder(abstrct);this.anchors = (anchors == null) ? new HashMap<yacyURL, String>(0) : anchors;- this.images = (images == null) ? new HashMap<String, htmlFilterImageEntry>() : images;+ this.images = (images == null) ? new HashMap<String, ImageEntry>() : images;this.hyperlinks = null;this.audiolinks = null;this.videolinks = null;@@ -107,28 +106,28 @@ public class plasmaParserDocument {}}- public plasmaParserDocument(final yacyURL location, final String mimeType, final String charset, final Set<String> languages) {+ public Document(final yacyURL location, final String mimeType, final String charset, final Set<String> languages) {this(location, mimeType, charset, languages, null, null, null, null, null, (Object)null, null, null);}- public plasmaParserDocument(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,+ public Document(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,final String[] keywords, final String title, final String author,final String[] sections, final String abstrct,- final byte[] text, final Map<yacyURL, String> anchors, final HashMap<String, htmlFilterImageEntry> images) {+ final byte[] text, final Map<yacyURL, String> anchors, final HashMap<String, ImageEntry> images) {this(location, mimeType, charset, languages, keywords, title, author, sections, abstrct, (Object)text, anchors, images);}- public plasmaParserDocument(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,+ public Document(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,final String[] keywords, final String title, final String author,final String[] sections, final String abstrct,- final File text, final Map<yacyURL, String> anchors, final HashMap<String, htmlFilterImageEntry> images) {+ final File text, final Map<yacyURL, String> anchors, final HashMap<String, ImageEntry> images) {this(location, mimeType, charset, languages, keywords, title, author, sections, abstrct, (Object)text, anchors, images);}- public plasmaParserDocument(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,+ public Document(final yacyURL location, final String mimeType, final String charset, final Set<String> languages,final String[] keywords, final String title, final String author,final String[] sections, final String abstrct,- final serverCachedFileOutputStream text, final Map<yacyURL, String> anchors, final HashMap<String, htmlFilterImageEntry> images) {+ final serverCachedFileOutputStream text, final Map<yacyURL, String> anchors, final HashMap<String, ImageEntry> images) {this(location, mimeType, charset, languages, keywords, title, author, sections, abstrct, (Object)text, anchors, images);}@@ -323,7 +322,7 @@ dc_rightsreturn this.videolinks;}- public HashMap<String, htmlFilterImageEntry> getImages() {+ public HashMap<String, ImageEntry> getImages() {// returns all links enbedded as pictures (visible in document)// this resturns a htmlFilterImageEntry collectionif (!resorted) resortLinks();@@ -355,7 +354,7 @@ dc_rightsaudiolinks = new HashMap<yacyURL, String>();applinks = new HashMap<yacyURL, String>();emaillinks = new HashMap<String, String>();- final HashMap<String, htmlFilterImageEntry> collectedImages = new HashMap<String, htmlFilterImageEntry>(); // this is a set that is collected now and joined later to the imagelinks+ final HashMap<String, ImageEntry> collectedImages = new HashMap<String, ImageEntry>(); // this is a set that is collected now and joined later to the imagelinksMap.Entry<yacyURL, String> entry;while (i.hasNext()) {entry = i.next();@@ -372,14 +371,14 @@ dc_rights} else {ext = u.substring(extpos + 1).toLowerCase();}- if (plasmaParser.mediaExtContains(ext)) {+ if (ParserDispatcher.mediaExtContains(ext)) {// this is not a normal anchor, its a media link- if (plasmaParser.imageExtContains(ext)) {- htmlFilterContentScraper.addImage(collectedImages, new htmlFilterImageEntry(url, entry.getValue(), -1, -1));+ if (ParserDispatcher.imageExtContains(ext)) {+ ContentScraper.addImage(collectedImages, new ImageEntry(url, entry.getValue(), -1, -1));}- else if (plasmaParser.audioExtContains(ext)) audiolinks.put(url, entry.getValue());- else if (plasmaParser.videoExtContains(ext)) videolinks.put(url, entry.getValue());- else if (plasmaParser.appsExtContains(ext)) applinks.put(url, entry.getValue());+ else if (ParserDispatcher.audioExtContains(ext)) audiolinks.put(url, entry.getValue());+ else if (ParserDispatcher.videoExtContains(ext)) videolinks.put(url, entry.getValue());+ else if (ParserDispatcher.appsExtContains(ext)) applinks.put(url, entry.getValue());} else {hyperlinks.put(url, entry.getValue());}@@ -391,16 +390,16 @@ dc_rights}// add image links that we collected from the anchors to the image map- htmlFilterContentScraper.addAllImages(images, collectedImages);+ ContentScraper.addAllImages(images, collectedImages);// expand the hyperlinks:// we add artificial hyperlinks to the hyperlink set// that can be calculated from given hyperlinks and imagelinks- hyperlinks.putAll(plasmaParser.allReflinks(images.values()));- hyperlinks.putAll(plasmaParser.allReflinks(audiolinks.keySet()));- hyperlinks.putAll(plasmaParser.allReflinks(videolinks.keySet()));- hyperlinks.putAll(plasmaParser.allReflinks(applinks.keySet()));+ hyperlinks.putAll(ParserDispatcher.allReflinks(images.values()));+ hyperlinks.putAll(ParserDispatcher.allReflinks(audiolinks.keySet()));+ hyperlinks.putAll(ParserDispatcher.allReflinks(videolinks.keySet()));+ hyperlinks.putAll(ParserDispatcher.allReflinks(applinks.keySet()));/*hyperlinks.putAll(plasmaParser.allSubpaths(hyperlinks.keySet()));hyperlinks.putAll(plasmaParser.allSubpaths(images.values()));@@ -412,7 +411,7 @@ dc_rightsthis.resorted = true;}- public void addSubDocument(final plasmaParserDocument doc) throws IOException {+ public void addSubDocument(final Document doc) throws IOException {this.sections.addAll(Arrays.asList(doc.getSectionTitles()));if (this.title.length() > 0) this.title.append('\n');@@ -430,7 +429,7 @@ dc_rightsFileUtils.copy(doc.getText(), (serverCachedFileOutputStream)this.text);anchors.putAll(doc.getAnchors());- htmlFilterContentScraper.addAllImages(images, doc.getImages());+ ContentScraper.addAllImages(images, doc.getImages());}/**diff --git a/source/de/anomic/plasma/parser/Parser.java b/source/de/anomic/document/Parser.javasimilarity index 72%rename from source/de/anomic/plasma/parser/Parser.javarename to source/de/anomic/document/Parser.javaindex 7b8705c97..50658c8b4 100644--- a/source/de/anomic/plasma/parser/Parser.java+++ b/source/de/anomic/document/Parser.java@@ -23,15 +23,13 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser;+package de.anomic.document;import java.io.File;import java.io.InputStream;import java.util.Hashtable;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.yacy.yacyURL;-import de.anomic.yacy.logging.Log;/*** This interface defines a list of methods that needs to be implemented@@ -50,12 +48,12 @@ public interface Parser {* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param source the content byte array- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.** @throws ParserException if the content could not be parsed properly*/- public plasmaParserDocument parse(yacyURL location, String mimeType, String charset, byte[] source)+ public Document parse(yacyURL location, String mimeType, String charset, byte[] source)throws ParserException, InterruptedException;/**@@ -64,12 +62,12 @@ public interface Parser {* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param sourceFile the file containing the content of the document- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.** @throws ParserException if the content could not be parsed properly*/- public plasmaParserDocument parse(yacyURL location, String mimeType, String charset, File sourceFile)+ public Document parse(yacyURL location, String mimeType, String charset, File sourceFile)throws ParserException, InterruptedException;/**@@ -78,12 +76,12 @@ public interface Parser {* @param mimeType the mimetype of the document* @param charset the supposed charset of the document or <code>null</code> if unkown* @param source the {@link InputStream} containing the document content- * @return a {@link plasmaParserDocument} containing the extracted plain text of the document+ * @return a {@link Document} containing the extracted plain text of the document* and some additional metadata.** @throws ParserException if the content could not be parsed properly*/- public plasmaParserDocument parse(yacyURL location, String mimeType, String charset, InputStream source)+ public Document parse(yacyURL location, String mimeType, String charset, InputStream source)throws ParserException, InterruptedException;/**@@ -100,23 +98,6 @@ public interface Parser {public void setContentLength(long length);- /**- * @return Returns a list of library names that are needed by this parser- */- public String[] getLibxDependences();-- /**- * Can be used to set the logger that should be used by the parser module- * @param log the {@link Log logger} that should be used- */- public void setLogger(Log log);-- /**- * Returns the version number of the current parser- * @return parser version number- */- public String getVersion();-/*** Returns the name of the parser* @return parser namediff --git a/source/de/anomic/plasma/plasmaParserConfig.java b/source/de/anomic/document/ParserConfig.javasimilarity index 74%rename from source/de/anomic/plasma/plasmaParserConfig.javarename to source/de/anomic/document/ParserConfig.javaindex f8b26c183..38bcdb059 100644--- a/source/de/anomic/plasma/plasmaParserConfig.java+++ b/source/de/anomic/document/ParserConfig.java@@ -25,7 +25,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma;+package de.anomic.document;import java.util.Arrays;import java.util.HashSet;@@ -33,40 +33,32 @@ import java.util.Hashtable;import java.util.Iterator;import java.util.Set;-import de.anomic.plasma.parser.Parser;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;-public class plasmaParserConfig {+public class ParserConfig {+/*** A list containing all enabled parsers and the mimeType that they can handle* @see #loadEnabledParserList()* @see #setEnabledParserList(Enumeration)*/- public final HashSet<String> enabledParserList = new HashSet<String>();+ public final HashSet<String> enabledParserList;/*** A list of file extensions that are supported by all enabled parsers*/- private final HashSet<String> supportedFileExt = new HashSet<String>();-- /**- * Parsermode this configuration belongs to- */- public String parserMode = null;+ private final HashSet<String> supportedFileExt;- public plasmaParserConfig(final String theParserMode) {- if (!plasmaParser.PARSER_MODE.contains(theParserMode)) {- throw new IllegalArgumentException("Unknown parser mode " + theParserMode);- }-- this.parserMode = theParserMode;+ public ParserConfig() {+ supportedFileExt = new HashSet<String>();+ enabledParserList = new HashSet<String>();}public boolean supportedContent(final yacyURL url, String mimeType) {// TODO: we need some exceptions here to index URLs like this// http://www.musicabona.com/respighi/12668/cd/index.html.fr- mimeType = plasmaParser.normalizeMimeType(mimeType);+ mimeType = ParserDispatcher.normalizeMimeType(mimeType);if (mimeType.equals("text/html") ||mimeType.equals("application/xhtml+xml") ||@@ -78,10 +70,10 @@ public class plasmaParserConfig {}public boolean supportedMimeTypesContains(String mimeType) {- mimeType = plasmaParser.normalizeMimeType(mimeType);+ mimeType = ParserDispatcher.normalizeMimeType(mimeType);- synchronized (plasmaParser.supportedHTMLMimeTypes) {- if (plasmaParser.supportedHTMLMimeTypes.contains(mimeType)) return true;+ synchronized (ParserDispatcher.supportedHTMLMimeTypes) {+ if (ParserDispatcher.supportedHTMLMimeTypes.contains(mimeType)) return true;}synchronized (this.enabledParserList) {@@ -93,7 +85,7 @@ public class plasmaParserConfig {if (url == null) throw new NullPointerException();// getting the file path- final String name = plasmaParser.getFileExt(url);+ final String name = ParserDispatcher.getFileExt(url);return supportedFileExtContains(name);}@@ -101,8 +93,8 @@ public class plasmaParserConfig {if (fileExt == null) return false;fileExt = fileExt.trim().toLowerCase();- synchronized (plasmaParser.supportedHTMLFileExt) {- if (plasmaParser.supportedHTMLFileExt.contains(fileExt)) return true;+ synchronized (ParserDispatcher.supportedHTMLFileExt) {+ if (ParserDispatcher.supportedHTMLFileExt.contains(fileExt)) return true;}synchronized(this.supportedFileExt) {@@ -110,7 +102,7 @@ public class plasmaParserConfig {}}- public void initParseableMimeTypes(final String enabledMimeTypes) {+ public void addParseableMimeTypes(final String enabledMimeTypes) {HashSet<String> mimeTypes = null;if ((enabledMimeTypes == null) || (enabledMimeTypes.length() == 0)) {mimeTypes = new HashSet<String>();@@ -123,11 +115,11 @@ public class plasmaParserConfig {}public void enableAllParsers() {- final Set<String> availableMimeTypes = plasmaParser.availableParserList.keySet();+ final Set<String> availableMimeTypes = ParserDispatcher.availableParserList.keySet();setEnabledParserList(availableMimeTypes);}- public String[] setEnabledParserList(final Set<String> mimeTypeSet) {+ public String[] setEnabledParserList(final Set<String> mimeTypeSet) {final HashSet<String> newEnabledParsers = new HashSet<String>();final HashSet<String> newSupportedFileExt = new HashSet<String>();@@ -136,12 +128,9 @@ public class plasmaParserConfig {final Iterator<String> mimeTypes = mimeTypeSet.iterator();while (mimeTypes.hasNext()) {final String mimeType = mimeTypes.next();- if (plasmaParser.availableParserList.containsKey(mimeType)) {- Parser theParser = null;+ Parser theParser = ParserDispatcher.availableParserList.get(mimeType);+ if (theParser != null) {try {- // getting the parser- theParser = plasmaParser.makeParser((plasmaParser.availableParserList.get(mimeType)).parserClassName);-// getting a list of mimeTypes that the parser supportsfinal Hashtable<String, String> parserSupportsMimeTypes = theParser.getSupportedMimeTypes();if (parserSupportsMimeTypes != null) {@@ -166,12 +155,10 @@ public class plasmaParserConfig {}synchronized (this.enabledParserList) {- this.enabledParserList.clear();this.enabledParserList.addAll(newEnabledParsers);}synchronized (this.supportedFileExt) {- this.supportedFileExt.clear();this.supportedFileExt.addAll(newSupportedFileExt);}diff --git a/source/de/anomic/document/ParserDispatcher.java b/source/de/anomic/document/ParserDispatcher.javanew file mode 100644index 000000000..64678afb2--- /dev/null+++ b/source/de/anomic/document/ParserDispatcher.java@@ -0,0 +1,776 @@++package de.anomic.document;++import java.io.BufferedInputStream;+import java.io.ByteArrayInputStream;+import java.io.File;+import java.io.FileInputStream;+import java.io.IOException;+import java.io.InputStream;+import java.io.UnsupportedEncodingException;+import java.net.MalformedURLException;+import java.nio.charset.Charset;+import java.nio.charset.IllegalCharsetNameException;+import java.nio.charset.UnsupportedCharsetException;+import java.util.Collection;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Hashtable;+import java.util.Iterator;+import java.util.LinkedList;+import java.util.List;+import java.util.Map;+import java.util.Properties;+import java.util.Set;++import de.anomic.document.parser.bzipParser;+import de.anomic.document.parser.docParser;+import de.anomic.document.parser.gzipParser;+import de.anomic.document.parser.mimeTypeParser;+import de.anomic.document.parser.odtParser;+import de.anomic.document.parser.pdfParser;+import de.anomic.document.parser.pptParser;+import de.anomic.document.parser.psParser;+import de.anomic.document.parser.rpmParser;+import de.anomic.document.parser.rssParser;+import de.anomic.document.parser.rtfParser;+import de.anomic.document.parser.sevenzipParser;+import de.anomic.document.parser.swfParser;+import de.anomic.document.parser.tarParser;+import de.anomic.document.parser.vcfParser;+import de.anomic.document.parser.vsdParser;+import de.anomic.document.parser.xlsParser;+import de.anomic.document.parser.zipParser;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;+import de.anomic.document.parser.html.ScraperInputStream;+import de.anomic.document.parser.html.TransformerWriter;+import de.anomic.kelondro.util.FileUtils;+import de.anomic.yacy.yacyURL;+import de.anomic.yacy.logging.Log;++public final class ParserDispatcher {++ private static final ParserConfig parserConfig = new ParserConfig();++ /**+ * A list containing all installed parsers and the mimeType that they support+ * @see #loadAvailableParserList()+ */+ public static final HashMap<String, Parser> availableParserList = new HashMap<String, Parser>();++ /**+ * A list of file extensions and mime types that are supported by the html-parser+ */+ public static final HashSet<String> supportedHTMLFileExt = new HashSet<String>();+ public static final HashSet<String> supportedHTMLMimeTypes = new HashSet<String>();++ private static final Properties mimeTypeLookupByFileExt = new Properties();+ static {+ // loading a list of extensions from file+ BufferedInputStream bufferedIn = null;+ try {+ mimeTypeLookupByFileExt.load(bufferedIn = new BufferedInputStream(new FileInputStream(new File("httpd.mime"))));+ } catch (final IOException e) {+ System.err.println("ERROR: httpd.mime not found in settings path");+ } finally {+ if (bufferedIn != null) try{bufferedIn.close();}catch(final Exception e){}+ }+ }++ /**+ * A list of media extensions that should <b>not</b> be handled by the Parser+ */+ private static final HashSet<String> mediaExtSet = new HashSet<String>();++ /**+ * A list of image, audio, video and application extensions+ */+ private static final HashSet<String> imageExtSet = new HashSet<String>();+ private static final HashSet<String> audioExtSet = new HashSet<String>();+ private static final HashSet<String> videoExtSet = new HashSet<String>();+ private static final HashSet<String> appsExtSet = new HashSet<String>();++ /**+ * This {@link FilenameFilter} is used to find all classes based on there filenames+ * which seems to be additional content parsers.+ * Currently the filenames of all content parser classes must end with <code>Parser.class</code>+ */+ /*+ private static final FilenameFilter parserFileNameFilter = new FilenameFilter() {+ public boolean accept(File dir, String name) {+ return name.endsWith("Parser.class");+ }+ };+ */++ /**+ * This {@link FileFilter} is used to get all subpackages+ * of the parser package.+ */+ /*+ private static final FileFilter parserDirectoryFilter = new FileFilter() {+ public boolean accept(File file) {+ return file.isDirectory();+ }+ };+ */++ /**+ * Initializing the+ * @see #initMediaExt(String)+ */+ static {+ final String apps = "sit,hqx,img,dmg,exe,com,bat,sh,vbs,zip,jar";+ final String audio = "mp2,mp3,ogg,aac,aif,aiff,wav";+ final String video = "swf,avi,wmv,rm,mov,mpg,mpeg,ram,m4v";+ final String image = "jpg,jpeg,jpe,gif,png,ico,bmp";+ initMediaExt(extString2extList(+ apps + "," + // application container+ "tar,gz,bz2,arj,zip,rar," + // archive formats+ "ps,xls,ppt,asf," + // text formats without support+ audio + "," + // audio formats+ video + "," + // video formats+ image // image formats+ ));+ initImageExt(extString2extList(image)); // image formats+ initAudioExt(extString2extList(audio)); // audio formats+ initVideoExt(extString2extList(video)); // video formats+ initAppsExt(extString2extList(apps)); // application formats++ /* ===================================================+ * loading a list of available parsers+ * =================================================== */+ loadAvailableParserList();+ }++ private static final Log theLogger = new Log("PARSER");++ public Log getLogger() {+ return theLogger;+ }++ /**+ * This function is used to initialize the HTMLParsableMimeTypes List.+ * This list contains a list of mimeTypes that can be parsed in realtime by+ * the yacy html-Parser+ * @param htmlParsableMimeTypes a list of mimetypes that can be parsed by the+ * yacy html parser+ */+ public static void initHTMLParsableMimeTypes(final String htmlParsableMimeTypes) {+ final LinkedList<String> mimeTypes = new LinkedList<String>();+ if ((htmlParsableMimeTypes == null) || (htmlParsableMimeTypes.length() == 0)) {+ return;+ }+ final String[] realtimeParsableMimeTypeList = htmlParsableMimeTypes.split(",");+ for (int i = 0; i < realtimeParsableMimeTypeList.length; i++) {+ mimeTypes.add(realtimeParsableMimeTypeList[i].toLowerCase().trim());+ }+ synchronized (supportedHTMLMimeTypes) {+ supportedHTMLMimeTypes.addAll(mimeTypes);+ }+ }++ public static List<String> extString2extList(final String extString) {+ final LinkedList<String> extensions = new LinkedList<String>();+ if ((extString == null) || (extString.length() == 0)) {+ return extensions;+ }+ final String[] xs = extString.split(",");+ for (int i = 0; i < xs.length; i++) extensions.add(xs[i].toLowerCase().trim());+ return extensions;+ }++ public static void initMediaExt(final List<String> mediaExtList) {+ synchronized (mediaExtSet) {+ mediaExtSet.addAll(mediaExtList);+ }+ }++ public static void initImageExt(final List<String> imageExtList) {+ synchronized (imageExtSet) {+ imageExtSet.addAll(imageExtList);+ }+ }++ public static void initAudioExt(final List<String> audioExtList) {+ synchronized (audioExtSet) {+ audioExtSet.addAll(audioExtList);+ }+ }++ public static void initVideoExt(final List<String> videoExtList) {+ synchronized (videoExtSet) {+ videoExtSet.addAll(videoExtList);+ }+ }++ public static void initAppsExt(final List<String> appsExtList) {+ synchronized (appsExtSet) {+ appsExtSet.addAll(appsExtList);+ }+ }++ public static String getMediaExtList() {+ synchronized (mediaExtSet) {+ return mediaExtSet.toString();+ }+ }++ public static void initSupportedHTMLFileExt(final List<String> supportedRealtimeFileExtList) {+ synchronized (supportedHTMLFileExt) {+ supportedHTMLFileExt.addAll(supportedRealtimeFileExtList);+ }+ }++ public static boolean HTMLParsableMimeTypesContains(String mimeType) {+ mimeType = normalizeMimeType(mimeType);+ synchronized (supportedHTMLMimeTypes) {+ return supportedHTMLMimeTypes.contains(mimeType);+ }+ }++ public static boolean supportedHTMLContent(final yacyURL url, final String mimeType) {+ return HTMLParsableMimeTypesContains(mimeType) && supportedHTMLFileExtContains(url);+ }++ public static boolean supportedHTMLFileExtContains(final yacyURL url) {+ final String fileExt = getFileExt(url);+ synchronized (supportedHTMLFileExt) {+ return supportedHTMLFileExt.contains(fileExt);+ }+ }++ public static String getFileExt(final yacyURL url) {+ // getting the file path+ String name = url.getPath();++ // tetermining last position of / in the file path+ int p = name.lastIndexOf('/');+ if (p != -1) {+ name = name.substring(p);+ }++ // termining last position of . in file path+ p = name.lastIndexOf('.');+ if (p < 0) return "";+ return name.substring(p + 1);+ }++ public static boolean mediaExtContains(String mediaExt) {+ if (mediaExt == null) return false;+ mediaExt = mediaExt.trim().toLowerCase();++ synchronized (supportedHTMLFileExt) {+ if (supportedHTMLFileExt.contains(mediaExt)) return false;+ }++ if (supportedFileExtContains(mediaExt)) return false;++ synchronized (mediaExtSet) {+ return mediaExtSet.contains(mediaExt);+ }+ }++ public static boolean imageExtContains(final String imageExt) {+ if (imageExt == null) return false;+ synchronized (imageExtSet) {+ return imageExtSet.contains(imageExt.trim().toLowerCase());+ }+ }++ public static boolean audioExtContains(final String audioExt) {+ if (audioExt == null) return false;+ synchronized (audioExtSet) {+ return audioExtSet.contains(audioExt.trim().toLowerCase());+ }+ }++ public static boolean videoExtContains(final String videoExt) {+ if (videoExt == null) return false;+ synchronized (videoExtSet) {+ return videoExtSet.contains(videoExt.trim().toLowerCase());+ }+ }++ public static boolean appsExtContains(final String appsExt) {+ if (appsExt == null) return false;+ synchronized (appsExtSet) {+ return appsExtSet.contains(appsExt.trim().toLowerCase());+ }+ }++ /**+ * some html authors use wrong encoding names, either because they don't know exactly what they+ * are doing or they produce a type. Many times, the upper/downcase scheme of the name is fuzzy+ * This method patches wrong encoding names. The correct names are taken from+ * http://www.iana.org/assignments/character-sets+ * @param encoding+ * @return patched encoding name+ */+ public static String patchCharsetEncoding(String encoding) {++ // return the system default encoding+ if ((encoding == null) || (encoding.length() < 3)) return Charset.defaultCharset().name();++ // trim encoding string+ encoding = encoding.trim();++ // fix upper/lowercase+ encoding = encoding.toUpperCase();+ if (encoding.startsWith("SHIFT")) return "Shift_JIS";+ if (encoding.startsWith("BIG")) return "Big5";+ // all other names but such with "windows" use uppercase+ if (encoding.startsWith("WINDOWS")) encoding = "windows" + encoding.substring(7);+ if (encoding.startsWith("MACINTOSH")) encoding = "MacRoman";++ // fix wrong fill characters+ encoding = encoding.replaceAll("_", "-");++ if (encoding.matches("GB[_-]?2312([-_]80)?")) return "GB2312";+ if (encoding.matches(".*UTF[-_]?8.*")) return "UTF-8";+ if (encoding.startsWith("US")) return "US-ASCII";+ if (encoding.startsWith("KOI")) return "KOI8-R";++ // patch missing '-'+ if (encoding.startsWith("windows") && encoding.length() > 7) {+ final char c = encoding.charAt(7);+ if ((c >= '0') && (c <= '9')) {+ encoding = "windows-" + encoding.substring(7);+ }+ }++ if (encoding.startsWith("ISO")) {+ // patch typos+ if (encoding.length() > 3) {+ final char c = encoding.charAt(3);+ if ((c >= '0') && (c <= '9')) {+ encoding = "ISO-" + encoding.substring(3);+ }+ }+ if (encoding.length() > 8) {+ final char c = encoding.charAt(8);+ if ((c >= '0') && (c <= '9')) {+ encoding = encoding.substring(0, 8) + "-" + encoding.substring(8);+ }+ }+ }++ // patch wrong name+ if (encoding.startsWith("ISO-8559")) {+ // popular typo+ encoding = "ISO-8859" + encoding.substring(8);+ }++ // converting cp\d{4} -> windows-\d{4}+ if (encoding.matches("CP([_-])?125[0-8]")) {+ final char c = encoding.charAt(2);+ if ((c >= '0') && (c <= '9')) {+ encoding = "windows-" + encoding.substring(2);+ } else {+ encoding = "windows" + encoding.substring(2);+ }+ }++ return encoding;+ }++ public static String normalizeMimeType(String mimeType) {+ //if (mimeType == null) doMimeTypeAnalysis+ if (mimeType == null) mimeType = "application/octet-stream";+ mimeType = mimeType.trim().toLowerCase();++ final int pos = mimeType.indexOf(';');+ return ((pos < 0) ? mimeType : mimeType.substring(0, pos));+ }++ public static String getMimeTypeByFileExt(final String fileExt) {+ return mimeTypeLookupByFileExt.getProperty(fileExt,"application/octet-stream");+ }++ public static HashMap<String, Parser> getAvailableParserList() {+ return availableParserList;+ }++ private static void loadAvailableParserList() {+ initParser(new bzipParser());+ initParser(new docParser());+ initParser(new gzipParser());+ initParser(new mimeTypeParser());+ initParser(new odtParser());+ initParser(new pdfParser());+ initParser(new pptParser());+ initParser(new psParser());+ initParser(new rpmParser());+ initParser(new rssParser());+ initParser(new rtfParser());+ initParser(new sevenzipParser());+ initParser(new swfParser());+ initParser(new tarParser());+ initParser(new vcfParser());+ initParser(new vsdParser());+ initParser(new xlsParser());+ initParser(new zipParser());+ }++ private static void initParser(Parser theParser) {+ // loading the list of mime-types that are supported by this parser class+ final Hashtable<String, String> supportedMimeTypes = theParser.getSupportedMimeTypes();++ final Iterator<String> mimeTypeIterator = supportedMimeTypes.keySet().iterator();+ while (mimeTypeIterator.hasNext()) {+ final String mimeType = mimeTypeIterator.next();+ availableParserList.put(mimeType, theParser);+ Log.logInfo("PARSER", "Found parser for mimeType '" + mimeType + "'." ++ "\n\tName: " + theParser.getName());+ }+ }++ public static Document parseSource(final yacyURL location, final String mimeType, final String charset, final byte[] sourceArray)+ throws InterruptedException, ParserException {+ ByteArrayInputStream byteIn = null;+ try {+ if (theLogger.isFine())+ theLogger.logFine("Parsing '" + location + "' from byte-array");++ // testing if the resource is not empty+ if (sourceArray == null || sourceArray.length == 0) {+ final String errorMsg = "No resource content available (1) " + (((sourceArray == null) ? "source == null" : "source.length() == 0") + ", url = " + location.toNormalform(true, false));+ theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location, errorMsg);+ }++ // creating an InputStream+ byteIn = new ByteArrayInputStream(sourceArray);++ // parsing the temp file+ return parseSource(location, mimeType, charset, sourceArray.length, byteIn);++ } catch (final Exception e) {+ // Interrupted- and Parser-Exceptions should pass through+ if (e instanceof InterruptedException) throw (InterruptedException) e;+ if (e instanceof ParserException) throw (ParserException) e;++ // log unexpected error+ theLogger.logSevere("Unexpected exception in parseSource from byte-array: " + e.getMessage(), e);+ throw new ParserException("Unexpected exception while parsing " + location,location, e);+ } finally {+ if (byteIn != null) try { byteIn.close(); } catch (final Exception ex){/* ignore this */}+ }++ }++ public static Document parseSource(final yacyURL location, final String theMimeType, final String theDocumentCharset, final File sourceFile) throws InterruptedException, ParserException {++ BufferedInputStream sourceStream = null;+ try {+ if (theLogger.isFine())+ theLogger.logFine("Parsing '" + location + "' from file");++ // testing if the resource is not empty+ if (!(sourceFile.exists() && sourceFile.canRead() && sourceFile.length() > 0)) {+ final String errorMsg = sourceFile.exists() ? "Empty resource file." : "No resource content available (2).";+ theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location, "document has no content");+ }++ // create a new InputStream+ sourceStream = new BufferedInputStream(new FileInputStream(sourceFile));++ // parsing the data+ return parseSource(location, theMimeType, theDocumentCharset, sourceFile.length(), sourceStream);++ } catch (final Exception e) {+ // Interrupted- and Parser-Exceptions should pass through+ if (e instanceof InterruptedException) throw (InterruptedException) e;+ if (e instanceof ParserException) throw (ParserException) e;++ // log unexpected error+ theLogger.logSevere("Unexpected exception in parseSource from File: " + e.getMessage(), e);+ throw new ParserException("Unexpected exception while parsing " + location,location, e);+ } finally {+ if (sourceStream != null) try { sourceStream.close(); } catch (final Exception ex){/* ignore this */}+ }+ }++ /**+ * To parse a resource from an {@link InputStream}+ * @param location the URL of the resource+ * @param theMimeType the resource mimetype (<code>null</code> if unknown)+ * @param theDocumentCharset the charset of the resource (<code>null</code> if unknown)+ * @param contentLength the content length of the resource (<code>-1</code> if unknown)+ * @param sourceStream an {@link InputStream} containing the resource body+ * @return the parsed {@link ParserDocument document}+ * @throws InterruptedException+ * @throws ParserException+ */+ public static Document parseSource(final yacyURL location, final String theMimeType, final String theDocumentCharset, final long contentLength, final InputStream sourceStream) throws InterruptedException, ParserException {+ Parser theParser = null;+ String mimeType = null;+ try {+ if (theLogger.isFine())+ theLogger.logFine("Parsing '" + location + "' from stream");++ // getting the mimetype of the document+ mimeType = normalizeMimeType(theMimeType);++ // getting the file extension of the document+ final String fileExt = getFileExt(location);++ // getting the charset of the document+ // TODO: do a charset detection here ....+ final String documentCharset = patchCharsetEncoding(theDocumentCharset);++ // testing if parsing is supported for this resource+ if (!supportedContent(location,mimeType)) {+ final String errorMsg = "No parser available to parse mimetype '" + mimeType + "' (1)";+ theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location, "wrong mime type or wrong extension");+ }++ if (theLogger.isFine())+ theLogger.logInfo("Parsing " + location + " with mimeType '" + mimeType ++ "' and file extension '" + fileExt + "'.");++ // getting the correct parser for the given mimeType+ theParser = getParser(mimeType);++ // if a parser was found we use it ...+ Document doc = null;+ if (theParser != null) {+ // set the content length of the resource+ theParser.setContentLength(contentLength);+ // parse the resource+ doc = theParser.parse(location, mimeType,documentCharset,sourceStream);+ } else if (HTMLParsableMimeTypesContains(mimeType)) {+ doc = parseHtml(location, mimeType, documentCharset, sourceStream);+ } else {+ final String errorMsg = "No parser available to parse mimetype '" + mimeType + "' (2)";+ theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location, "wrong mime type or wrong extension");+ }++ // check result+ if (doc == null) {+ final String errorMsg = "Unexpected error. Parser returned null.";+ theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location);+ }+ return doc;++ } catch (final UnsupportedEncodingException e) {+ final String errorMsg = "unsupported charset encoding: " + e.getMessage();+ theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg, e);+ throw new ParserException(errorMsg,location, errorMsg);+ } catch (final IOException e) {+ // IOExceptions may occur during html parsing when a server closes the connection during reading.+ // This may happen here, because the html parser is a streaming parser+ // that produces surrogates while the connection is active+ final String errorMsg = "IOException - server may have closed the connection. " + e.getMessage();+ theLogger.logWarning("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg, location, errorMsg);+ } catch (final Exception e) {+ // Interrupted- and Parser-Exceptions should pass through+ if (e instanceof InterruptedException) throw (InterruptedException) e;+ if (e instanceof ParserException) throw (ParserException) e;++ // log unexpected error+ final String errorMsg = "Unexpected exception. " + e.getMessage();+ theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg, e);+ throw new ParserException(errorMsg,location,e);++ } finally {+ if (theParser != null) {+ theParser = null; // delete object+ }+ }+ }++ private static Document parseHtml(+ final yacyURL location,+ final String mimeType,+ final String documentCharset,+ final InputStream sourceStream) throws IOException, ParserException {++ // make a scraper and transformer+ final ScraperInputStream htmlFilter = new ScraperInputStream(sourceStream,documentCharset,location,null,false);+ String charset = htmlFilter.detectCharset();+ if (charset == null) {+ charset = documentCharset;+ } else {+ charset = patchCharsetEncoding(charset);+ }++ if (!documentCharset.equalsIgnoreCase(charset)) {+ theLogger.logInfo("Charset transformation needed from '" + documentCharset + "' to '" + charset + "' for URL = " + location.toNormalform(true, true));+ }++ Charset c;+ try {+ c = Charset.forName(charset);+ } catch (IllegalCharsetNameException e) {+ c = Charset.defaultCharset();+ } catch (UnsupportedCharsetException e) {+ c = Charset.defaultCharset();+ }++ // parsing the content+ final ContentScraper scraper = new ContentScraper(location);+ final TransformerWriter writer = new TransformerWriter(null,null,scraper,null,false);+ FileUtils.copy(htmlFilter, writer, c);+ writer.close();+ //OutputStream hfos = new htmlFilterOutputStream(null, scraper, null, false);+ //serverFileUtils.copy(sourceFile, hfos);+ //hfos.close();+ if (writer.binarySuspect()) {+ final String errorMsg = "Binary data found in resource";+ theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg);+ throw new ParserException(errorMsg,location);+ }+ return transformScraper(location, mimeType, documentCharset, scraper);+ }++ public static Document transformScraper(final yacyURL location, final String mimeType, final String charSet, final ContentScraper scraper) {+ final String[] sections = new String[scraper.getHeadlines(1).length + scraper.getHeadlines(2).length + scraper.getHeadlines(3).length + scraper.getHeadlines(4).length];+ int p = 0;+ for (int i = 1; i <= 4; i++) for (int j = 0; j < scraper.getHeadlines(i).length; j++) sections[p++] = scraper.getHeadlines(i)[j];+ final Document ppd = new Document(+ location,+ mimeType,+ charSet,+ scraper.getContentLanguages(),+ scraper.getKeywords(),+ scraper.getTitle(),+ scraper.getAuthor(),+ sections,+ scraper.getDescription(),+ scraper.getText(),+ scraper.getAnchors(),+ scraper.getImages());+ //scraper.close();+ ppd.setFavicon(scraper.getFavicon());+ return ppd;+ }++ /**+ * This function is used to determine the parser class that should be used for a given+ * mimetype ...+ * @param mimeType MIME-Type of the resource+ * @return the {@link Parser}-class that is supposed to parse the resource of+ * the given MIME-Type+ */+ private static Parser getParser(String mimeType) {++ mimeType = normalizeMimeType(mimeType);++ // determining the proper parser class name for the mimeType+ return availableParserList.get(mimeType);+ }++ public static Map<yacyURL, String> allReflinks(final Collection<?> links) {+ // links is either a Set of Strings (with urls) or htmlFilterImageEntries+ // we find all links that are part of a reference inside a url+ final HashMap<yacyURL, String> v = new HashMap<yacyURL, String>();+ final Iterator<?> i = links.iterator();+ Object o;+ yacyURL url;+ String u;+ int pos;+ loop: while (i.hasNext()) try {+ o = i.next();+ if (o instanceof yacyURL) url = (yacyURL) o;+ else if (o instanceof String) url = new yacyURL((String) o, null);+ else if (o instanceof ImageEntry) url = ((ImageEntry) o).url();+ else {+ assert false;+ continue;+ }+ u = url.toNormalform(true, true);+ if ((pos = u.toLowerCase().indexOf("http://",7)) > 0) {+ i.remove();+ u = u.substring(pos);+ while ((pos = u.toLowerCase().indexOf("http://",7)) > 0) u = u.substring(pos);+ url = new yacyURL(u, null);+ if (!(v.containsKey(url))) v.put(url, "ref");+ continue loop;+ }+ if ((pos = u.toLowerCase().indexOf("/www.",7)) > 0) {+ i.remove();+ u = "http:/" + u.substring(pos);+ while ((pos = u.toLowerCase().indexOf("/www.",7)) > 0) u = "http:/" + u.substring(pos);+ url = new yacyURL(u, null);+ if (!(v.containsKey(url))) v.put(url, "ref");+ continue loop;+ }+ } catch (final MalformedURLException e) {}+ return v;+ }++ static Map<yacyURL, String> allSubpaths(final Collection<?> links) {+ // links is either a Set of Strings (urls) or a Set of htmlFilterImageEntries+ final HashSet<String> h = new HashSet<String>();+ Iterator<?> i = links.iterator();+ Object o;+ yacyURL url;+ String u;+ int pos;+ int l;+ while (i.hasNext()) try {+ o = i.next();+ if (o instanceof yacyURL) url = (yacyURL) o;+ else if (o instanceof String) url = new yacyURL((String) o, null);+ else if (o instanceof ImageEntry) url = ((ImageEntry) o).url();+ else {+ assert false;+ continue;+ }+ u = url.toNormalform(true, true);+ if (u.endsWith("/")) u = u.substring(0, u.length() - 1);+ pos = u.lastIndexOf('/');+ while (pos > 8) {+ l = u.length();+ u = u.substring(0, pos + 1);+ h.add(u);+ u = u.substring(0, pos);+ assert (u.length() < l) : "u = " + u;+ pos = u.lastIndexOf('/');+ }+ } catch (final MalformedURLException e) {}+ // now convert the strings to yacyURLs+ i = h.iterator();+ final HashMap<yacyURL, String> v = new HashMap<yacyURL, String>();+ while (i.hasNext()) {+ u = (String) i.next();+ try {+ url = new yacyURL(u, null);+ v.put(url, "sub");+ } catch (final MalformedURLException e) {}+ }+ return v;+ }++ public static boolean supportedContent(final yacyURL url, final String mimeType) {+ if (url == null) throw new NullPointerException();++ if (parserConfig.supportedContent(url, mimeType)) return true;++ return false;+ }++ public static void addParseableMimeTypes(final String configStr) {+ parserConfig.addParseableMimeTypes(configStr);+ }++ public static String[] setEnabledParserList(final Set<String> mimeTypeSet) {+ return parserConfig.setEnabledParserList(mimeTypeSet);+ }++ public static boolean supportedFileExtContains(final String fileExt) {+ return parserConfig.supportedFileExtContains(fileExt);+ }++ public static boolean supportedMimeTypesContains(final String mimeType) {+ return parserConfig.supportedMimeTypesContains(mimeType);+ }++}diff --git a/source/de/anomic/plasma/parser/ParserException.java b/source/de/anomic/document/ParserException.javasimilarity index 95%rename from source/de/anomic/plasma/parser/ParserException.javarename to source/de/anomic/document/ParserException.javaindex e2cd81dd0..01a6a20cb 100644--- a/source/de/anomic/plasma/parser/ParserException.java+++ b/source/de/anomic/document/ParserException.java@@ -22,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser;+package de.anomic.document;import de.anomic.yacy.yacyURL;diff --git a/source/de/anomic/plasma/parser/Phrase.java b/source/de/anomic/document/Phrase.javasimilarity index 94%rename from source/de/anomic/plasma/parser/Phrase.javarename to source/de/anomic/document/Phrase.javaindex d8eaf5cd9..863adf1de 100644--- a/source/de/anomic/plasma/parser/Phrase.java+++ b/source/de/anomic/document/Phrase.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser;+package de.anomic.document;import java.util.HashSet;diff --git a/source/de/anomic/plasma/parser/Word.java b/source/de/anomic/document/Word.javasimilarity index 96%rename from source/de/anomic/plasma/parser/Word.javarename to source/de/anomic/document/Word.javaindex fd65fd07a..7e72d1c66 100644--- a/source/de/anomic/plasma/parser/Word.java+++ b/source/de/anomic/document/Word.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser;+package de.anomic.document;import java.util.HashSet;import java.util.Iterator;diff --git a/source/de/anomic/plasma/parser/mimeType/odtDetector.java b/source/de/anomic/document/detector/odtDetector.javasimilarity index 93%rename from source/de/anomic/plasma/parser/mimeType/odtDetector.javarename to source/de/anomic/document/detector/odtDetector.javaindex b49525ba2..6fd9362c4 100644--- a/source/de/anomic/plasma/parser/mimeType/odtDetector.java+++ b/source/de/anomic/document/detector/odtDetector.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.mimeType;+package de.anomic.document.detector;import java.io.File;import java.io.IOException;diff --git a/source/de/anomic/plasma/parser/mimeType/rssDetector.java b/source/de/anomic/document/detector/rssDetector.javasimilarity index 93%rename from source/de/anomic/plasma/parser/mimeType/rssDetector.javarename to source/de/anomic/document/detector/rssDetector.javaindex 583448eca..c60d1dd8c 100644--- a/source/de/anomic/plasma/parser/mimeType/rssDetector.java+++ b/source/de/anomic/document/detector/rssDetector.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.mimeType;+package de.anomic.document.detector;import java.io.ByteArrayInputStream;import java.io.File;diff --git a/source/de/anomic/language/identification/Identificator.java b/source/de/anomic/document/language/Identificator.javasimilarity index 99%rename from source/de/anomic/language/identification/Identificator.javarename to source/de/anomic/document/language/Identificator.javaindex 3f5fe217e..80b0b3089 100644--- a/source/de/anomic/language/identification/Identificator.java+++ b/source/de/anomic/document/language/Identificator.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.language.identification;+package de.anomic.document.language;import java.util.HashMap;import java.util.Iterator;diff --git a/source/de/anomic/language/identification/LanguageFilenameFilter.java b/source/de/anomic/document/language/LanguageFilenameFilter.javasimilarity index 96%rename from source/de/anomic/language/identification/LanguageFilenameFilter.javarename to source/de/anomic/document/language/LanguageFilenameFilter.javaindex 394c7c0a1..8fb06cdd0 100644--- a/source/de/anomic/language/identification/LanguageFilenameFilter.java+++ b/source/de/anomic/document/language/LanguageFilenameFilter.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.language.identification;+package de.anomic.document.language;import java.io.File;import java.io.FilenameFilter;diff --git a/source/de/anomic/language/identification/LanguageStatistics.java b/source/de/anomic/document/language/LanguageStatistics.javasimilarity index 99%rename from source/de/anomic/language/identification/LanguageStatistics.javarename to source/de/anomic/document/language/LanguageStatistics.javaindex ff6e14d64..289c3f9e0 100644--- a/source/de/anomic/language/identification/LanguageStatistics.java+++ b/source/de/anomic/document/language/LanguageStatistics.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.language.identification;+package de.anomic.document.language;import java.io.BufferedReader;import java.io.File;diff --git a/source/de/anomic/language/identification/LanguageStatisticsHolder.java b/source/de/anomic/document/language/LanguageStatisticsHolder.javasimilarity index 98%rename from source/de/anomic/language/identification/LanguageStatisticsHolder.javarename to source/de/anomic/document/language/LanguageStatisticsHolder.javaindex 1be45875b..40d54b4a3 100644--- a/source/de/anomic/language/identification/LanguageStatisticsHolder.java+++ b/source/de/anomic/document/language/LanguageStatisticsHolder.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.language.identification;+package de.anomic.document.language;import java.io.File;import java.io.FilenameFilter;diff --git a/source/de/anomic/plasma/parser/bzip/bzipParser.java b/source/de/anomic/document/parser/bzipParser.javasimilarity index 78%rename from source/de/anomic/plasma/parser/bzip/bzipParser.javarename to source/de/anomic/document/parser/bzipParser.javaindex 10dd461bf..e60bc9a52 100644--- a/source/de/anomic/plasma/parser/bzip/bzipParser.java+++ b/source/de/anomic/document/parser/bzipParser.java@@ -6,11 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$-//+//last major change: 16.05.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@@ -26,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.bzip;+package de.anomic.document.parser;import java.io.File;import java.io.FileOutputStream;@@ -35,12 +31,12 @@ import java.util.Hashtable;import org.apache.tools.bzip2.CBZip2InputStream;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.FileUtils;-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;import de.anomic.yacy.yacyURL;public class bzipParser extends AbstractParser implements Parser {@@ -50,15 +46,11 @@ public class bzipParser extends AbstractParser implements Parser {* @see #getSupportedMimeTypes()*/public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static final String fileExtensions = "bz2,tbz,tbz2";+ static String fileExtensions = "bz2,tbz,tbz2";static {SUPPORTED_MIME_TYPES.put("application/x-bzip2",fileExtensions);SUPPORTED_MIME_TYPES.put("application/bzip2", fileExtensions);SUPPORTED_MIME_TYPES.put("application/x-bz2", fileExtensions);- SUPPORTED_MIME_TYPES.put("application/octet-stream",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-bzip",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-compressed",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-stuffit",fileExtensions);}/**@@ -76,7 +68,7 @@ public class bzipParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {File tempFile = null;try {@@ -114,8 +106,7 @@ public class bzipParser extends AbstractParser implements Parser {checkInterruption();// creating a new parser class to parse the unzipped content- final plasmaParser theParser = new plasmaParser();- return theParser.parseSource(location,null,null,tempFile);+ return ParserDispatcher.parseSource(location,null,null,tempFile);} catch (final Exception e) {if (e instanceof InterruptedException) throw (InterruptedException) e;if (e instanceof ParserException) throw (ParserException) e;@@ -126,7 +117,6 @@ public class bzipParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/doc/docParser.java b/source/de/anomic/document/parser/docParser.javasimilarity index 73%rename from source/de/anomic/plasma/parser/doc/docParser.javarename to source/de/anomic/document/parser/docParser.javaindex 4abc2cc6a..65beb246b 100644--- a/source/de/anomic/plasma/parser/doc/docParser.java+++ b/source/de/anomic/document/parser/docParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.doc;+package de.anomic.document.parser;import java.io.InputStream;import java.util.Hashtable;@@ -33,10 +30,10 @@ import java.util.Hashtable;import org.textmining.extraction.TextExtractor;import org.textmining.extraction.word.WordTextExtractorFactory;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;public class docParser extends AbstractParser implements Parser {@@ -46,17 +43,7 @@ public class docParser extends AbstractParser implements Parser {* @see #getSupportedMimeTypes()*/public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static {- SUPPORTED_MIME_TYPES.put("application/msword","doc");- SUPPORTED_MIME_TYPES.put("application/doc","doc");- SUPPORTED_MIME_TYPES.put("appl/text","doc");- SUPPORTED_MIME_TYPES.put("application/vnd.msword","doc");- SUPPORTED_MIME_TYPES.put("application/vnd.ms-word","doc");- SUPPORTED_MIME_TYPES.put("application/winword","doc");- SUPPORTED_MIME_TYPES.put("application/word","doc");- SUPPORTED_MIME_TYPES.put("application/x-msw6","doc");- SUPPORTED_MIME_TYPES.put("application/x-msword","doc");- }+ static { SUPPORTED_MIME_TYPES.put("application/msword","doc"); }/*** a list of library names that are needed by this parser@@ -71,7 +58,7 @@ public class docParser extends AbstractParser implements Parser {this.parserName = "Word Document Parser";}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,+ public Document parse(final yacyURL location, final String mimeType, final String charset,final InputStream source) throws ParserException, InterruptedException {@@ -87,7 +74,7 @@ public class docParser extends AbstractParser implements Parser {if (title.length() == l) break;l = title.length();}- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -102,7 +89,8 @@ public class docParser extends AbstractParser implements Parser {null);return theDoc;- } catch (final Exception e) {+ } catch (final Exception e) {+ e.printStackTrace();if (e instanceof InterruptedException) throw (InterruptedException) e;if (e instanceof ParserException) throw (ParserException) e;@@ -114,7 +102,6 @@ public class docParser extends AbstractParser implements Parser {return docParser.SUPPORTED_MIME_TYPES;}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/gzip/gzipParser.java b/source/de/anomic/document/parser/gzipParser.javasimilarity index 67%rename from source/de/anomic/plasma/parser/gzip/gzipParser.javarename to source/de/anomic/document/parser/gzipParser.javaindex 5ed07c189..611177580 100644--- a/source/de/anomic/plasma/parser/gzip/gzipParser.java+++ b/source/de/anomic/document/parser/gzipParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.gzip;+package de.anomic.document.parser;import java.io.File;import java.io.FileOutputStream;@@ -33,12 +30,12 @@ import java.io.InputStream;import java.util.Hashtable;import java.util.zip.GZIPInputStream;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.FileUtils;-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;import de.anomic.yacy.yacyURL;public class gzipParser extends AbstractParser implements Parser {@@ -47,19 +44,10 @@ public class gzipParser extends AbstractParser implements Parser {* a list of mime types that are supported by this parser class* @see #getSupportedMimeTypes()*/- public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static final String fileExtensions = "gz,tgz";+ public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();static {- SUPPORTED_MIME_TYPES.put("application/x-gzip",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/gzip",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-gunzip",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/gzipped",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/gzip-compressed",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-compressed",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-compress",fileExtensions);- SUPPORTED_MIME_TYPES.put("gzip/document",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/octet-stream",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-tar",fileExtensions);+ SUPPORTED_MIME_TYPES.put("application/x-gzip","gz,tgz");+ SUPPORTED_MIME_TYPES.put("application/gzip","gz,tgz");}/**@@ -77,7 +65,7 @@ public class gzipParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {File tempFile = null;try {@@ -103,8 +91,7 @@ public class gzipParser extends AbstractParser implements Parser {checkInterruption();// creating a new parser class to parse the unzipped content- final plasmaParser theParser = new plasmaParser();- return theParser.parseSource(location,null,null,tempFile);+ return ParserDispatcher.parseSource(location,null,null,tempFile);} catch (final Exception e) {if (e instanceof InterruptedException) throw (InterruptedException) e;if (e instanceof ParserException) throw (ParserException) e;@@ -115,7 +102,6 @@ public class gzipParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.java b/source/de/anomic/document/parser/html/AbstractScraper.javasimilarity index 89%rename from source/de/anomic/htmlFilter/htmlFilterAbstractScraper.javarename to source/de/anomic/document/parser/html/AbstractScraper.javaindex 09b980784..a1cf72640 100644--- a/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.java+++ b/source/de/anomic/document/parser/html/AbstractScraper.java@@ -24,12 +24,12 @@// MUST CONTAIN THE INTACT AND UNCHANGED COPYRIGHT NOTICE.// CONTRIBUTIONS AND CHANGES TO THE PROGRAM CODE SHOULD BE MARKED AS SUCH.-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.util.HashSet;import java.util.Properties;-public abstract class htmlFilterAbstractScraper implements htmlFilterScraper {+public abstract class AbstractScraper implements Scraper {public static final char lb = '<';public static final char rb = '>';@@ -43,7 +43,7 @@ public abstract class htmlFilterAbstractScraper implements htmlFilterScraper {* @param tags0* @param tags1*/- public htmlFilterAbstractScraper(final HashSet<String> tags0, final HashSet<String> tags1) {+ public AbstractScraper(final HashSet<String> tags0, final HashSet<String> tags1) {this.tags0 = tags0;this.tags1 = tags1;}@@ -83,7 +83,7 @@ public abstract class htmlFilterAbstractScraper implements htmlFilterScraper {}public static String stripAll(String s) {- return htmlFilterCharacterCoding.html2unicode(stripAllTags(s));+ return CharacterCoding.html2unicode(stripAllTags(s));}public void close() {diff --git a/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.java b/source/de/anomic/document/parser/html/AbstractTransformer.javasimilarity index 82%rename from source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.javarename to source/de/anomic/document/parser/html/AbstractTransformer.javaindex e67e057e2..f418f8fcf 100644--- a/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.java+++ b/source/de/anomic/document/parser/html/AbstractTransformer.java@@ -19,17 +19,17 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.util.Properties;import java.util.TreeSet;-public abstract class htmlFilterAbstractTransformer implements htmlFilterTransformer {+public abstract class AbstractTransformer implements Transformer {private TreeSet<String> tags0;private TreeSet<String> tags1;- public htmlFilterAbstractTransformer(final TreeSet<String> tags0, final TreeSet<String> tags1) {+ public AbstractTransformer(final TreeSet<String> tags0, final TreeSet<String> tags1) {this.tags0 = tags0;this.tags1 = tags1;}@@ -52,11 +52,11 @@ public abstract class htmlFilterAbstractTransformer implements htmlFilterTransfo// the other methods must take into account to construct the return value correctlypublic char[] transformTag0(final String tagname, final Properties tagopts, final char quotechar) {- return htmlFilterWriter.genTag0(tagname, tagopts, quotechar);+ return TransformerWriter.genTag0(tagname, tagopts, quotechar);}public char[] transformTag1(final String tagname, final Properties tagopts, final char[] text, final char quotechar) {- return htmlFilterWriter.genTag1(tagname, tagopts, text, quotechar);+ return TransformerWriter.genTag1(tagname, tagopts, text, quotechar);}public void close() {diff --git a/source/de/anomic/htmlFilter/htmlFilterCharacterCoding.java b/source/de/anomic/document/parser/html/CharacterCoding.javasimilarity index 99%rename from source/de/anomic/htmlFilter/htmlFilterCharacterCoding.javarename to source/de/anomic/document/parser/html/CharacterCoding.javaindex 701a6d879..55f0180a7 100644--- a/source/de/anomic/htmlFilter/htmlFilterCharacterCoding.java+++ b/source/de/anomic/document/parser/html/CharacterCoding.java@@ -18,11 +18,11 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.util.HashMap;-public class htmlFilterCharacterCoding {+public class CharacterCoding {private static final char amp_unicode = "\u0026".charAt(0);private static final String amp_html = "&";diff --git a/source/de/anomic/htmlFilter/htmlFilterContentScraper.java b/source/de/anomic/document/parser/html/ContentScraper.javasimilarity index 83%rename from source/de/anomic/htmlFilter/htmlFilterContentScraper.javarename to source/de/anomic/document/parser/html/ContentScraper.javaindex e4f704b7e..a3c7f5354 100644--- a/source/de/anomic/htmlFilter/htmlFilterContentScraper.java+++ b/source/de/anomic/document/parser/html/ContentScraper.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.io.ByteArrayInputStream;import java.io.File;@@ -45,16 +45,16 @@ import java.util.Properties;import javax.swing.event.EventListenerList;import de.anomic.crawler.HTTPLoader;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParser;import de.anomic.server.serverCharBuffer;import de.anomic.yacy.yacyURL;import de.anomic.tools.iso639;-public class htmlFilterContentScraper extends htmlFilterAbstractScraper implements htmlFilterScraper {+public class ContentScraper extends AbstractScraper implements Scraper {// statics: for initialization of the HTMLFilterAbstractScraperprivate static final HashSet<String> linkTags0 = new HashSet<String>(9,0.99f);@@ -81,7 +81,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemen// class variables: collectors for linksprivate HashMap<yacyURL, String> anchors;- private HashMap<String, htmlFilterImageEntry> images; // urlhash/image relation+ private HashMap<String, ImageEntry> images; // urlhash/image relationprivate final HashMap<String, String> metas;private String title;//private String headline;@@ -100,13 +100,13 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenprivate yacyURL root;@SuppressWarnings("unchecked")- public htmlFilterContentScraper(final yacyURL root) {+ public ContentScraper(final yacyURL root) {// the root value here will not be used to load the resource.// it is only the reference for relative linkssuper(linkTags0, linkTags1);this.root = root;this.anchors = new HashMap<yacyURL, String>();- this.images = new HashMap<String, htmlFilterImageEntry>();+ this.images = new HashMap<String, ImageEntry>();this.metas = new HashMap<String, String>();this.title = "";this.headlines = new ArrayList[4];@@ -158,7 +158,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenfinal float ratio = (float) Math.min(width, height) / Math.max(width, height);if (ratio > 0.4) {final yacyURL url = absolutePath(tagopts.getProperty("src", ""));- final htmlFilterImageEntry ie = new htmlFilterImageEntry(url, tagopts.getProperty("alt", ""), width, height);+ final ImageEntry ie = new ImageEntry(url, tagopts.getProperty("alt", ""), width, height);addImage(images, ie);}// i think that real pictures have witdth & height tags - thq@@ -178,11 +178,11 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenif (tagname.equalsIgnoreCase("meta")) {String name = tagopts.getProperty("name", "");if (name.length() > 0) {- metas.put(name.toLowerCase(), htmlFilterCharacterCoding.html2unicode(tagopts.getProperty("content","")));+ metas.put(name.toLowerCase(), CharacterCoding.html2unicode(tagopts.getProperty("content","")));} else {name = tagopts.getProperty("http-equiv", "");if (name.length() > 0) {- metas.put(name.toLowerCase(), htmlFilterCharacterCoding.html2unicode(tagopts.getProperty("content","")));+ metas.put(name.toLowerCase(), CharacterCoding.html2unicode(tagopts.getProperty("content","")));}}}@@ -200,7 +200,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenfinal String linktitle = tagopts.getProperty("title", "");if (type.equalsIgnoreCase("shortcut icon")) {- final htmlFilterImageEntry ie = new htmlFilterImageEntry(newLink, linktitle, -1,-1);+ final ImageEntry ie = new ImageEntry(newLink, linktitle, -1,-1);images.put(ie.url().hash(), ie);this.favicon = newLink;} else if (!type.equalsIgnoreCase("stylesheet") && !type.equalsIgnoreCase("alternate stylesheet")) {@@ -235,7 +235,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenfinal String type = (p < 0) ? "" : f.substring(p + 1);if (type.equals("png") || type.equals("gif") || type.equals("jpg") || type.equals("jpeg")) {// special handling of such urls: put them to the image urls- final htmlFilterImageEntry ie = new htmlFilterImageEntry(url, super.stripAll(new String(text)).trim(), -1, -1);+ final ImageEntry ie = new ImageEntry(url, super.stripAll(new String(text)).trim(), -1, -1);addImage(images, ie);} else {anchors.put(url, super.stripAll(new String(text)).trim());@@ -338,7 +338,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenreturn anchors;}- public HashMap<String, htmlFilterImageEntry> getImages() {+ public HashMap<String, ImageEntry> getImages() {// this resturns a String(absolute url)/htmlFilterImageEntry - relationreturn images;}@@ -463,23 +463,23 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenSystem.out.println("TEXT :" + content.toString());}- public void registerHtmlFilterEventListener(final htmlFilterEventListener listener) {+ public void registerHtmlFilterEventListener(final ScraperListener listener) {if (listener != null) {- this.htmlFilterEventListeners.add(htmlFilterEventListener.class, listener);+ this.htmlFilterEventListeners.add(ScraperListener.class, listener);}}- public void deregisterHtmlFilterEventListener(final htmlFilterEventListener listener) {+ public void deregisterHtmlFilterEventListener(final ScraperListener listener) {if (listener != null) {- this.htmlFilterEventListeners.remove(htmlFilterEventListener.class, listener);+ this.htmlFilterEventListeners.remove(ScraperListener.class, listener);}}private void fireScrapeTag0(final String tagname, final Properties tagopts) {final Object[] listeners = this.htmlFilterEventListeners.getListenerList();for (int i=0; i<listeners.length; i+=2) {- if (listeners[i]==htmlFilterEventListener.class) {- ((htmlFilterEventListener)listeners[i+1]).scrapeTag0(tagname, tagopts);+ if (listeners[i]==ScraperListener.class) {+ ((ScraperListener)listeners[i+1]).scrapeTag0(tagname, tagopts);}}}@@ -487,43 +487,43 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenprivate void fireScrapeTag1(final String tagname, final Properties tagopts, final char[] text) {final Object[] listeners = this.htmlFilterEventListeners.getListenerList();for (int i=0; i<listeners.length; i+=2) {- if (listeners[i]==htmlFilterEventListener.class) {- ((htmlFilterEventListener)listeners[i+1]).scrapeTag1(tagname, tagopts, text);+ if (listeners[i]==ScraperListener.class) {+ ((ScraperListener)listeners[i+1]).scrapeTag1(tagname, tagopts, text);}}}- public static htmlFilterContentScraper parseResource(final File file) throws IOException {+ public static ContentScraper parseResource(final File file) throws IOException {// load pagefinal byte[] page = FileUtils.read(file);if (page == null) throw new IOException("no content in file " + file.toString());// scrape document to look up charset- final htmlFilterInputStream htmlFilter = new htmlFilterInputStream(new ByteArrayInputStream(page),"UTF-8",new yacyURL("http://localhost", null),null,false);- final String charset = plasmaParser.patchCharsetEncoding(htmlFilter.detectCharset());+ final ScraperInputStream htmlFilter = new ScraperInputStream(new ByteArrayInputStream(page),"UTF-8",new yacyURL("http://localhost", null),null,false);+ final String charset = ParserDispatcher.patchCharsetEncoding(htmlFilter.detectCharset());// scrape content- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL("http://localhost", null));- final Writer writer = new htmlFilterWriter(null, null, scraper, null, false);+ final ContentScraper scraper = new ContentScraper(new yacyURL("http://localhost", null));+ final Writer writer = new TransformerWriter(null, null, scraper, null, false);FileUtils.copy(new ByteArrayInputStream(page), writer, Charset.forName(charset));return scraper;}- public static htmlFilterContentScraper parseResource(final yacyURL location) throws IOException {+ public static ContentScraper parseResource(final yacyURL location) throws IOException {// load pagefinal httpRequestHeader reqHeader = new httpRequestHeader();reqHeader.put(httpHeader.USER_AGENT, HTTPLoader.crawlerUserAgent);return parseResource(location, reqHeader);}- public static htmlFilterContentScraper parseResource(final yacyURL location, final httpRequestHeader reqHeader) throws IOException {+ public static ContentScraper parseResource(final yacyURL location, final httpRequestHeader reqHeader) throws IOException {final Reader pageReader = httpClient.wgetReader(location.toString(), reqHeader, 10000);if (pageReader == null) throw new IOException("no response from url " + location.toString());// scrape content- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(location);- final Writer writer = new htmlFilterWriter(null, null, scraper, null, false);+ final ContentScraper scraper = new ContentScraper(location);+ final Writer writer = new TransformerWriter(null, null, scraper, null, false);try {FileUtils.copy(pageReader, writer);} finally {@@ -533,16 +533,16 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenreturn scraper;}- public static void addAllImages(final HashMap<String, htmlFilterImageEntry> a, final HashMap<String, htmlFilterImageEntry> b) {- final Iterator<Map.Entry<String, htmlFilterImageEntry>> i = b.entrySet().iterator();- Map.Entry<String, htmlFilterImageEntry> ie;+ public static void addAllImages(final HashMap<String, ImageEntry> a, final HashMap<String, ImageEntry> b) {+ final Iterator<Map.Entry<String, ImageEntry>> i = b.entrySet().iterator();+ Map.Entry<String, ImageEntry> ie;while (i.hasNext()) {ie = i.next();addImage(a, ie.getValue());}}- public static void addImage(final HashMap<String, htmlFilterImageEntry> a, final htmlFilterImageEntry ie) {+ public static void addImage(final HashMap<String, ImageEntry> a, final ImageEntry ie) {if (a.containsKey(ie.url().hash())) {// in case of a collision, take that image that has the better image size tagsif ((ie.height() > 0) && (ie.width() > 0)) a.put(ie.url().hash(), ie);diff --git a/source/de/anomic/htmlFilter/htmlFilterContentTransformer.java b/source/de/anomic/document/parser/html/ContentTransformer.javasimilarity index 92%rename from source/de/anomic/htmlFilter/htmlFilterContentTransformer.javarename to source/de/anomic/document/parser/html/ContentTransformer.javaindex fb0c80048..69d79523d 100644--- a/source/de/anomic/htmlFilter/htmlFilterContentTransformer.java+++ b/source/de/anomic/document/parser/html/ContentTransformer.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.io.BufferedReader;import java.io.File;@@ -38,7 +38,7 @@ import de.anomic.http.httpTemplate;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.server.serverCharBuffer;-public class htmlFilterContentTransformer extends htmlFilterAbstractTransformer implements htmlFilterTransformer {+public class ContentTransformer extends AbstractTransformer implements Transformer {// statics: for initialisation of the HTMLFilterAbstractTransformerprivate static final Collator insensitiveCollator = Collator.getInstance(Locale.US);@@ -59,7 +59,7 @@ public class htmlFilterContentTransformer extends htmlFilterAbstractTransformerprivate ArrayList<String> bluelist = null;- public htmlFilterContentTransformer() {+ public ContentTransformer() {super(linkTags0, linkTags1);}@@ -159,13 +159,13 @@ public class htmlFilterContentTransformer extends htmlFilterAbstractTransformer// rewrite button nametagopts.setProperty("value", new String(transformText(tagopts.getProperty("value", "").toCharArray())));}- return htmlFilterWriter.genTag0(tagname, tagopts, quotechar);+ return TransformerWriter.genTag0(tagname, tagopts, quotechar);}public char[] transformTag1(final String tagname, final Properties tagopts, final char[] text, final char quotechar) {if (bluelistHit(tagopts.getProperty("href","").toCharArray())) return genBlueLetters(text.length);if (bluelistHit(text)) return genBlueLetters(text.length);- return htmlFilterWriter.genTag1(tagname, tagopts, text, quotechar);+ return TransformerWriter.genTag1(tagname, tagopts, text, quotechar);}public void close() {diff --git a/source/de/anomic/htmlFilter/htmlFilterImageEntry.java b/source/de/anomic/document/parser/html/ImageEntry.javasimilarity index 85%rename from source/de/anomic/htmlFilter/htmlFilterImageEntry.javarename to source/de/anomic/document/parser/html/ImageEntry.javaindex 9029005d9..bbcdb3a41 100644--- a/source/de/anomic/htmlFilter/htmlFilterImageEntry.java+++ b/source/de/anomic/document/parser/html/ImageEntry.java@@ -19,17 +19,17 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import de.anomic.yacy.yacyURL;-public class htmlFilterImageEntry implements Comparable<htmlFilterImageEntry> {+public class ImageEntry implements Comparable<ImageEntry> {private final yacyURL url;private final String alt;private final int width, height;- public htmlFilterImageEntry(final yacyURL url, final String alt, final int width, final int height) {+ public ImageEntry(final yacyURL url, final String alt, final int width, final int height) {this.url = url;this.alt = alt;this.width = width;@@ -66,7 +66,7 @@ public class htmlFilterImageEntry implements Comparable<htmlFilterImageEntry> {return ((0x7FFF - (((width * height) >> 9) & 0x7FFF)) << 16) | (url.hashCode() & 0xFFFF);}- public int compareTo(final htmlFilterImageEntry h) {+ public int compareTo(final ImageEntry h) {// this is needed if this object is stored in a TreeSet// this method uses the image-size ordering from the hashCode method// assuming that hashCode would return a 'perfect hash' this method would@@ -81,8 +81,8 @@ public class htmlFilterImageEntry implements Comparable<htmlFilterImageEntry> {}public boolean equals(final Object o) {- if(o != null && o instanceof htmlFilterImageEntry) {- return compareTo((htmlFilterImageEntry) o) == 0;+ if(o != null && o instanceof ImageEntry) {+ return compareTo((ImageEntry) o) == 0;}return super.equals(o);}diff --git a/source/de/anomic/htmlFilter/htmlFilterScraper.java b/source/de/anomic/document/parser/html/Scraper.javasimilarity index 82%rename from source/de/anomic/htmlFilter/htmlFilterScraper.javarename to source/de/anomic/document/parser/html/Scraper.javaindex 08792172b..84ddd105f 100644--- a/source/de/anomic/htmlFilter/htmlFilterScraper.java+++ b/source/de/anomic/document/parser/html/Scraper.java@@ -19,11 +19,11 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.util.Properties;-public interface htmlFilterScraper {+public interface Scraper {public boolean isTag0(String tag);@@ -37,7 +37,7 @@ public interface htmlFilterScraper {public void close();- public void registerHtmlFilterEventListener(htmlFilterEventListener listener);+ public void registerHtmlFilterEventListener(ScraperListener listener);- public void deregisterHtmlFilterEventListener(htmlFilterEventListener listener);+ public void deregisterHtmlFilterEventListener(ScraperListener listener);}diff --git a/source/de/anomic/htmlFilter/htmlFilterInputStream.java b/source/de/anomic/document/parser/html/ScraperInputStream.javasimilarity index 91%rename from source/de/anomic/htmlFilter/htmlFilterInputStream.javarename to source/de/anomic/document/parser/html/ScraperInputStream.javaindex 5d28f6537..f9181d192 100644--- a/source/de/anomic/htmlFilter/htmlFilterInputStream.java+++ b/source/de/anomic/document/parser/html/ScraperInputStream.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.io.BufferedInputStream;import java.io.IOException;@@ -37,7 +37,7 @@ import java.util.Properties;import de.anomic.yacy.yacyURL;-public class htmlFilterInputStream extends InputStream implements htmlFilterEventListener {+public class ScraperInputStream extends InputStream implements ScraperListener {private static final int MODE_PRESCAN = 0;private static final int MODE_PRESCAN_FINISHED = 1;@@ -54,18 +54,18 @@ public class htmlFilterInputStream extends InputStream implements htmlFilterEvenprivate Reader reader;private Writer writer;- public htmlFilterInputStream(+ public ScraperInputStream(final InputStream inStream,final String inputStreamCharset,final yacyURL rooturl,- final htmlFilterTransformer transformer,+ final Transformer transformer,final boolean passbyIfBinarySuspect) {// create a input stream for buffereingthis.bufferedIn = new BufferedInputStream(inStream,(int) preBufferSize);this.bufferedIn.mark((int) preBufferSize);- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(rooturl);+ final ContentScraper scraper = new ContentScraper(rooturl);scraper.registerHtmlFilterEventListener(this);try {@@ -78,7 +78,7 @@ public class htmlFilterInputStream extends InputStream implements htmlFilterEventhis.reader = new InputStreamReader(this);}}- this.writer = new htmlFilterWriter(null,null,scraper,transformer,passbyIfBinarySuspect);+ this.writer = new TransformerWriter(null,null,scraper,transformer,passbyIfBinarySuspect);}private static String extractCharsetFromMimetypeHeader(final String mimeType) {diff --git a/source/de/anomic/htmlFilter/htmlFilterEventListener.java b/source/de/anomic/document/parser/html/ScraperListener.javasimilarity index 56%rename from source/de/anomic/htmlFilter/htmlFilterEventListener.javarename to source/de/anomic/document/parser/html/ScraperListener.javaindex ceb26f856..1d68fc6d5 100644--- a/source/de/anomic/htmlFilter/htmlFilterEventListener.java+++ b/source/de/anomic/document/parser/html/ScraperListener.java@@ -1,9 +1,8 @@-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;-import java.util.EventListener;import java.util.Properties;-public interface htmlFilterEventListener extends EventListener {+public interface ScraperListener extends java.util.EventListener {public void scrapeTag0(String tagname, Properties tagopts);public void scrapeTag1(String tagname, Properties tagopts, char[] text);}diff --git a/source/de/anomic/htmlFilter/htmlFilterTransformer.java b/source/de/anomic/document/parser/html/Transformer.javasimilarity index 94%rename from source/de/anomic/htmlFilter/htmlFilterTransformer.javarename to source/de/anomic/document/parser/html/Transformer.javaindex 9328e0215..4bc8cd176 100644--- a/source/de/anomic/htmlFilter/htmlFilterTransformer.java+++ b/source/de/anomic/document/parser/html/Transformer.java@@ -19,11 +19,11 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.util.Properties;-public interface htmlFilterTransformer {+public interface Transformer {// the init method is used to initialize the transformer with some values// i.e. the initarg - String can be the name of a file which may containdiff --git a/source/de/anomic/htmlFilter/htmlFilterWriter.java b/source/de/anomic/document/parser/html/TransformerWriter.javasimilarity index 95%rename from source/de/anomic/htmlFilter/htmlFilterWriter.javarename to source/de/anomic/document/parser/html/TransformerWriter.javaindex be7a5e6a7..05b127767 100644--- a/source/de/anomic/htmlFilter/htmlFilterWriter.java+++ b/source/de/anomic/document/parser/html/TransformerWriter.java@@ -29,7 +29,7 @@*/-package de.anomic.htmlFilter;+package de.anomic.document.parser.html;import java.io.File;import java.io.FileOutputStream;@@ -47,7 +47,7 @@ import java.util.Properties;import de.anomic.server.serverCharBuffer;import de.anomic.yacy.yacyURL;-public final class htmlFilterWriter extends Writer {+public final class TransformerWriter extends Writer {public static final char lb = '<';public static final char rb = '>';@@ -62,8 +62,8 @@ public final class htmlFilterWriter extends Writer {private String filterTag;private Properties filterOpts;private serverCharBuffer filterCont;- private final htmlFilterScraper scraper;- private final htmlFilterTransformer transformer;+ private final Scraper scraper;+ private final Transformer transformer;private boolean inSingleQuote;private boolean inDoubleQuote;private boolean inComment;@@ -72,11 +72,11 @@ public final class htmlFilterWriter extends Writer {private boolean binaryUnsuspect;private final boolean passbyIfBinarySuspect;- public htmlFilterWriter(+ public TransformerWriter(final OutputStream outStream,final Charset charSet,- final htmlFilterScraper scraper,- final htmlFilterTransformer transformer,+ final Scraper scraper,+ final Transformer transformer,final boolean passbyIfBinarySuspect) {this.outStream = outStream;@@ -583,11 +583,11 @@ public final class htmlFilterWriter extends Writer {System.exit(0);final char[] buffer = new char[512];try {- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(new yacyURL("http://localhost:8080", null));- final htmlFilterTransformer transformer = new htmlFilterContentTransformer();+ final ContentScraper scraper = new ContentScraper(new yacyURL("http://localhost:8080", null));+ final Transformer transformer = new ContentTransformer();final Reader is = new FileReader(args[0]);final FileOutputStream fos = new FileOutputStream(new File(args[0] + ".out"));- final Writer os = new htmlFilterWriter(fos, Charset.forName("UTF-8"),scraper, transformer, false);+ final Writer os = new TransformerWriter(fos, Charset.forName("UTF-8"),scraper, transformer, false);int i;while ((i = is.read(buffer)) > 0) os.write(buffer, 0, i);os.close();diff --git a/source/de/anomic/plasma/parser/mimeType/mimeTypeParser.java b/source/de/anomic/document/parser/mimeTypeParser.javasimilarity index 87%rename from source/de/anomic/plasma/parser/mimeType/mimeTypeParser.javarename to source/de/anomic/document/parser/mimeTypeParser.javaindex 22c427a20..e9fc1c8e7 100644--- a/source/de/anomic/plasma/parser/mimeType/mimeTypeParser.java+++ b/source/de/anomic/document/parser/mimeTypeParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.mimeType;+package de.anomic.document.parser;import java.io.File;import java.io.IOException;@@ -40,12 +37,12 @@ import net.sf.jmimemagic.MagicMatchNotFoundException;import org.apache.log4j.Level;import org.apache.log4j.Logger;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.FileUtils;-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;import de.anomic.yacy.yacyURL;public class mimeTypeParser extends AbstractParser implements Parser {@@ -110,8 +107,7 @@ public class mimeTypeParser extends AbstractParser implements Parser {}@SuppressWarnings("unchecked")- @Override- public plasmaParserDocument parse(final yacyURL location, String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {final String orgMimeType = mimeType;@@ -151,8 +147,7 @@ public class mimeTypeParser extends AbstractParser implements Parser {checkInterruption();// parsing the content using the determined mimetype- final plasmaParser theParser = new plasmaParser();- return theParser.parseSource(location,mimeType,charset,sourceFile);+ return ParserDispatcher.parseSource(location,mimeType,charset,sourceFile);}throw new ParserException("Unable to detect mimetype of resource (3).",location);} catch (final MagicMatchNotFoundException e) {@@ -172,7 +167,7 @@ public class mimeTypeParser extends AbstractParser implements Parser {}}- public plasmaParserDocument parse(final yacyURL location, final String mimeType,final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType,final String charset, final InputStream source) throws ParserException, InterruptedException {File dstFile = null;try {dstFile = File.createTempFile("mimeTypeParser",".prt");@@ -190,7 +185,6 @@ public class mimeTypeParser extends AbstractParser implements Parser {return mimeTypeParser.SUPPORTED_MIME_TYPES;}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/odt/odtParser.java b/source/de/anomic/document/parser/odtParser.javasimilarity index 88%rename from source/de/anomic/plasma/parser/odt/odtParser.javarename to source/de/anomic/document/parser/odtParser.javaindex d80d679f3..364ea9209 100644--- a/source/de/anomic/plasma/parser/odt/odtParser.java+++ b/source/de/anomic/document/parser/odtParser.java@@ -1,4 +1,4 @@-//odtParser.java+//zipParser.java//------------------------//part of YaCy//(C) by Michael Peter Christen; [email protected]@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.odt;+package de.anomic.document.parser;import java.io.ByteArrayInputStream;import java.io.File;@@ -46,17 +43,16 @@ import com.catcode.odf.OpenDocumentMetadata;import com.catcode.odf.OpenDocumentTextInputStream;import de.anomic.crawler.HTTPLoader;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.server.serverCharBuffer;import de.anomic.yacy.yacyURL;-import de.anomic.yacy.logging.Log;public class odtParser extends AbstractParser implements Parser {@@ -85,8 +81,7 @@ public class odtParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- @Override- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final File dest) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final File dest) throws ParserException, InterruptedException {Writer writer = null;File writerFile = null;@@ -162,10 +157,10 @@ public class odtParser extends AbstractParser implements Parser {if (docKeywordStr != null) docKeywords = docKeywordStr.split(" |,");// create the parser document- plasmaParserDocument theDoc = null;+ Document theDoc = null;if (writer instanceof serverCharBuffer) {final byte[] contentBytes = ((serverCharBuffer)writer).toString().getBytes("UTF-8");- theDoc = new plasmaParserDocument(+ theDoc = new Document(location,mimeType,"UTF-8",@@ -179,7 +174,7 @@ public class odtParser extends AbstractParser implements Parser {null,null);} else {- theDoc = new plasmaParserDocument(+ theDoc = new Document(location,mimeType,"UTF-8",@@ -208,7 +203,7 @@ public class odtParser extends AbstractParser implements Parser {}}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {File dest = null;try {// creating a tempfile@@ -230,7 +225,6 @@ public class odtParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();@@ -246,9 +240,6 @@ public class odtParser extends AbstractParser implements Parser {// creating a new parserfinal odtParser testParser = new odtParser();- // setting the parser logger- testParser.setLogger(new Log("PARSER.ODT"));-// downloading the document contentfinal httpRequestHeader reqHeader = new httpRequestHeader();reqHeader.put(httpHeader.USER_AGENT, HTTPLoader.crawlerUserAgent);diff --git a/source/de/anomic/plasma/parser/pdf/pdfParser.java b/source/de/anomic/document/parser/pdfParser.javasimilarity index 87%rename from source/de/anomic/plasma/parser/pdf/pdfParser.javarename to source/de/anomic/document/parser/pdfParser.javaindex e9b06e62f..80342b7c1 100644--- a/source/de/anomic/plasma/parser/pdf/pdfParser.java+++ b/source/de/anomic/document/parser/pdfParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.pdf;+package de.anomic.document.parser;import java.io.File;import java.io.FileOutputStream;@@ -42,11 +39,11 @@ import org.pdfbox.pdmodel.encryption.AccessPermission;import org.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;import org.pdfbox.util.PDFTextStripper;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.server.serverCharBuffer;import de.anomic.yacy.yacyURL;@@ -57,15 +54,8 @@ public class pdfParser extends AbstractParser implements Parser {* @see #getSupportedMimeTypes()*/public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static {- SUPPORTED_MIME_TYPES.put("application/pdf","pdf");- SUPPORTED_MIME_TYPES.put("application/x-pdf","pdf");- SUPPORTED_MIME_TYPES.put("application/acrobat","pdf");- SUPPORTED_MIME_TYPES.put("applications/vnd.pdf","pdf");- SUPPORTED_MIME_TYPES.put("text/pdf","pdf");- SUPPORTED_MIME_TYPES.put("text/x-pdf","pdf");- }-+ static { SUPPORTED_MIME_TYPES.put("application/pdf","pdf"); }+/*** a list of library names that are needed by this parser* @see Parser#getLibxDependences()@@ -83,7 +73,7 @@ public class pdfParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {PDDocument theDocument = null;Writer writer = null;@@ -145,11 +135,11 @@ public class pdfParser extends AbstractParser implements Parser {String[] docKeywords = null;if (docKeywordStr != null) docKeywords = docKeywordStr.split(" |,");- plasmaParserDocument theDoc = null;+ Document theDoc = null;if (writer instanceof serverCharBuffer) {final byte[] contentBytes = ((serverCharBuffer)writer).toString().getBytes("UTF-8");- theDoc = new plasmaParserDocument(+ theDoc = new Document(location,mimeType,"UTF-8",@@ -163,7 +153,7 @@ public class pdfParser extends AbstractParser implements Parser {null,null);} else {- theDoc = new plasmaParserDocument(+ theDoc = new Document(location,mimeType,"UTF-8",@@ -200,7 +190,6 @@ public class pdfParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();@@ -221,7 +210,7 @@ public class pdfParser extends AbstractParser implements Parser {// parsefinal AbstractParser parser = new pdfParser();- plasmaParserDocument document = null;+ Document document = null;try {document = parser.parse(null, "application/pdf", null, pdfFile);diff --git a/source/de/anomic/plasma/parser/ppt/pptParser.java b/source/de/anomic/document/parser/pptParser.javasimilarity index 77%rename from source/de/anomic/plasma/parser/ppt/pptParser.javarename to source/de/anomic/document/parser/pptParser.javaindex 2a7f054eb..f1c46f187 100644--- a/source/de/anomic/plasma/parser/ppt/pptParser.java+++ b/source/de/anomic/document/parser/pptParser.java@@ -11,6 +11,7 @@// $LastChangedRevision$// $LastChangedBy$//+////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@@ -25,7 +26,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.ppt;+package de.anomic.document.parser;import java.io.BufferedInputStream;import java.io.InputStream;@@ -33,10 +34,10 @@ import java.util.Hashtable;import org.apache.poi.hslf.extractor.PowerPointExtractor;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;public class pptParser extends AbstractParser implements Parser {@@ -45,17 +46,11 @@ public class pptParser extends AbstractParser implements Parser {* a list of mime types that are supported by this parser class* @see #getSupportedMimeTypes()*/- public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static final String fileExtensions = "ppt,pps";+ public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();static {- SUPPORTED_MIME_TYPES.put("application/mspowerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/powerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/vnd.ms-powerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/ms-powerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/mspowerpnt",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/vnd-mspowerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-powerpoint",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/x-m",fileExtensions);+ SUPPORTED_MIME_TYPES.put("application/mspowerpoint","ppt,pps");+ SUPPORTED_MIME_TYPES.put("application/powerpoint","ppt,pps");+ SUPPORTED_MIME_TYPES.put("application/vnd.ms-powerpoint","ppt,pps");}/**@@ -70,14 +65,13 @@ public class pptParser extends AbstractParser implements Parser {public pptParser(){super(LIBX_DEPENDENCIES);this.parserName = "Microsoft Powerpoint Parser";- this.parserVersionNr = "0.1";}/** parses the source documents and returns a plasmaParserDocument containing* all extracted information about the parsed document*/- public plasmaParserDocument parse(final yacyURL location, final String mimeType,+ public Document parse(final yacyURL location, final String mimeType,final String charset, final InputStream source) throws ParserException,InterruptedException {try {@@ -95,12 +89,12 @@ public class pptParser extends AbstractParser implements Parser {if (title.length() == l) break;l = title.length();}-+/** create the plasmaParserDocument for the database* and set shortText and bodyText properly*/- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",diff --git a/source/de/anomic/plasma/parser/ps/psParser.java b/source/de/anomic/document/parser/psParser.javasimilarity index 88%rename from source/de/anomic/plasma/parser/ps/psParser.javarename to source/de/anomic/document/parser/psParser.javaindex da803444f..0f2d6885d 100644--- a/source/de/anomic/plasma/parser/ps/psParser.java+++ b/source/de/anomic/document/parser/psParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2007////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 15.09.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.ps;+package de.anomic.document.parser;import java.io.BufferedReader;import java.io.BufferedWriter;@@ -36,11 +33,11 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.util.Hashtable;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.yacy.yacyURL;public class psParser extends AbstractParser implements Parser {@@ -53,10 +50,6 @@ public class psParser extends AbstractParser implements Parser {static {SUPPORTED_MIME_TYPES.put("application/postscript","ps");SUPPORTED_MIME_TYPES.put("text/postscript","ps");- SUPPORTED_MIME_TYPES.put("application/ps","ps");- SUPPORTED_MIME_TYPES.put("application/x-postscript","ps");- SUPPORTED_MIME_TYPES.put("application/x-ps","ps");- SUPPORTED_MIME_TYPES.put("application/x-postscript-not-eps","ps");}/**@@ -65,7 +58,7 @@ public class psParser extends AbstractParser implements Parser {*/private static final String[] LIBX_DEPENDENCIES = new String[] {};- private final static Object modeScan = new Object();+ private static Object modeScan = new Object();private static boolean modeScanDone = false;private static String parserMode = "java";@@ -103,8 +96,7 @@ public class psParser extends AbstractParser implements Parser {}- @Override- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {File outputFile = null;try {@@ -119,7 +111,7 @@ public class psParser extends AbstractParser implements Parser {}// return result- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -269,13 +261,12 @@ public class psParser extends AbstractParser implements Parser {if (execCode != 0) throw new Exception("Unable to convert ps to ascii. ps2ascii returned statuscode " + execCode + "\n" + procErr.toString());}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {File tempFile = null;try {diff --git a/source/de/anomic/plasma/parser/rpm/rpmParser.java b/source/de/anomic/document/parser/rpmParser.javasimilarity index 88%rename from source/de/anomic/plasma/parser/rpm/rpmParser.javarename to source/de/anomic/document/parser/rpmParser.javaindex 6b26afd25..fda6f1d19 100644--- a/source/de/anomic/plasma/parser/rpm/rpmParser.java+++ b/source/de/anomic/document/parser/rpmParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 20.11.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.rpm;+package de.anomic.document.parser;import java.io.ByteArrayInputStream;import java.io.File;@@ -37,14 +34,14 @@ import com.jguild.jrpm.io.RPMFile;import com.jguild.jrpm.io.datatype.DataTypeIf;import de.anomic.crawler.HTTPLoader;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.yacy.yacyURL;/**@@ -79,7 +76,7 @@ public class rpmParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,+ public Document parse(final yacyURL location, final String mimeType, final String charset,final InputStream source) throws ParserException {File dstFile = null;try {@@ -93,8 +90,7 @@ public class rpmParser extends AbstractParser implements Parser {}}- @Override- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final File sourceFile) throws ParserException, InterruptedException {RPMFile rpmFile = null;try {String summary = null, description = null, packager = null, name = sourceFile.getName();@@ -134,7 +130,7 @@ public class rpmParser extends AbstractParser implements Parser {rpmFile = null;if (summary == null) summary = name;- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -159,7 +155,6 @@ public class rpmParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/rss/rssParser.java b/source/de/anomic/document/parser/rssParser.javasimilarity index 75%rename from source/de/anomic/plasma/parser/rss/rssParser.javarename to source/de/anomic/document/parser/rssParser.javaindex 15cbc2eda..5baa344e4 100644--- a/source/de/anomic/plasma/parser/rss/rssParser.java+++ b/source/de/anomic/document/parser/rssParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.rss;+package de.anomic.document.parser;import java.io.ByteArrayInputStream;import java.io.IOException;@@ -38,19 +35,19 @@ import java.util.LinkedList;import java.util.Map;import de.anomic.content.RSSMessage;-import de.anomic.htmlFilter.htmlFilterAbstractScraper;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;-import de.anomic.htmlFilter.htmlFilterWriter;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.document.parser.html.AbstractScraper;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;+import de.anomic.document.parser.html.TransformerWriter;+import de.anomic.document.parser.xml.RSSFeed;+import de.anomic.document.parser.xml.RSSReader;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.server.serverCharBuffer;-import de.anomic.xml.RSSFeed;-import de.anomic.xml.RSSReader;import de.anomic.yacy.yacyURL;public class rssParser extends AbstractParser implements Parser {@@ -59,13 +56,12 @@ public class rssParser extends AbstractParser implements Parser {* a list of mime types that are supported by this parser class* @see #getSupportedMimeTypes()*/- public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static final String fileExtensions = "xml,rss,rdf";+ public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();static {- SUPPORTED_MIME_TYPES.put("text/rss",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/rdf+xml",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/rss+xml",fileExtensions);- SUPPORTED_MIME_TYPES.put("application/atom+xml",fileExtensions);+ SUPPORTED_MIME_TYPES.put("text/rss","xml,rss,rdf");+ SUPPORTED_MIME_TYPES.put("application/rdf+xml","xml,rss,rdf");+ SUPPORTED_MIME_TYPES.put("application/rss+xml","xml,rss,rdf");+ SUPPORTED_MIME_TYPES.put("application/atom+xml","xml,atom");}/**@@ -79,12 +75,12 @@ public class rssParser extends AbstractParser implements Parser {this.parserName = "Rich Site Summary/Atom Feed Parser";}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {try {final LinkedList<String> feedSections = new LinkedList<String>();final HashMap<yacyURL, String> anchors = new HashMap<yacyURL, String>();- final HashMap<String, htmlFilterImageEntry> images = new HashMap<String, htmlFilterImageEntry>();+ final HashMap<String, ImageEntry> images = new HashMap<String, ImageEntry>();final ByteBuffer text = new ByteBuffer();final serverCharBuffer authors = new serverCharBuffer();@@ -104,7 +100,7 @@ public class rssParser extends AbstractParser implements Parser {if (feed.getImage() != null) {final yacyURL imgURL = new yacyURL(feed.getImage(), null);- images.put(imgURL.hash(), new htmlFilterImageEntry(imgURL, feedTitle, -1, -1));+ images.put(imgURL.hash(), new ImageEntry(imgURL, feedTitle, -1, -1));}// loop through the feed items@@ -122,13 +118,13 @@ public class rssParser extends AbstractParser implements Parser {anchors.put(itemURL, itemTitle);if ((text.length() != 0) && (text.byteAt(text.length() - 1) != 32)) text.append((byte) 32);- text.append(htmlFilterAbstractScraper.stripAll(itemDescr).trim()).append(' ');+ text.append(AbstractScraper.stripAll(itemDescr).trim()).append(' ');final String itemContent = item.getDescription();if ((itemContent != null) && (itemContent.length() > 0)) {- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(itemURL);- final Writer writer = new htmlFilterWriter(null, null, scraper, null, false);+ final ContentScraper scraper = new ContentScraper(itemURL);+ final Writer writer = new TransformerWriter(null, null, scraper, null, false);FileUtils.copy(new ByteArrayInputStream(itemContent.getBytes("UTF-8")), writer, Charset.forName("UTF-8"));final String itemHeadline = scraper.getTitle();@@ -141,9 +137,9 @@ public class rssParser extends AbstractParser implements Parser {anchors.putAll(itemLinks);}- final HashMap<String, htmlFilterImageEntry> itemImages = scraper.getImages();+ final HashMap<String, ImageEntry> itemImages = scraper.getImages();if ((itemImages != null) && (itemImages.size() > 0)) {- htmlFilterContentScraper.addAllImages(images, itemImages);+ ContentScraper.addAllImages(images, itemImages);}final byte[] extractedText = scraper.getText();@@ -155,7 +151,7 @@ public class rssParser extends AbstractParser implements Parser {}}- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -186,7 +182,6 @@ public class rssParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/rtf/rtfParser.java b/source/de/anomic/document/parser/rtfParser.javasimilarity index 77%rename from source/de/anomic/plasma/parser/rtf/rtfParser.javarename to source/de/anomic/document/parser/rtfParser.javaindex 128353d34..4fea8ed59 100644--- a/source/de/anomic/plasma/parser/rtf/rtfParser.java+++ b/source/de/anomic/document/parser/rtfParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.rtf;+package de.anomic.document.parser;import java.io.InputStream;import java.util.Hashtable;@@ -33,10 +30,10 @@ import java.util.Hashtable;import javax.swing.text.DefaultStyledDocument;import javax.swing.text.rtf.RTFEditorKit;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;public class rtfParser extends AbstractParser implements Parser {@@ -49,11 +46,6 @@ public class rtfParser extends AbstractParser implements Parser {static {SUPPORTED_MIME_TYPES.put("application/rtf","rtf");SUPPORTED_MIME_TYPES.put("text/rtf","rtf");- SUPPORTED_MIME_TYPES.put("application/x-rtf","rtf");- SUPPORTED_MIME_TYPES.put("text/richtext","rtf");- SUPPORTED_MIME_TYPES.put("application/msword","rtf");- SUPPORTED_MIME_TYPES.put("application/doc","rtf");- SUPPORTED_MIME_TYPES.put("application/x-soffice","rtf");}/**@@ -67,7 +59,7 @@ public class rtfParser extends AbstractParser implements Parser {this.parserName = "Rich Text Format Parser";}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {try {@@ -78,7 +70,7 @@ public class rtfParser extends AbstractParser implements Parser {final String bodyText = doc.getText(0, doc.getLength());- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -110,7 +102,6 @@ public class rtfParser extends AbstractParser implements Parser {return rtfParser.SUPPORTED_MIME_TYPES;}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/document/parser/sevenzipParser.java b/source/de/anomic/document/parser/sevenzipParser.javanew file mode 100644index 000000000..5261a23cc--- /dev/null+++ b/source/de/anomic/document/parser/sevenzipParser.java@@ -0,0 +1,268 @@+// sevenzipParser.java+// -------------------------------------+// part of YACY+// (C) by Michael Peter Christen; [email protected]+// first published on http://www.anomic.de+// Frankfurt, Germany, 2004+//+// This file ist contributed by Franz Brausze+//+// 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++package de.anomic.document.parser;++import java.io.ByteArrayInputStream;+import java.io.File;+import java.io.IOException;+import java.io.InputStream;+import java.io.OutputStream;+import java.util.Hashtable;++import SevenZip.ArchiveExtractCallback;+import SevenZip.IInStream;+import SevenZip.MyRandomAccessFile;+import SevenZip.Archive.IInArchive;+import SevenZip.Archive.SevenZipEntry;+import SevenZip.Archive.SevenZip.Handler;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.kelondro.util.FileUtils;+import de.anomic.server.serverCachedFileOutputStream;+import de.anomic.yacy.yacyURL;+import de.anomic.yacy.logging.Log;++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<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();+ static {+ SUPPORTED_MIME_TYPES.put("application/x-7z-compressed", "7z");+ }++ /**+ * a list of library names that are needed by this parser+ * @see Parser#getLibxDependences()+ */+ private static final String[] LIBX_DEPENDENCIES = new String[] { "J7Zip-modified.jar" };++ public sevenzipParser() {+ super(LIBX_DEPENDENCIES);+ super.parserName = "7zip Archive Parser";+ }++ public Document parse(final yacyURL location, final String mimeType, final String charset,+ final IInStream source, final long maxRamSize) throws ParserException, InterruptedException {+ final Document doc = new Document(location, mimeType, charset, null);+ Handler archive;+ super.theLogger.logFine("opening 7zip archive...");+ try {+ archive = new Handler(source);+ } catch (final IOException e) {+ throw new ParserException("error opening 7zip archive", location, e);+ }+ checkInterruption();+ final SZParserExtractCallback aec = new SZParserExtractCallback(super.theLogger, archive,+ maxRamSize, doc, location.getFile());+ super.theLogger.logFine("processing archive contents...");+ try {+ archive.Extract(null, -1, 0, aec);+ return doc;+ } catch (final IOException e) {+ if (e.getCause() instanceof InterruptedException)+ throw (InterruptedException)e.getCause();+ if (e.getCause() instanceof ParserException)+ throw (ParserException)e.getCause();+ throw new ParserException(+ "error processing 7zip archive at internal file: " + aec.getCurrentFilePath(),+ location, e);+ } finally {+ try { archive.close(); } catch (final IOException e) { }+ }+ }++ public Document parse(final yacyURL location, final String mimeType, final String charset,+ final byte[] source) throws ParserException, InterruptedException {+ return parse(location, mimeType, charset, new ByteArrayIInStream(source), Parser.MAX_KEEP_IN_MEMORY_SIZE - source.length);+ }++ public Document parse(final yacyURL location, final String mimeType, final String charset,+ final File sourceFile) throws ParserException, InterruptedException {+ try {+ return parse(location, mimeType, charset, new MyRandomAccessFile(sourceFile, "r"), Parser.MAX_KEEP_IN_MEMORY_SIZE);+ } catch (final IOException e) {+ throw new ParserException("error processing 7zip archive", location, e);+ }+ }++ public Document parse(final yacyURL location, final String mimeType, final String charset,+ final InputStream source) throws ParserException, InterruptedException {+ try {+ final serverCachedFileOutputStream cfos = new serverCachedFileOutputStream(Parser.MAX_KEEP_IN_MEMORY_SIZE);+ FileUtils.copy(source, cfos);+ if (cfos.isFallback()) {+ return parse(location, mimeType, charset, cfos.getContentFile());+ }+ return parse(location, mimeType, charset, cfos.getContentBAOS());+ } catch (final IOException e) {+ throw new ParserException("error processing 7zip archive", location, e);+ }+ }++ public Hashtable<String, String> getSupportedMimeTypes() {+ return SUPPORTED_MIME_TYPES;+ }+++ // wrapper class to redirect output of standard ArchiveExtractCallback to serverLog+ // and parse the extracted content+ public static class SZParserExtractCallback extends ArchiveExtractCallback {++ private final Log log;+ private final long maxRamSize;+ private serverCachedFileOutputStream cfos = null;+ private final Document doc;+ private final String prefix;++ public SZParserExtractCallback(final Log logger, final IInArchive handler,+ final long maxRamSize, final Document doc, final String prefix) {+ super.Init(handler);+ this.log = logger;+ this.maxRamSize = maxRamSize;+ this.doc = doc;+ this.prefix = prefix;+ }++ public void PrepareOperation(final int arg0) {+ this.extractMode = (arg0 == IInArchive.NExtract_NAskMode_kExtract);+ switch (arg0) {+ case IInArchive.NExtract_NAskMode_kExtract:+ this.log.logFine("Extracting " + this.filePath);+ break;+ case IInArchive.NExtract_NAskMode_kTest:+ this.log.logFine("Testing " + this.filePath);+ break;+ case IInArchive.NExtract_NAskMode_kSkip:+ this.log.logFine("Skipping " + this.filePath);+ break;+ }+ }++ public void SetOperationResult(final int arg0) throws IOException {+ if (arg0 != IInArchive.NExtract_NOperationResult_kOK) {+ this.NumErrors++;+ switch(arg0) {+ case IInArchive.NExtract_NOperationResult_kUnSupportedMethod:+ throw new IOException("Unsupported Method");+ case IInArchive.NExtract_NOperationResult_kCRCError:+ throw new IOException("CRC Failed");+ case IInArchive.NExtract_NOperationResult_kDataError:+ throw new IOException("Data Error");+ default:+ // throw new IOException("Unknown Error");+ }+ } else try {+ AbstractParser.checkInterruption();++ if (this.cfos != null) {+ // parse the file+ Document theDoc;+ // workaround for relative links in file, normally '#' shall be used behind the location, see+ // below for reversion of the effects+ final yacyURL url = yacyURL.newURL(doc.dc_source(), this.prefix + "/" + super.filePath);+ final String mime = ParserDispatcher.getMimeTypeByFileExt(super.filePath.substring(super.filePath.lastIndexOf('.') + 1));+ if (this.cfos.isFallback()) {+ theDoc = ParserDispatcher.parseSource(url, mime, null, this.cfos.getContentFile());+ } else {+ theDoc = ParserDispatcher.parseSource(url, mime, null, this.cfos.getContentBAOS());+ }++ this.doc.addSubDocument(theDoc);+ }+ } catch (final ParserException e) {+ final IOException ex = new IOException("error parsing extracted content of " + super.filePath + ": " + e.getMessage());+ ex.initCause(e);+ throw ex;+ } catch (final InterruptedException e) {+ final IOException ex = new IOException("interrupted");+ ex.initCause(e);+ throw ex;+ }+ }++ public OutputStream GetStream(final int index, final int askExtractMode) throws IOException {+ final SevenZipEntry item = super.archiveHandler.getEntry(index);+ super.filePath = item.getName();+ try {+ AbstractParser.checkInterruption();+ } catch (final InterruptedException e) {+ final IOException ex = new IOException("interrupted");+ ex.initCause(e);+ throw ex;+ }+ this.cfos = (item.isDirectory()) ? null+ : new serverCachedFileOutputStream(this.maxRamSize, null, true, item.getSize());+ return this.cfos;+ }++ public String getCurrentFilePath() {+ return super.filePath;+ }+ }++ private static class SeekableByteArrayInputStream extends ByteArrayInputStream {+ public SeekableByteArrayInputStream(final byte[] buf) { super(buf); }+ public SeekableByteArrayInputStream(final byte[] buf, final int off, final int len) { super(buf, off, len); }++ public int getPosition() { return super.pos; }+ public void seekRelative(final int offset) { seekAbsolute(super.pos + offset); }+ public void seekAbsolute(final int offset) {+ if (offset > super.count)+ throw new IndexOutOfBoundsException(Integer.toString(offset));+ super.pos = offset;+ }+ }++ private static class ByteArrayIInStream extends IInStream {++ private final SeekableByteArrayInputStream sbais;++ public ByteArrayIInStream(final byte[] buffer) {+ this.sbais = new SeekableByteArrayInputStream(buffer);+ }++ public long Seek(final long offset, final int origin) {+ switch (origin) {+ case STREAM_SEEK_SET: this.sbais.seekAbsolute((int)offset); break;+ case STREAM_SEEK_CUR: this.sbais.seekRelative((int)offset); break;+ }+ return this.sbais.getPosition();+ }++ public int read() throws IOException {+ return this.sbais.read();+ }++ public int read(final byte[] b, final int off, final int len) throws IOException {+ return this.sbais.read(b, off, len);+ }+ }++}diff --git a/source/de/anomic/plasma/parser/swf/swfParser.java b/source/de/anomic/document/parser/swfParser.javasimilarity index 89%rename from source/de/anomic/plasma/parser/swf/swfParser.javarename to source/de/anomic/document/parser/swfParser.javaindex fb1dbbd60..0751bb8f1 100644--- a/source/de/anomic/plasma/parser/swf/swfParser.java+++ b/source/de/anomic/document/parser/swfParser.java@@ -25,17 +25,17 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.swf;+package de.anomic.document.parser;import java.io.InputStream;import java.util.HashMap;import java.util.Hashtable;import pt.tumba.parser.swf.SWF2HTML;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;public class swfParser extends AbstractParser implements Parser {@@ -48,8 +48,6 @@ public class swfParser extends AbstractParser implements Parser {static {SUPPORTED_MIME_TYPES.put("application/x-shockwave-flash","swf");SUPPORTED_MIME_TYPES.put("application/x-shockwave-flash2-preview","swf");- SUPPORTED_MIME_TYPES.put("application/futuresplash","swf");- SUPPORTED_MIME_TYPES.put("image/vnd.rn-realflash","swf");}/**@@ -61,7 +59,6 @@ public class swfParser extends AbstractParser implements Parser {public swfParser() {super(LIBX_DEPENDENCIES);this.parserName = "Adobe Flash Parser";- this.parserVersionNr = "0.1";}/**@@ -75,7 +72,7 @@ public class swfParser extends AbstractParser implements Parser {* parses the source documents and returns a plasmaParserDocument containing* all extracted information about the parsed document*/- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {try {final SWF2HTML swf2html = new SWF2HTML();@@ -114,7 +111,7 @@ public class swfParser extends AbstractParser implements Parser {}// As the result of parsing this function must return a plasmaParserDocument object- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location, // url of the source documentmimeType, // the documents mime type"UTF-8", // charset of the document textdiff --git a/source/de/anomic/plasma/parser/tar/tarParser.java b/source/de/anomic/document/parser/tarParser.javasimilarity index 80%rename from source/de/anomic/plasma/parser/tar/tarParser.javarename to source/de/anomic/document/parser/tarParser.javaindex 8f529b432..1ffa672db 100644--- a/source/de/anomic/plasma/parser/tar/tarParser.java+++ b/source/de/anomic/document/parser/tarParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.tar;+package de.anomic.document.parser;import java.io.BufferedOutputStream;import java.io.File;@@ -42,15 +39,15 @@ import java.util.zip.GZIPInputStream;import com.ice.tar.TarEntry;import com.ice.tar.TarInputStream;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.kelondro.util.FileUtils;-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;import de.anomic.yacy.yacyURL;public class tarParser extends AbstractParser implements Parser {@@ -63,10 +60,6 @@ public class tarParser extends AbstractParser implements Parser {static {SUPPORTED_MIME_TYPES.put("application/x-tar","tar");SUPPORTED_MIME_TYPES.put("application/tar","tar");- SUPPORTED_MIME_TYPES.put("applicaton/x-gtar","tar");- SUPPORTED_MIME_TYPES.put("multipart/x-tar","tar");- SUPPORTED_MIME_TYPES.put("application/x-compress","tar");- SUPPORTED_MIME_TYPES.put("application/x-compressed","tar");}/**@@ -86,12 +79,12 @@ public class tarParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, InputStream source) throws ParserException, InterruptedException {long docTextLength = 0;OutputStream docText = null;File outputFile = null;- plasmaParserDocument subDoc = null;+ Document subDoc = null;try {if ((this.contentLength == -1) || (this.contentLength > Parser.MAX_KEEP_IN_MEMORY_SIZE)) {outputFile = File.createTempFile("zipParser",".prt");@@ -100,14 +93,11 @@ public class tarParser extends AbstractParser implements Parser {docText = new ByteBuffer();}- // creating a new parser class to parse the unzipped content- final plasmaParser theParser = new plasmaParser();-/** If the mimeType was not reported correcly by the webserve we* have to decompress it first*/- final String ext = plasmaParser.getFileExt(location).toLowerCase();+ final String ext = ParserDispatcher.getFileExt(location).toLowerCase();if (ext.equals("gz") || ext.equals("tgz")) {source = new GZIPInputStream(source);}@@ -120,7 +110,7 @@ public class tarParser extends AbstractParser implements Parser {final StringBuilder docAbstrct = new StringBuilder();final Map<yacyURL, String> docAnchors = new HashMap<yacyURL, String>();- final HashMap<String, htmlFilterImageEntry> docImages = new HashMap<String, htmlFilterImageEntry>();+ final HashMap<String, ImageEntry> docImages = new HashMap<String, ImageEntry>();// looping through the contained filesTarEntry entry;@@ -140,7 +130,7 @@ public class tarParser extends AbstractParser implements Parser {final String entryExt = (idx > -1) ? entryName.substring(idx+1) : "";// trying to determine the mimeType per file extension- final String entryMime = plasmaParser.getMimeTypeByFileExt(entryExt);+ final String entryMime = ParserDispatcher.getMimeTypeByFileExt(entryExt);// getting the entry contentFile subDocTempFile = null;@@ -155,7 +145,7 @@ public class tarParser extends AbstractParser implements Parser {checkInterruption();// parsing the content- subDoc = theParser.parseSource(yacyURL.newURL(location,"#" + entryName),entryMime,null,subDocTempFile);+ subDoc = ParserDispatcher.parseSource(yacyURL.newURL(location,"#" + entryName),entryMime,null,subDocTempFile);} catch (final ParserException e) {this.theLogger.logInfo("Unable to parse tar file entry '" + entryName + "'. " + e.getMessage());} finally {@@ -181,17 +171,17 @@ public class tarParser extends AbstractParser implements Parser {}//docAnchors.putAll(subDoc.getAnchors());- htmlFilterContentScraper.addAllImages(docImages, subDoc.getImages());+ ContentScraper.addAllImages(docImages, subDoc.getImages());// release subdocumentsubDoc.close();subDoc = null;}- plasmaParserDocument result = null;+ Document result = null;if (docText instanceof ByteBuffer) {- result = new plasmaParserDocument(+ result = new Document(location,mimeType,null,@@ -205,7 +195,7 @@ public class tarParser extends AbstractParser implements Parser {docAnchors,docImages);} else {- result = new plasmaParserDocument(+ result = new Document(location,mimeType,null,@@ -237,7 +227,6 @@ public class tarParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/vcf/vcfParser.java b/source/de/anomic/document/parser/vcfParser.javasimilarity index 91%rename from source/de/anomic/plasma/parser/vcf/vcfParser.javarename to source/de/anomic/document/parser/vcfParser.javaindex 075b3c23d..cf0ed4d34 100644--- a/source/de/anomic/plasma/parser/vcf/vcfParser.java+++ b/source/de/anomic/document/parser/vcfParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+//last major change: 20.11.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.vcf;+package de.anomic.document.parser;import java.io.BufferedReader;import java.io.ByteArrayInputStream;@@ -38,14 +35,14 @@ import java.util.Iterator;import java.util.LinkedList;import de.anomic.crawler.HTTPLoader;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.kelondro.order.Base64Order;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;import de.anomic.yacy.yacyURL;/**@@ -64,13 +61,8 @@ public class vcfParser extends AbstractParser implements Parser {public static final Hashtable<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();static {SUPPORTED_MIME_TYPES.put("text/x-vcard","vcf");- SUPPORTED_MIME_TYPES.put("application/vcard","vcf");- SUPPORTED_MIME_TYPES.put("text/anytext","vcf");- SUPPORTED_MIME_TYPES.put("text/directory","vcf");- SUPPORTED_MIME_TYPES.put("application/x-versit","vcf");- SUPPORTED_MIME_TYPES.put("text/x-versit","vcf");- SUPPORTED_MIME_TYPES.put("text/x-vcalendar","vcf");- }+ SUPPORTED_MIME_TYPES.put("application/vcard","vcf");+ }/*** a list of library names that are needed by this parser@@ -87,7 +79,7 @@ public class vcfParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL url, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL url, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {try {final StringBuilder parsedTitle = new StringBuilder();@@ -230,7 +222,7 @@ public class vcfParser extends AbstractParser implements Parser {final String[] sections = parsedNames.toArray(new String[parsedNames.size()]);final byte[] text = parsedDataText.toString().getBytes();- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(url, // url of the source documentmimeType, // the documents mime typenull,@@ -252,7 +244,6 @@ public class vcfParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/plasma/parser/vsd/vsdParser.java b/source/de/anomic/document/parser/vsdParser.javasimilarity index 91%rename from source/de/anomic/plasma/parser/vsd/vsdParser.javarename to source/de/anomic/document/parser/vsdParser.javaindex 379e5fb49..5072fd305 100644--- a/source/de/anomic/plasma/parser/vsd/vsdParser.java+++ b/source/de/anomic/document/parser/vsdParser.java@@ -25,15 +25,15 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.vsd;+package de.anomic.document.parser;import java.io.InputStream;import java.util.Hashtable;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;import org.apache.poi.hdgf.extractor.VisioTextExtractor;import org.apache.poi.hpsf.SummaryInformation;@@ -68,7 +68,6 @@ public class vsdParser extends AbstractParser implements Parser {public vsdParser() {super(LIBX_DEPENDENCIES);this.parserName = "Microsoft Visio Parser";- this.parserVersionNr = "0.1";}/**@@ -82,9 +81,9 @@ public class vsdParser extends AbstractParser implements Parser {* parses the source documents and returns a plasmaParserDocument containing* all extracted information about the parsed document*/- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {- plasmaParserDocument theDoc = null;+ Document theDoc = null;try {String contents = "";@@ -120,7 +119,7 @@ public class vsdParser extends AbstractParser implements Parser {}// As the result of parsing this function must return a plasmaParserDocument object- theDoc = new plasmaParserDocument(+ theDoc = new Document(location, // url of the source documentmimeType, // the documents mime type"UTF-8", // charset of the document textdiff --git a/source/de/anomic/plasma/parser/xls/xlsParser.java b/source/de/anomic/document/parser/xlsParser.javasimilarity index 88%rename from source/de/anomic/plasma/parser/xls/xlsParser.javarename to source/de/anomic/document/parser/xlsParser.javaindex 4cda9b4bb..72096fe76 100644--- a/source/de/anomic/plasma/parser/xls/xlsParser.java+++ b/source/de/anomic/document/parser/xlsParser.java@@ -25,7 +25,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.xls;+package de.anomic.document.parser;import java.io.InputStream;import java.util.Hashtable;@@ -39,10 +39,10 @@ import org.apache.poi.hssf.record.Record;import org.apache.poi.hssf.record.SSTRecord;import org.apache.poi.poifs.filesystem.POIFSFileSystem;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.yacy.yacyURL;public class xlsParser extends AbstractParser implements Parser, HSSFListener {@@ -64,9 +64,6 @@ public class xlsParser extends AbstractParser implements Parser, HSSFListener {SUPPORTED_MIME_TYPES.put("application/vnd.ms-excel","xls");SUPPORTED_MIME_TYPES.put("application/x-excel","xls");SUPPORTED_MIME_TYPES.put("application/x-msexcel","xls");- SUPPORTED_MIME_TYPES.put("application/x-ms-excel","xls");- SUPPORTED_MIME_TYPES.put("application/x-dos_ms_excel","xls");- SUPPORTED_MIME_TYPES.put("application/xls","xls");}/**@@ -81,14 +78,13 @@ public class xlsParser extends AbstractParser implements Parser, HSSFListener {public xlsParser(){super(LIBX_DEPENDENCIES);this.parserName = "Microsoft Excel Parser";- this.parserVersionNr = "0.1";}/** parses the source documents and returns a plasmaParserDocument containing* all extracted information about the parsed document*/- public plasmaParserDocument parse(final yacyURL location, final String mimeType,+ public Document parse(final yacyURL location, final String mimeType,final String charset, final InputStream source) throws ParserException,InterruptedException {try {@@ -117,7 +113,7 @@ public class xlsParser extends AbstractParser implements Parser, HSSFListener {* create the plasmaParserDocument for the database* and set shortText and bodyText properly*/- final plasmaParserDocument theDoc = new plasmaParserDocument(+ final Document theDoc = new Document(location,mimeType,"UTF-8",@@ -138,7 +134,7 @@ public class xlsParser extends AbstractParser implements Parser, HSSFListener {* an unexpected error occurred, log it and throw a ParserException*/final String errorMsg = "Unable to parse the xls document '" + location + "':" + e.getMessage();- this.theLogger.logSevere(errorMsg);+ this.theLogger.logSevere(errorMsg);throw new ParserException(errorMsg, location);} finally {sbFoundStrings = null;diff --git a/source/de/anomic/xml/RSSFeed.java b/source/de/anomic/document/parser/xml/RSSFeed.javasimilarity index 99%rename from source/de/anomic/xml/RSSFeed.javarename to source/de/anomic/document/parser/xml/RSSFeed.javaindex 1c77ed300..e58411c83 100644--- a/source/de/anomic/xml/RSSFeed.java+++ b/source/de/anomic/document/parser/xml/RSSFeed.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.xml;+package de.anomic.document.parser.xml;import java.util.HashSet;import java.util.Iterator;diff --git a/source/de/anomic/xml/RSSReader.java b/source/de/anomic/document/parser/xml/RSSReader.javasimilarity index 99%rename from source/de/anomic/xml/RSSReader.javarename to source/de/anomic/document/parser/xml/RSSReader.javaindex 98bc93a90..f7aab32cc 100644--- a/source/de/anomic/xml/RSSReader.java+++ b/source/de/anomic/document/parser/xml/RSSReader.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.xml;+package de.anomic.document.parser.xml;import java.io.ByteArrayInputStream;import java.io.IOException;diff --git a/source/de/anomic/xml/opensearchdescriptionReader.java b/source/de/anomic/document/parser/xml/opensearchdescriptionReader.javasimilarity index 99%rename from source/de/anomic/xml/opensearchdescriptionReader.javarename to source/de/anomic/document/parser/xml/opensearchdescriptionReader.javaindex 16ec7cfa6..34f1bc56f 100644--- a/source/de/anomic/xml/opensearchdescriptionReader.java+++ b/source/de/anomic/document/parser/xml/opensearchdescriptionReader.java@@ -24,7 +24,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.xml;+package de.anomic.document.parser.xml;import java.io.ByteArrayInputStream;import java.io.IOException;diff --git a/source/de/anomic/plasma/parser/zip/zipParser.java b/source/de/anomic/document/parser/zipParser.javasimilarity index 80%rename from source/de/anomic/plasma/parser/zip/zipParser.javarename to source/de/anomic/document/parser/zipParser.javaindex 6f2be03c9..e88d87d1e 100644--- a/source/de/anomic/plasma/parser/zip/zipParser.java+++ b/source/de/anomic/document/parser/zipParser.java@@ -6,10 +6,7 @@//Frankfurt, Germany, 2005////this file is contributed by Martin Thelian-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$//last major change: 16.05.2005+//last major change: 16.05.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@@ -25,7 +22,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma.parser.zip;+package de.anomic.document.parser;import java.io.BufferedOutputStream;import java.io.File;@@ -40,15 +37,15 @@ import java.util.Map;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.AbstractParser;+import de.anomic.document.Parser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.kelondro.util.FileUtils;-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;import de.anomic.yacy.yacyURL;public class zipParser extends AbstractParser implements Parser {@@ -62,10 +59,6 @@ public class zipParser extends AbstractParser implements Parser {SUPPORTED_MIME_TYPES.put("application/zip","zip");SUPPORTED_MIME_TYPES.put("application/x-zip","zip");SUPPORTED_MIME_TYPES.put("application/x-zip-compressed","zip");- SUPPORTED_MIME_TYPES.put("application/octet-stream","zip");- SUPPORTED_MIME_TYPES.put("application/x-compress","zip");- SUPPORTED_MIME_TYPES.put("application/x-compressed","zip");- SUPPORTED_MIME_TYPES.put("multipart/x-zip","zip");SUPPORTED_MIME_TYPES.put("application/java-archive","jar");}@@ -84,12 +77,12 @@ public class zipParser extends AbstractParser implements Parser {return SUPPORTED_MIME_TYPES;}- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {+ public Document parse(final yacyURL location, final String mimeType, final String charset, final InputStream source) throws ParserException, InterruptedException {long docTextLength = 0;OutputStream docText = null;File outputFile = null;- plasmaParserDocument subDoc = null;+ Document subDoc = null;try {if ((this.contentLength == -1) || (this.contentLength > Parser.MAX_KEEP_IN_MEMORY_SIZE)) {outputFile = File.createTempFile("zipParser",".prt");@@ -103,10 +96,7 @@ public class zipParser extends AbstractParser implements Parser {final LinkedList<String> docSections = new LinkedList<String>();final StringBuilder docAbstrct = new StringBuilder();final Map<yacyURL, String> docAnchors = new HashMap<yacyURL, String>();- final HashMap<String, htmlFilterImageEntry> docImages = new HashMap<String, htmlFilterImageEntry>();-- // creating a new parser class to parse the unzipped content- final plasmaParser theParser = new plasmaParser();+ final HashMap<String, ImageEntry> docImages = new HashMap<String, ImageEntry>();// looping through the contained filesZipEntry entry;@@ -126,7 +116,7 @@ public class zipParser extends AbstractParser implements Parser {final String entryExt = (idx > -1) ? entryName.substring(idx+1) : "";// trying to determine the mimeType per file extension- final String entryMime = plasmaParser.getMimeTypeByFileExt(entryExt);+ final String entryMime = ParserDispatcher.getMimeTypeByFileExt(entryExt);// parsing the contentFile subDocTempFile = null;@@ -138,7 +128,7 @@ public class zipParser extends AbstractParser implements Parser {FileUtils.copy(zippedContent,subDocTempFile,entry.getSize());// parsing the zip file entry- subDoc = theParser.parseSource(yacyURL.newURL(location,"#" + entryName),entryMime,null, subDocTempFile);+ subDoc = ParserDispatcher.parseSource(yacyURL.newURL(location,"#" + entryName),entryMime,null, subDocTempFile);} catch (final ParserException e) {this.theLogger.logInfo("Unable to parse zip file entry '" + entryName + "'. " + e.getMessage());} finally {@@ -164,7 +154,7 @@ public class zipParser extends AbstractParser implements Parser {}//docAnchors.putAll(subDoc.getAnchors());- htmlFilterContentScraper.addAllImages(docImages, subDoc.getImages());+ ContentScraper.addAllImages(docImages, subDoc.getImages());// release subdocumentsubDoc.close();@@ -172,10 +162,10 @@ public class zipParser extends AbstractParser implements Parser {}- plasmaParserDocument result = null;+ Document result = null;if (docText instanceof ByteBuffer) {- result = new plasmaParserDocument(+ result = new Document(location,mimeType,null,@@ -189,7 +179,7 @@ public class zipParser extends AbstractParser implements Parser {docAnchors,docImages);} else {- result = new plasmaParserDocument(+ result = new Document(location,mimeType,null,@@ -221,7 +211,6 @@ public class zipParser extends AbstractParser implements Parser {}}- @Overridepublic void reset() {// Nothing todo here at the momentsuper.reset();diff --git a/source/de/anomic/http/httpdProxyCacheEntry.java b/source/de/anomic/http/httpDocument.javasimilarity index 99%rename from source/de/anomic/http/httpdProxyCacheEntry.javarename to source/de/anomic/http/httpDocument.javaindex c9d21e19e..01e03391a 100755--- a/source/de/anomic/http/httpdProxyCacheEntry.java+++ b/source/de/anomic/http/httpDocument.java@@ -31,10 +31,9 @@ import java.util.Date;import de.anomic.crawler.CrawlProfile;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.parser.Document;import de.anomic.yacy.yacyURL;-public class httpdProxyCacheEntry implements Document {+public class httpDocument {// doctypes:public static final char DT_PDFPS = 'p';@@ -131,7 +130,7 @@ public class httpdProxyCacheEntry implements Document {return doctype;}- public httpdProxyCacheEntry(+ public httpDocument(final int depth,final yacyURL url,final String name,diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex 940d1a66d..7b1a5154a 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -61,7 +61,7 @@ import org.apache.commons.httpclient.ChunkedInputStream;import org.apache.commons.httpclient.ContentLengthInputStream;import de.anomic.data.userDB;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.Digest;import de.anomic.kelondro.util.ByteBuffer;@@ -849,7 +849,7 @@ public final class httpd implements serverHandler, Cloneable {// 06.01.2007: decode HTML entities by [FB]public static String decodeHtmlEntities(String s) {// replace all entities defined in wikiCode.characters and htmlentities- s = htmlFilterCharacterCoding.html2unicode(s);+ s = CharacterCoding.html2unicode(s);// replace all otherfinal CharArrayWriter b = new CharArrayWriter(s.length());diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.javaindex 4b9925233..3de08bd34 100644--- a/source/de/anomic/http/httpdFileHandler.java+++ b/source/de/anomic/http/httpdFileHandler.java@@ -80,13 +80,13 @@ import java.util.Properties;import java.util.concurrent.ConcurrentHashMap;import java.util.zip.GZIPOutputStream;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterInputStream;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ScraperInputStream;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;import de.anomic.server.serverClassLoader;@@ -230,7 +230,7 @@ public final class httpdFileHandler {}headers.put(httpHeader.SERVER, "AnomicHTTPD (www.anomic.de)");headers.put(httpHeader.DATE, DateFormatter.formatRFC1123(new Date()));- if(!(plasmaParser.mediaExtContains(ext))){+ if(!(ParserDispatcher.mediaExtContains(ext))){headers.put(httpHeader.PRAGMA, "no-cache");}return headers;@@ -441,14 +441,14 @@ public final class httpdFileHandler {long sz;String headline, author, description;int images, links;- htmlFilterContentScraper scraper;+ ContentScraper scraper;for (int i = 0; i < list.length; i++) {f = new File(targetFile, list[i]);if (f.isDirectory()) {aBuffer.append(" <li><a href=\"" + path + list[i] + "/\">" + list[i] + "/</a><br></li>\n");} else {if (list[i].endsWith("html") || (list[i].endsWith("htm"))) {- scraper = htmlFilterContentScraper.parseResource(f);+ scraper = ContentScraper.parseResource(f);headline = scraper.getTitle();author = scraper.getAuthor();description = scraper.getDescription();@@ -859,8 +859,8 @@ public final class httpdFileHandler {// save positionfis.mark(1000);// scrape document to look up charset- final htmlFilterInputStream htmlFilter = new htmlFilterInputStream(fis,"UTF-8",new yacyURL("http://localhost", null),null,false);- final String charset = plasmaParser.patchCharsetEncoding(htmlFilter.detectCharset());+ final ScraperInputStream htmlFilter = new ScraperInputStream(fis,"UTF-8",new yacyURL("http://localhost", null),null,false);+ final String charset = ParserDispatcher.patchCharsetEncoding(htmlFilter.detectCharset());if(charset != null)mimeType = mimeType + "; charset="+charset;// reset positiondiff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex f0a02957c..59d7b3496 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -73,15 +73,14 @@ import java.util.zip.GZIPOutputStream;import de.anomic.crawler.HTTPLoader;import de.anomic.data.Blacklist;-import de.anomic.htmlFilter.htmlFilterContentTransformer;-import de.anomic.htmlFilter.htmlFilterTransformer;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.parser.html.ContentTransformer;+import de.anomic.document.parser.html.Transformer;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;-import de.anomic.plasma.parser.Document;import de.anomic.server.serverCore;import de.anomic.server.serverDomains;import de.anomic.server.serverObjects;@@ -102,7 +101,7 @@ public final class httpdProxyHandler {private static PrintWriter redirectorWriter = null;private static BufferedReader redirectorReader = null;- private static htmlFilterTransformer transformer = null;+ private static Transformer transformer = null;private static File htRootPath = null;//private Properties connectionProperties = null;@@ -175,7 +174,7 @@ public final class httpdProxyHandler {}// load a transformer- transformer = new htmlFilterContentTransformer();+ transformer = new ContentTransformer();transformer.init(new File(sb.getRootPath(), sb.getConfig(plasmaSwitchboardConstants.LIST_BLUE, "")).toString());// load the yellow-list@@ -378,7 +377,7 @@ public final class httpdProxyHandler {if (theLogger.isFinest()) theLogger.logFinest(reqID + " page not in cache: fulfill request from web");fulfillRequestFromWeb(conProp, url, requestHeader, cachedResponseHeader, countedRespond);} else {- final Document cacheEntry = new httpdProxyCacheEntry(+ final httpDocument cacheEntry = new httpDocument(0, // crawling depthurl, // url"", // name of the url is unknown@@ -492,7 +491,7 @@ public final class httpdProxyHandler {}// reserver cache entry- final Document cacheEntry = new httpdProxyCacheEntry(+ final httpDocument cacheEntry = new httpDocument(0,url,"",@@ -529,7 +528,7 @@ public final class httpdProxyHandler {final String storeError = cacheEntry.shallStoreCacheForProxy();final boolean storeHTCache = cacheEntry.profile().storeHTCache();- final boolean isSupportedContent = plasmaParser.supportedContent(plasmaParser.PARSER_MODE_PROXY,cacheEntry.url(),cacheEntry.getMimeType());+ final boolean isSupportedContent = ParserDispatcher.supportedContent(cacheEntry.url(), cacheEntry.getMimeType());if (/** Now we store the response into the htcache directory ifdiff --git a/source/de/anomic/icap/icapd.java b/source/de/anomic/icap/icapd.javaindex ccc159c98..6a0038782 100644--- a/source/de/anomic/icap/icapd.java+++ b/source/de/anomic/icap/icapd.java@@ -36,17 +36,16 @@ import java.net.InetAddress;import java.util.Date;import java.util.Properties;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpChunkedInputStream;import de.anomic.http.httpHeader;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpResponseHeader;-import de.anomic.http.httpdProxyCacheEntry;+import de.anomic.http.httpDocument;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaHTCache;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;import de.anomic.server.serverCore;import de.anomic.server.serverHandler;import de.anomic.server.serverCore.Session;@@ -164,7 +163,7 @@ public class icapd implements serverHandler, Cloneable {resHeader.put(icapHeader.SERVICE, "YaCy ICAP Indexing Service 1.0");resHeader.put(icapHeader.METHODS,icapHeader.METHOD_RESPMOD);- String transferIgnoreList = plasmaParser.getMediaExtList();+ String transferIgnoreList = ParserDispatcher.getMediaExtList();transferIgnoreList = transferIgnoreList.substring(1,transferIgnoreList.length()-1);resHeader.put(icapHeader.TRANSFER_IGNORE, transferIgnoreList);} else {@@ -365,7 +364,7 @@ public class icapd implements serverHandler, Cloneable {resHdrStream.close();}- if (!plasmaParser.supportedContent(plasmaParser.PARSER_MODE_ICAP, httpRequestURL, httpResHeader.mime())) {+ if (!ParserDispatcher.supportedContent(httpRequestURL, httpResHeader.mime())) {log.logInfo("Wrong mimeType or fileExtension for indexing:" +"\nMimeType: " + httpResHeader.mime() +"\nRequest Line:" + httpRequestLine);@@ -378,7 +377,7 @@ public class icapd implements serverHandler, Cloneable {* ========================================================================= */// generating a htcache entry object- final Document cacheEntry = new httpdProxyCacheEntry(+ final httpDocument cacheEntry = new httpDocument(0,httpRequestURL,"",diff --git a/source/de/anomic/kelondro/text/MetadataRepository.java b/source/de/anomic/kelondro/text/MetadataRepository.javaindex 9fad18f5e..7fb824416 100644--- a/source/de/anomic/kelondro/text/MetadataRepository.java+++ b/source/de/anomic/kelondro/text/MetadataRepository.java@@ -39,7 +39,7 @@ import java.util.Map;import java.util.TreeSet;import de.anomic.data.Blacklist;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.http.httpClient;import de.anomic.http.httpResponse;import de.anomic.http.httpRemoteProxyConfig;@@ -487,14 +487,14 @@ public final class MetadataRepository implements Iterable<byte[]> {pw.println(url);}if (format == 1) {- pw.println("<a href=\"" + url + "\">" + htmlFilterCharacterCoding.unicode2xml(metadata.dc_title(), true) + "</a><br>");+ pw.println("<a href=\"" + url + "\">" + CharacterCoding.unicode2xml(metadata.dc_title(), true) + "</a><br>");}if (format == 2) {pw.println("<item>");- pw.println("<title>" + htmlFilterCharacterCoding.unicode2xml(metadata.dc_title(), true) + "</title>");+ pw.println("<title>" + CharacterCoding.unicode2xml(metadata.dc_title(), true) + "</title>");pw.println("<link>" + yacyURL.escape(url) + "</link>");- if (metadata.dc_creator().length() > 0) pw.println("<author>" + htmlFilterCharacterCoding.unicode2xml(metadata.dc_creator(), true) + "</author>");- if (metadata.dc_subject().length() > 0) pw.println("<description>" + htmlFilterCharacterCoding.unicode2xml(metadata.dc_subject(), true) + "</description>");+ if (metadata.dc_creator().length() > 0) pw.println("<author>" + CharacterCoding.unicode2xml(metadata.dc_creator(), true) + "</author>");+ if (metadata.dc_subject().length() > 0) pw.println("<description>" + CharacterCoding.unicode2xml(metadata.dc_subject(), true) + "</description>");pw.println("<pubDate>" + entry.moddate().toString() + "</pubDate>");pw.println("<yacy:size>" + entry.size() + "</yacy:size>");pw.println("<guid isPermaLink=\"false\">" + entry.hash() + "</guid>");diff --git a/source/de/anomic/kelondro/text/ReferenceOrder.java b/source/de/anomic/kelondro/text/ReferenceOrder.javaindex 87f77f473..a82083eb4 100644--- a/source/de/anomic/kelondro/text/ReferenceOrder.java+++ b/source/de/anomic/kelondro/text/ReferenceOrder.java@@ -31,13 +31,13 @@ import java.util.HashMap;import java.util.Iterator;import java.util.Map;+import de.anomic.document.Condenser;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.text.referencePrototype.WordReference;import de.anomic.kelondro.text.referencePrototype.WordReferenceRow;import de.anomic.kelondro.text.referencePrototype.WordReferenceVars;import de.anomic.kelondro.util.ScoreCluster;import de.anomic.plasma.plasmaSearchRankingProcess;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.RankingProfile;import de.anomic.server.serverProcessor;import de.anomic.yacy.yacyURL;diff --git a/source/de/anomic/kelondro/text/Segment.java b/source/de/anomic/kelondro/text/Segment.javaindex 0e854532c..9b204bb43 100644--- a/source/de/anomic/kelondro/text/Segment.java+++ b/source/de/anomic/kelondro/text/Segment.java@@ -35,8 +35,11 @@ import java.util.Map;import java.util.TreeSet;import de.anomic.data.Blacklist;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.http.httpdProxyCacheEntry;+import de.anomic.document.Condenser;+import de.anomic.document.Word;+import de.anomic.document.Document;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.http.httpDocument;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.ByteOrder;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;@@ -46,10 +49,7 @@ import de.anomic.kelondro.text.navigationPrototype.NavigationReferenceRow;import de.anomic.kelondro.text.referencePrototype.WordReference;import de.anomic.kelondro.text.referencePrototype.WordReferenceFactory;import de.anomic.kelondro.text.referencePrototype.WordReferenceRow;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.tools.iso639;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -153,10 +153,10 @@ public final class Segment {* @param outlinksOther* @return*/- private int addPageIndex(final yacyURL url, final Date urlModified, final plasmaParserDocument document, final Condenser condenser, final String language, final char doctype, final int outlinksSame, final int outlinksOther) {+ private int addPageIndex(final yacyURL url, final Date urlModified, final Document document, final Condenser condenser, final String language, final char doctype, final int outlinksSame, final int outlinksOther) {int wordCount = 0;final int urlLength = url.toNormalform(true, true).length();- final int urlComps = htmlFilterContentScraper.urlComps(url.toString()).length;+ final int urlComps = ContentScraper.urlComps(url.toString()).length;// iterate over all words of context textfinal Iterator<Map.Entry<String, Word>> i = condenser.words().entrySet().iterator();@@ -203,7 +203,7 @@ public final class Segment {final yacyURL referrerURL,final Date docDate,final long sourcesize,- final plasmaParserDocument document,+ final Document document,final Condenser condenser) throws IOException {final long startTime = System.currentTimeMillis();@@ -269,7 +269,7 @@ public final class Segment {new byte[0], // md5(int) sourcesize, // sizecondenser.RESULT_NUMB_WORDS, // word count- httpdProxyCacheEntry.docType(document.dc_format()), // doctype+ httpDocument.docType(document.dc_format()), // doctypecondenser.RESULT_FLAGS, // flagslanguage, // languagedocument.inboundLinks(), // inbound links@@ -292,7 +292,7 @@ public final class Segment {document, // document contentcondenser, // document condenserlanguage, // document language- httpdProxyCacheEntry.docType(document.dc_format()), // document type+ httpDocument.docType(document.dc_format()), // document typedocument.inboundLinks(), // inbound linksdocument.outboundLinks() // outbound links);diff --git a/source/de/anomic/kelondro/text/referencePrototype/WordReferenceRow.java b/source/de/anomic/kelondro/text/referencePrototype/WordReferenceRow.javaindex 6c46ea900..ef5afedf2 100644--- a/source/de/anomic/kelondro/text/referencePrototype/WordReferenceRow.java+++ b/source/de/anomic/kelondro/text/referencePrototype/WordReferenceRow.java@@ -26,6 +26,7 @@package de.anomic.kelondro.text.referencePrototype;+import de.anomic.document.Word;import de.anomic.kelondro.index.Column;import de.anomic.kelondro.index.Row;import de.anomic.kelondro.index.Row.Entry;@@ -34,7 +35,6 @@ import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.order.MicroDate;import de.anomic.kelondro.text.AbstractReference;import de.anomic.kelondro.text.Reference;-import de.anomic.plasma.parser.Word;import de.anomic.yacy.yacySeedDB;public final class WordReferenceRow extends AbstractReference implements WordReference, Cloneable {diff --git a/source/de/anomic/plasma/parser/Document.java b/source/de/anomic/plasma/parser/Document.javadeleted file mode 100644index 0584907c7..000000000--- a/source/de/anomic/plasma/parser/Document.java+++ /dev/null@@ -1,84 +0,0 @@-// indexDocumentMetadata.java-// (C) 2008 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany-// first published 19.08.2008 on http://yacy.net-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$-//-// LICENSE-//-// 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--package de.anomic.plasma.parser;--import java.util.Date;--import de.anomic.crawler.CrawlProfile;-import de.anomic.yacy.yacyURL;--public interface Document {-- /**- * @return an anchor name; can be either the text inside the anchor tag or the- * page description after loading of the page- */- public String name();-- public yacyURL url();-- public String urlHash();-- public Date lastModified();-- public String language();-- public CrawlProfile.entry profile();-- public String initiator();-- public boolean proxy();-- public long size();-- public int depth();-- public yacyURL referrerURL();-- public void setCacheArray(final byte[] data);-- public byte[] cacheArray();-- public String getMimeType();- public Date ifModifiedSince();- public boolean requestProhibitsIndexing();- public boolean requestWithCookie();-- /**- * @return NULL if the answer is TRUE, in case of FALSE, the reason as- * String is returned- */- public String shallStoreCacheForProxy();-- /**- * decide upon header information if a specific file should be taken from- * the cache or not- *- * @return whether the file should be taken from the cache- */- public boolean shallUseCacheForProxy();-}diff --git a/source/de/anomic/plasma/parser/ParserInfo.java b/source/de/anomic/plasma/parser/ParserInfo.javadeleted file mode 100644index 7d68928ff..000000000--- a/source/de/anomic/plasma/parser/ParserInfo.java+++ /dev/null@@ -1,34 +0,0 @@-package de.anomic.plasma.parser;--import java.util.Hashtable;--public class ParserInfo {- // general parser info- public Class<?> parserClass;- public String parserClassName;-- public String parserName;- public String parserVersionNr;-- // parser properties- public String[] libxDependencies;- public Hashtable<String, String> supportedMimeTypes;-- // usage statistic- public int usageCount = 0;-- public String toString() {- final StringBuilder toStr = new StringBuilder();-- toStr.append(this.parserName).append(" V")- .append((this.parserVersionNr==null)?"0.0":this.parserVersionNr).append(" | ")- .append(this.parserClassName).append(" | ")- .append(this.supportedMimeTypes);-- return toStr.toString();- }-- public synchronized void incUsageCounter() {- this.usageCount++;- }-}diff --git a/source/de/anomic/plasma/parser/mimeType/log4j.properties b/source/de/anomic/plasma/parser/mimeType/log4j.propertiesdeleted file mode 100644index 8520d48c3..000000000--- a/source/de/anomic/plasma/parser/mimeType/log4j.properties+++ /dev/null@@ -1 +0,0 @@-log4j.rootLogger=OFFdiff --git a/source/de/anomic/plasma/parser/sevenzip/ByteArrayIInStream.java b/source/de/anomic/plasma/parser/sevenzip/ByteArrayIInStream.javadeleted file mode 100644index 3856d6ef5..000000000--- a/source/de/anomic/plasma/parser/sevenzip/ByteArrayIInStream.java+++ /dev/null@@ -1,72 +0,0 @@-// ByteArrayIInStream.java-// --------------------------------------// part of YACY-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2004-//-// This file ist contributed by Franz Brausze-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$-//-// 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--package de.anomic.plasma.parser.sevenzip;--import java.io.ByteArrayInputStream;-import java.io.IOException;--import SevenZip.IInStream;--public class ByteArrayIInStream extends IInStream {-- private static class SeekableByteArrayInputStream extends ByteArrayInputStream {- public SeekableByteArrayInputStream(final byte[] buf) { super(buf); }- public SeekableByteArrayInputStream(final byte[] buf, final int off, final int len) { super(buf, off, len); }-- public int getPosition() { return super.pos; }- public void seekRelative(final int offset) { seekAbsolute(super.pos + offset); }- public void seekAbsolute(final int offset) {- if (offset > super.count)- throw new IndexOutOfBoundsException(Integer.toString(offset));- super.pos = offset;- }- }-- private final SeekableByteArrayInputStream sbais;-- public ByteArrayIInStream(final byte[] buffer) {- this.sbais = new SeekableByteArrayInputStream(buffer);- }-- public long Seek(final long offset, final int origin) {- switch (origin) {- case STREAM_SEEK_SET: this.sbais.seekAbsolute((int)offset); break;- case STREAM_SEEK_CUR: this.sbais.seekRelative((int)offset); break;- }- return this.sbais.getPosition();- }-- public int read() throws IOException {- return this.sbais.read();- }-- @Override- public int read(final byte[] b, final int off, final int len) throws IOException {- return this.sbais.read(b, off, len);- }-}\ No newline at end of filediff --git a/source/de/anomic/plasma/parser/sevenzip/SZParserExtractCallback.java b/source/de/anomic/plasma/parser/sevenzip/SZParserExtractCallback.javadeleted file mode 100644index ed724bbba..000000000--- a/source/de/anomic/plasma/parser/sevenzip/SZParserExtractCallback.java+++ /dev/null@@ -1,164 +0,0 @@-// SZParserExtractCallback.java-// --------------------------------------// part of YACY-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2004-//-// This file ist contributed by Franz Brausze-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$-//-// 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--package de.anomic.plasma.parser.sevenzip;--import java.io.IOException;-import java.io.OutputStream;--import SevenZip.ArchiveExtractCallback;-import SevenZip.Archive.IInArchive;-import SevenZip.Archive.SevenZipEntry;-import de.anomic.plasma.plasmaParser;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.ParserException;-import de.anomic.server.serverCachedFileOutputStream;-import de.anomic.yacy.yacyURL;-import de.anomic.yacy.logging.Log;--// wrapper class to redirect output of standard ArchiveExtractCallback to serverLog-// and parse the extracted content-public class SZParserExtractCallback extends ArchiveExtractCallback {-- private final Log log;- private final long maxRamSize;- private serverCachedFileOutputStream cfos = null;- private final plasmaParser parser;- private final plasmaParserDocument doc;- private final String prefix;-- public SZParserExtractCallback(final Log logger, final IInArchive handler,- final long maxRamSize, final plasmaParserDocument doc, final String prefix) {- super.Init(handler);- this.log = logger;- this.maxRamSize = maxRamSize;- this.parser = new plasmaParser();- this.doc = doc;- this.prefix = prefix;- }-- @Override- public void PrepareOperation(final int arg0) {- this.extractMode = (arg0 == IInArchive.NExtract_NAskMode_kExtract);- switch (arg0) {- case IInArchive.NExtract_NAskMode_kExtract:- this.log.logFine("Extracting " + this.filePath);- break;- case IInArchive.NExtract_NAskMode_kTest:- this.log.logFine("Testing " + this.filePath);- break;- case IInArchive.NExtract_NAskMode_kSkip:- this.log.logFine("Skipping " + this.filePath);- break;- }- }-- @Override- public void SetOperationResult(final int arg0) throws IOException {- if (arg0 != IInArchive.NExtract_NOperationResult_kOK) {- this.NumErrors++;- switch(arg0) {- case IInArchive.NExtract_NOperationResult_kUnSupportedMethod:- throw new IOException("Unsupported Method");- case IInArchive.NExtract_NOperationResult_kCRCError:- throw new IOException("CRC Failed");- case IInArchive.NExtract_NOperationResult_kDataError:- throw new IOException("Data Error");- default:- // throw new IOException("Unknown Error");- }- } else try {- AbstractParser.checkInterruption();-- if (this.cfos != null) {- // parse the file- plasmaParserDocument theDoc;- // workaround for relative links in file, normally '#' shall be used behind the location, see- // below for reversion of the effects- final yacyURL url = yacyURL.newURL(doc.dc_source(), this.prefix + "/" + super.filePath);- final String mime = plasmaParser.getMimeTypeByFileExt(super.filePath.substring(super.filePath.lastIndexOf('.') + 1));- if (this.cfos.isFallback()) {- theDoc = this.parser.parseSource(url, mime, null, this.cfos.getContentFile());- } else {- theDoc = this.parser.parseSource(url, mime, null, this.cfos.getContentBAOS());- }-- /*- // revert the above workaround- final Map<yacyURL, String> nanchors = new HashMap<yacyURL, String>(theDoc.getAnchors().size(), 1f);- final Iterator<Map.Entry<yacyURL, String>> it = theDoc.getAnchors().entrySet().iterator();- Map.Entry<yacyURL, String> entry;- final String base = doc.dc_source().toNormalform(false, true);- String u;- while (it.hasNext()) {- entry = it.next();- u = entry.getKey().toNormalform(true, true);- if (u.startsWith(base + "/")) {- final String ref = "#" + u.substring(base.length() + 1);- if (this.log.isFinest()) this.log.logFinest("changing " + entry.getKey() + " to use reference " + ref);- nanchors.put(new yacyURL(base + ref, null), entry.getValue());- } else {- nanchors.put(entry.getKey(), entry.getValue());- }- }- theDoc.getAnchors().clear();- theDoc.getAnchors().putAll(nanchors);- */- this.doc.addSubDocument(theDoc);- }- } catch (final ParserException e) {- final IOException ex = new IOException("error parsing extracted content of " + super.filePath + ": " + e.getMessage());- ex.initCause(e);- throw ex;- } catch (final InterruptedException e) {- final IOException ex = new IOException("interrupted");- ex.initCause(e);- throw ex;- }- }-- @Override- public OutputStream GetStream(final int index, final int askExtractMode) throws IOException {- final SevenZipEntry item = super.archiveHandler.getEntry(index);- super.filePath = item.getName();- try {- AbstractParser.checkInterruption();- } catch (final InterruptedException e) {- final IOException ex = new IOException("interrupted");- ex.initCause(e);- throw ex;- }- this.cfos = (item.isDirectory()) ? null- : new serverCachedFileOutputStream(this.maxRamSize, null, true, item.getSize());- return this.cfos;- }-- public String getCurrentFilePath() {- return super.filePath;- }-}diff --git a/source/de/anomic/plasma/parser/sevenzip/sevenzipParser.java b/source/de/anomic/plasma/parser/sevenzip/sevenzipParser.javadeleted file mode 100644index 586ff6113..000000000--- a/source/de/anomic/plasma/parser/sevenzip/sevenzipParser.java+++ /dev/null@@ -1,131 +0,0 @@-// sevenzipParser.java-// --------------------------------------// part of YACY-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2004-//-// This file ist contributed by Franz Brausze-//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$-//-// 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--package de.anomic.plasma.parser.sevenzip;--import java.io.File;-import java.io.IOException;-import java.io.InputStream;-import java.util.Hashtable;--import SevenZip.IInStream;-import SevenZip.MyRandomAccessFile;-import SevenZip.Archive.SevenZip.Handler;-import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.AbstractParser;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;-import de.anomic.server.serverCachedFileOutputStream;-import de.anomic.yacy.yacyURL;--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<String, String> SUPPORTED_MIME_TYPES = new Hashtable<String, String>();- static {- SUPPORTED_MIME_TYPES.put("application/x-7z-compressed", "7z");- }-- /**- * a list of library names that are needed by this parser- * @see Parser#getLibxDependences()- */- private static final String[] LIBX_DEPENDENCIES = new String[] { "J7Zip-modified.jar" };-- public sevenzipParser() {- super(LIBX_DEPENDENCIES);- super.parserName = "7zip Archive Parser";- }-- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,- final IInStream source, final long maxRamSize) throws ParserException, InterruptedException {- final plasmaParserDocument doc = new plasmaParserDocument(location, mimeType, charset, null);- Handler archive;- super.theLogger.logFine("opening 7zip archive...");- try {- archive = new Handler(source);- } catch (final IOException e) {- throw new ParserException("error opening 7zip archive", location, e);- }- checkInterruption();- final SZParserExtractCallback aec = new SZParserExtractCallback(super.theLogger, archive,- maxRamSize, doc, location.getFile());- super.theLogger.logFine("processing archive contents...");- try {- archive.Extract(null, -1, 0, aec);- return doc;- } catch (final IOException e) {- if (e.getCause() instanceof InterruptedException)- throw (InterruptedException)e.getCause();- if (e.getCause() instanceof ParserException)- throw (ParserException)e.getCause();- throw new ParserException(- "error processing 7zip archive at internal file: " + aec.getCurrentFilePath(),- location, e);- } finally {- try { archive.close(); } catch (final IOException e) { }- }- }-- @Override- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,- final byte[] source) throws ParserException, InterruptedException {- return parse(location, mimeType, charset, new ByteArrayIInStream(source), Parser.MAX_KEEP_IN_MEMORY_SIZE - source.length);- }-- @Override- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,- final File sourceFile) throws ParserException, InterruptedException {- try {- return parse(location, mimeType, charset, new MyRandomAccessFile(sourceFile, "r"), Parser.MAX_KEEP_IN_MEMORY_SIZE);- } catch (final IOException e) {- throw new ParserException("error processing 7zip archive", location, e);- }- }-- public plasmaParserDocument parse(final yacyURL location, final String mimeType, final String charset,- final InputStream source) throws ParserException, InterruptedException {- try {- final serverCachedFileOutputStream cfos = new serverCachedFileOutputStream(Parser.MAX_KEEP_IN_MEMORY_SIZE);- FileUtils.copy(source, cfos);- if (cfos.isFallback()) {- return parse(location, mimeType, charset, cfos.getContentFile());- }- return parse(location, mimeType, charset, cfos.getContentBAOS());- } catch (final IOException e) {- throw new ParserException("error processing 7zip archive", location, e);- }- }-- public Hashtable<String, String> getSupportedMimeTypes() {- return SUPPORTED_MIME_TYPES;- }-}diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.javaindex cfe47726a..20e1d1a71 100644--- a/source/de/anomic/plasma/plasmaHTCache.java+++ b/source/de/anomic/plasma/plasmaHTCache.java@@ -41,14 +41,15 @@ import java.io.InputStream;import java.util.HashMap;import java.util.Map;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpResponseHeader;+import de.anomic.http.httpDocument;import de.anomic.kelondro.blob.ArrayStack;import de.anomic.kelondro.blob.Compressor;import de.anomic.kelondro.blob.Heap;import de.anomic.kelondro.blob.MapView;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.parser.Document;import de.anomic.yacy.yacySeedDB;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -180,7 +181,7 @@ public final class plasmaHTCache {}public static boolean isText(final String mimeType) {- return plasmaParser.supportedMimeTypesContains(mimeType);+ return ParserDispatcher.supportedMimeTypesContains(mimeType);}public static boolean noIndexingURL(final yacyURL url) {@@ -199,7 +200,7 @@ public final class plasmaHTCache {//php- return plasmaParser.mediaExtContains(urlString);+ return ParserDispatcher.mediaExtContains(urlString);}@@ -207,7 +208,7 @@ public final class plasmaHTCache {public static void storeMetadata(final httpResponseHeader responseHeader,- Document metadata+ httpDocument metadata) {if (responseHeader != null) try {// store the response header into the header databasediff --git a/source/de/anomic/plasma/plasmaParser.java b/source/de/anomic/plasma/plasmaParser.javadeleted file mode 100644index 499e7ad68..000000000--- a/source/de/anomic/plasma/plasmaParser.java+++ /dev/null@@ -1,1074 +0,0 @@-// plasmaParser.java-// (C) 2005 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany-// first published in january 2005 on http://yacy.net-// with contributions 02.05.2005 by Martin Thelian-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $-// $LastChangedRevision: 1986 $-// $LastChangedBy: orbiter $-//-// LICENSE-//-// 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--package de.anomic.plasma;--import java.io.BufferedInputStream;-import java.io.ByteArrayInputStream;-import java.io.File;-import java.io.FileInputStream;-import java.io.IOException;-import java.io.InputStream;-import java.io.UnsupportedEncodingException;-import java.net.MalformedURLException;-import java.nio.charset.Charset;-import java.nio.charset.IllegalCharsetNameException;-import java.nio.charset.UnsupportedCharsetException;-import java.util.ArrayList;-import java.util.Arrays;-import java.util.Collection;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Hashtable;-import java.util.Iterator;-import java.util.LinkedList;-import java.util.List;-import java.util.Map;-import java.util.Properties;-import java.util.Set;-import java.util.Map.Entry;-import java.util.regex.Matcher;-import java.util.regex.Pattern;--import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;-import de.anomic.htmlFilter.htmlFilterInputStream;-import de.anomic.htmlFilter.htmlFilterWriter;-import de.anomic.http.httpClient;-import de.anomic.http.httpResponse;-import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.parser.Parser;-import de.anomic.plasma.parser.ParserException;-import de.anomic.plasma.parser.ParserInfo;-import de.anomic.tools.ListDirs;-import de.anomic.yacy.yacyURL;-import de.anomic.yacy.logging.Log;--public final class plasmaParser {- public static final String PARSER_MODE_PROXY = "PROXY";- public static final String PARSER_MODE_CRAWLER = "CRAWLER";- public static final String PARSER_MODE_URLREDIRECTOR = "URLREDIRECTOR";- public static final String PARSER_MODE_ICAP = "ICAP";- public static final String PARSER_MODE_IMAGE = "IMAGE";- public static final HashSet<String> PARSER_MODE = new HashSet<String>(Arrays.asList(new String[]{- PARSER_MODE_PROXY,- PARSER_MODE_CRAWLER,- PARSER_MODE_ICAP,- PARSER_MODE_URLREDIRECTOR,- PARSER_MODE_IMAGE- }));-- private static final HashMap<String, plasmaParserConfig> parserConfigList = new HashMap<String, plasmaParserConfig>();-- /**- * A list containing all installed parsers and the mimeType that they support- * @see #loadAvailableParserList()- */- public static final HashMap<String, ParserInfo> availableParserList = new HashMap<String, ParserInfo>();-- /**- * A list of file extensions and mime types that are supported by the html-parser- */- public static final HashSet<String> supportedHTMLFileExt = new HashSet<String>();- public static final HashSet<String> supportedHTMLMimeTypes = new HashSet<String>();-- private static final Properties mimeTypeLookupByFileExt = new Properties();- static {- // loading a list of extensions from file- BufferedInputStream bufferedIn = null;- try {- mimeTypeLookupByFileExt.load(bufferedIn = new BufferedInputStream(new FileInputStream(new File("httpd.mime"))));- } catch (final IOException e) {- System.err.println("ERROR: httpd.mime not found in settings path");- } finally {- if (bufferedIn != null) try{bufferedIn.close();}catch(final Exception e){}- }- }-- /**- * A list of media extensions that should <b>not</b> be handled by the plasmaParser- */- private static final HashSet<String> mediaExtSet = new HashSet<String>();-- /**- * A list of image, audio, video and application extensions- */- private static final HashSet<String> imageExtSet = new HashSet<String>();- private static final HashSet<String> audioExtSet = new HashSet<String>();- private static final HashSet<String> videoExtSet = new HashSet<String>();- private static final HashSet<String> appsExtSet = new HashSet<String>();-- /**- * This {@link FilenameFilter} is used to find all classes based on there filenames- * which seems to be additional content parsers.- * Currently the filenames of all content parser classes must end with <code>Parser.class</code>- */- /*- private static final FilenameFilter parserFileNameFilter = new FilenameFilter() {- public boolean accept(File dir, String name) {- return name.endsWith("Parser.class");- }- };- */-- /**- * This {@link FileFilter} is used to get all subpackages- * of the parser package.- */- /*- private static final FileFilter parserDirectoryFilter = new FileFilter() {- public boolean accept(File file) {- return file.isDirectory();- }- };- */-- /**- * Initializing the- * @see #initMediaExt(String)- */- static {- final String apps = "sit,hqx,img,dmg,exe,com,bat,sh,vbs,zip,jar";- final String audio = "mp2,mp3,ogg,aac,aif,aiff,wav";- final String video = "swf,avi,wmv,rm,mov,mpg,mpeg,ram,m4v";- final String image = "jpg,jpeg,jpe,gif,png,ico,bmp";- initMediaExt(extString2extList(- apps + "," + // application container- "tar,gz,bz2,arj,zip,rar," + // archive formats- "ps,xls,ppt,asf," + // text formats without support- audio + "," + // audio formats- video + "," + // video formats- image // image formats- ));- initImageExt(extString2extList(image)); // image formats- initAudioExt(extString2extList(audio)); // audio formats- initVideoExt(extString2extList(video)); // video formats- initAppsExt(extString2extList(apps)); // application formats-- /* ===================================================- * loading a list of available parsers- * =================================================== */- loadAvailableParserList();- }-- private static final Log theLogger = new Log("PARSER");-- public Log getLogger() {- return theLogger;- }-- public static HashMap<String, plasmaParserConfig> getParserConfigList() {- return parserConfigList;- }-- /**- * This function is used to initialize the HTMLParsableMimeTypes List.- * This list contains a list of mimeTypes that can be parsed in realtime by- * the yacy html-Parser- * @param htmlParsableMimeTypes a list of mimetypes that can be parsed by the- * yacy html parser- */- public static void initHTMLParsableMimeTypes(final String htmlParsableMimeTypes) {- final LinkedList<String> mimeTypes = new LinkedList<String>();- if ((htmlParsableMimeTypes == null) || (htmlParsableMimeTypes.length() == 0)) {- return;- }- final String[] realtimeParsableMimeTypeList = htmlParsableMimeTypes.split(",");- for (int i = 0; i < realtimeParsableMimeTypeList.length; i++) {- mimeTypes.add(realtimeParsableMimeTypeList[i].toLowerCase().trim());- }- synchronized (supportedHTMLMimeTypes) {- supportedHTMLMimeTypes.clear();- supportedHTMLMimeTypes.addAll(mimeTypes);- }- }-- public static List<String> extString2extList(final String extString) {- final LinkedList<String> extensions = new LinkedList<String>();- if ((extString == null) || (extString.length() == 0)) {- return extensions;- }- final String[] xs = extString.split(",");- for (int i = 0; i < xs.length; i++) extensions.add(xs[i].toLowerCase().trim());- return extensions;- }-- public static void initMediaExt(final List<String> mediaExtList) {- synchronized (mediaExtSet) {- mediaExtSet.clear();- mediaExtSet.addAll(mediaExtList);- }- }-- public static void initImageExt(final List<String> imageExtList) {- synchronized (imageExtSet) {- imageExtSet.clear();- imageExtSet.addAll(imageExtList);- }- }-- public static void initAudioExt(final List<String> audioExtList) {- synchronized (audioExtSet) {- audioExtSet.clear();- audioExtSet.addAll(audioExtList);- }- }-- public static void initVideoExt(final List<String> videoExtList) {- synchronized (videoExtSet) {- videoExtSet.clear();- videoExtSet.addAll(videoExtList);- }- }-- public static void initAppsExt(final List<String> appsExtList) {- synchronized (appsExtSet) {- appsExtSet.clear();- appsExtSet.addAll(appsExtList);- }- }-- public static String getMediaExtList() {- synchronized (mediaExtSet) {- return mediaExtSet.toString();- }- }-- public static void initSupportedHTMLFileExt(final List<String> supportedRealtimeFileExtList) {- synchronized (supportedHTMLFileExt) {- supportedHTMLFileExt.clear();- supportedHTMLFileExt.addAll(supportedRealtimeFileExtList);- }- }-- public static boolean HTMLParsableMimeTypesContains(String mimeType) {- mimeType = normalizeMimeType(mimeType);- synchronized (supportedHTMLMimeTypes) {- return supportedHTMLMimeTypes.contains(mimeType);- }- }-- public static boolean supportedHTMLContent(final yacyURL url, final String mimeType) {- return HTMLParsableMimeTypesContains(mimeType) && supportedHTMLFileExtContains(url);- }-- public static boolean supportedHTMLFileExtContains(final yacyURL url) {- final String fileExt = getFileExt(url);- synchronized (supportedHTMLFileExt) {- return supportedHTMLFileExt.contains(fileExt);- }- }-- public static String getFileExt(final yacyURL url) {- // getting the file path- String name = url.getPath();-- // tetermining last position of / in the file path- int p = name.lastIndexOf('/');- if (p != -1) {- name = name.substring(p);- }-- // termining last position of . in file path- p = name.lastIndexOf('.');- if (p < 0) return "";- return name.substring(p + 1);- }-- public static boolean mediaExtContains(String mediaExt) {- if (mediaExt == null) return false;- mediaExt = mediaExt.trim().toLowerCase();-- synchronized (supportedHTMLFileExt) {- if (supportedHTMLFileExt.contains(mediaExt)) return false;- }-- if (supportedFileExtContains(mediaExt)) return false;-- synchronized (mediaExtSet) {- return mediaExtSet.contains(mediaExt);- }- }-- public static boolean imageExtContains(final String imageExt) {- if (imageExt == null) return false;- synchronized (imageExtSet) {- return imageExtSet.contains(imageExt.trim().toLowerCase());- }- }-- public static boolean audioExtContains(final String audioExt) {- if (audioExt == null) return false;- synchronized (audioExtSet) {- return audioExtSet.contains(audioExt.trim().toLowerCase());- }- }-- public static boolean videoExtContains(final String videoExt) {- if (videoExt == null) return false;- synchronized (videoExtSet) {- return videoExtSet.contains(videoExt.trim().toLowerCase());- }- }-- public static boolean appsExtContains(final String appsExt) {- if (appsExt == null) return false;- synchronized (appsExtSet) {- return appsExtSet.contains(appsExt.trim().toLowerCase());- }- }-- /**- * some html authors use wrong encoding names, either because they don't know exactly what they- * are doing or they produce a type. Many times, the upper/downcase scheme of the name is fuzzy- * This method patches wrong encoding names. The correct names are taken from- * http://www.iana.org/assignments/character-sets- * @param encoding- * @return patched encoding name- */- public static String patchCharsetEncoding(String encoding) {-- // return the system default encoding- if ((encoding == null) || (encoding.length() < 3)) return Charset.defaultCharset().name();-- // trim encoding string- encoding = encoding.trim();-- // fix upper/lowercase- encoding = encoding.toUpperCase();- if (encoding.startsWith("SHIFT")) return "Shift_JIS";- if (encoding.startsWith("BIG")) return "Big5";- // all other names but such with "windows" use uppercase- if (encoding.startsWith("WINDOWS")) encoding = "windows" + encoding.substring(7);- if (encoding.startsWith("MACINTOSH")) encoding = "MacRoman";-- // fix wrong fill characters- encoding = encoding.replaceAll("_", "-");-- if (encoding.matches("GB[_-]?2312([-_]80)?")) return "GB2312";- if (encoding.matches(".*UTF[-_]?8.*")) return "UTF-8";- if (encoding.startsWith("US")) return "US-ASCII";- if (encoding.startsWith("KOI")) return "KOI8-R";-- // patch missing '-'- if (encoding.startsWith("windows") && encoding.length() > 7) {- final char c = encoding.charAt(7);- if ((c >= '0') && (c <= '9')) {- encoding = "windows-" + encoding.substring(7);- }- }-- if (encoding.startsWith("ISO")) {- // patch typos- if (encoding.length() > 3) {- final char c = encoding.charAt(3);- if ((c >= '0') && (c <= '9')) {- encoding = "ISO-" + encoding.substring(3);- }- }- if (encoding.length() > 8) {- final char c = encoding.charAt(8);- if ((c >= '0') && (c <= '9')) {- encoding = encoding.substring(0, 8) + "-" + encoding.substring(8);- }- }- }-- // patch wrong name- if (encoding.startsWith("ISO-8559")) {- // popular typo- encoding = "ISO-8859" + encoding.substring(8);- }-- // converting cp\d{4} -> windows-\d{4}- if (encoding.matches("CP([_-])?125[0-8]")) {- final char c = encoding.charAt(2);- if ((c >= '0') && (c <= '9')) {- encoding = "windows-" + encoding.substring(2);- } else {- encoding = "windows" + encoding.substring(2);- }- }-- return encoding;- }-- public static String normalizeMimeType(String mimeType) {- //if (mimeType == null) doMimeTypeAnalysis- if (mimeType == null) mimeType = "application/octet-stream";- mimeType = mimeType.trim().toLowerCase();-- final int pos = mimeType.indexOf(';');- return ((pos < 0) ? mimeType : mimeType.substring(0, pos));- }-- public static String getMimeTypeByFileExt(final String fileExt) {- return mimeTypeLookupByFileExt.getProperty(fileExt,"application/octet-stream");- }-- public HashMap<String, ParserInfo> getAvailableParserList() {- return plasmaParser.availableParserList;- }-- private static void loadAvailableParserList() {- try {- plasmaParser.availableParserList.clear();-- // getting the current java classpath- final String javaClassPath = System.getProperty("java.class.path");-- // getting the current package name- final String plasmaParserPkgName = plasmaParser.class.getPackage().getName() + ".parser";- Log.logInfo("PARSER","Searching for additional content parsers in package " + plasmaParserPkgName);-- // getting an uri to the parser subpackage- final String packageURI = plasmaParser.class.getResource("/"+plasmaParserPkgName.replace('.','/')).toString() + "/";- Log.logFine("PARSER", "Parser directory is " + packageURI);-- /*- * loop through all subdirectories and test if we can- * find an additional parser class- */- final ListDirs parserDir = new ListDirs(packageURI);- final ArrayList<String> parserClasses = parserDir.listFiles(".*\\"+ File.separator +"parser\\"+ File.separator +"[^\\"+ File.separator +"]+\\"+ File.separator +"[^\\"+ File.separator +"]+Parser\\.class");- if (parserClasses == null) return;-- final Pattern patternGetClassName = Pattern.compile(".*\\"+ File.separator +"([^\\"+ File.separator +"]+)\\.class");- final Pattern patternGetFullClassName = Pattern.compile(".*(\\"+ File.separator +"[^\\"+ File.separator +"]+\\"+ File.separator +"[^\\"+ File.separator +"]+)\\.class");-- for (final String parserClassFile: parserClasses) {- Log.logFine("PARSER", "Testing parser class " + parserClassFile);- final Matcher matcherClassName = patternGetClassName.matcher(parserClassFile);- matcherClassName.find();- final String className = matcherClassName.group(1);- final Matcher matcherFullClassName = patternGetFullClassName.matcher(parserClassFile);- matcherFullClassName.find();- final String fullClassName = plasmaParserPkgName + matcherFullClassName.group(1).replace(File.separator , ".");- try {- // trying to load the parser class by its name- final Class<?> parserClass = Class.forName(fullClassName);- final Object theParser0 = parserClass.newInstance();- if (!(theParser0 instanceof Parser)) continue;- final Parser theParser = (Parser) theParser0;-- // testing if all needed libx libraries are available- final String[] neededLibx = theParser.getLibxDependences();- final StringBuilder neededLibxBuf = new StringBuilder();- if (neededLibx != null) {- for (int libxId=0; libxId < neededLibx.length; libxId++) {- if (javaClassPath.indexOf(neededLibx[libxId]) == -1) {- throw new Exception("Missing dependency detected: '" + neededLibx[libxId] + "'.");- }- neededLibxBuf.append(neededLibx[libxId])- .append(",");- }- if (neededLibxBuf.length()>0) neededLibxBuf.deleteCharAt(neededLibxBuf.length()-1);- }-- // loading the list of mime-types that are supported by this parser class- final Hashtable<String, String> supportedMimeTypes = theParser.getSupportedMimeTypes();-- // creating a parser info object- final ParserInfo parserInfo = new ParserInfo();- parserInfo.parserClass = parserClass;- parserInfo.parserClassName = fullClassName;- parserInfo.libxDependencies = neededLibx;- parserInfo.supportedMimeTypes = supportedMimeTypes;- parserInfo.parserVersionNr = (theParser).getVersion();- parserInfo.parserName = (theParser).getName();-- final Iterator<String> mimeTypeIterator = supportedMimeTypes.keySet().iterator();- while (mimeTypeIterator.hasNext()) {- final String mimeType = mimeTypeIterator.next();- availableParserList.put(mimeType, parserInfo);- Log.logInfo("PARSER", "Found functional parser for mimeType '" + mimeType + "'." +- "\n\tName: " + parserInfo.parserName +- "\n\tVersion: " + parserInfo.parserVersionNr +- "\n\tClass: " + parserInfo.parserClassName +- ((neededLibxBuf.length()>0)?"\n\tDependencies: " + neededLibxBuf.toString():""));- }-- } catch (final Exception e) { /* we can ignore this for the moment */- Log.logWarning("PARSER", "Parser '" + className + "' doesn't work correctly and will be ignored.\n [" + e.getClass().getName() + "]: " + e.getMessage());- e.printStackTrace();- } catch (final Error e) { /* we can ignore this for the moment */- Log.logWarning("PARSER", "Parser '" + className + "' doesn't work correctly and will be ignored.\n [" + e.getClass().getName() + "]: " + e.getMessage());- e.printStackTrace();- }- }-- } catch (final Exception e) {- Log.logSevere("PARSER", "Unable to determine all installed parsers. " + e.toString());- }- }-- public void close() {- // clearing the parser list- final Iterator<plasmaParserConfig> configs = parserConfigList.values().iterator();- while (configs.hasNext()) {- final plasmaParserConfig currentConfig = configs.next();- synchronized (currentConfig.enabledParserList) {- currentConfig.enabledParserList.clear();- }- }- }-- public plasmaParserDocument parseSource(final yacyURL location, final String mimeType, final String charset, final byte[] sourceArray)- throws InterruptedException, ParserException {- ByteArrayInputStream byteIn = null;- try {- if (theLogger.isFine())- theLogger.logFine("Parsing '" + location + "' from byte-array");-- // testing if the resource is not empty- if (sourceArray == null || sourceArray.length == 0) {- final String errorMsg = "No resource content available (1) " + (((sourceArray == null) ? "source == null" : "source.length() == 0") + ", url = " + location.toNormalform(true, false));- theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location, errorMsg);- }-- // creating an InputStream- byteIn = new ByteArrayInputStream(sourceArray);-- // parsing the temp file- return parseSource(location, mimeType, charset, sourceArray.length, byteIn);-- } catch (final Exception e) {- // Interrupted- and Parser-Exceptions should pass through- if (e instanceof InterruptedException) throw (InterruptedException) e;- if (e instanceof ParserException) throw (ParserException) e;-- // log unexpected error- theLogger.logSevere("Unexpected exception in parseSource from byte-array: " + e.getMessage(), e);- throw new ParserException("Unexpected exception while parsing " + location,location, e);- } finally {- if (byteIn != null) try { byteIn.close(); } catch (final Exception ex){/* ignore this */}- }-- }-- public plasmaParserDocument parseSource(final yacyURL location, final String theMimeType, final String theDocumentCharset, final File sourceFile) throws InterruptedException, ParserException {-- BufferedInputStream sourceStream = null;- try {- if (theLogger.isFine())- theLogger.logFine("Parsing '" + location + "' from file");-- // testing if the resource is not empty- if (!(sourceFile.exists() && sourceFile.canRead() && sourceFile.length() > 0)) {- final String errorMsg = sourceFile.exists() ? "Empty resource file." : "No resource content available (2).";- theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location, "document has no content");- }-- // create a new InputStream- sourceStream = new BufferedInputStream(new FileInputStream(sourceFile));-- // parsing the data- return this.parseSource(location, theMimeType, theDocumentCharset, sourceFile.length(), sourceStream);-- } catch (final Exception e) {- // Interrupted- and Parser-Exceptions should pass through- if (e instanceof InterruptedException) throw (InterruptedException) e;- if (e instanceof ParserException) throw (ParserException) e;-- // log unexpected error- theLogger.logSevere("Unexpected exception in parseSource from File: " + e.getMessage(), e);- throw new ParserException("Unexpected exception while parsing " + location,location, e);- } finally {- if (sourceStream != null) try { sourceStream.close(); } catch (final Exception ex){/* ignore this */}- }- }-- /**- * To parse a resource from an {@link InputStream}- * @param location the URL of the resource- * @param theMimeType the resource mimetype (<code>null</code> if unknown)- * @param theDocumentCharset the charset of the resource (<code>null</code> if unknown)- * @param contentLength the content length of the resource (<code>-1</code> if unknown)- * @param sourceStream an {@link InputStream} containing the resource body- * @return the parsed {@link plasmaParserDocument document}- * @throws InterruptedException- * @throws ParserException- */- public plasmaParserDocument parseSource(final yacyURL location, final String theMimeType, final String theDocumentCharset, final long contentLength, final InputStream sourceStream) throws InterruptedException, ParserException {- Parser theParser = null;- String mimeType = null;- try {- if (theLogger.isFine())- theLogger.logFine("Parsing '" + location + "' from stream");-- // getting the mimetype of the document- mimeType = normalizeMimeType(theMimeType);-- // getting the file extension of the document- final String fileExt = getFileExt(location);-- // getting the charset of the document- // TODO: do a charset detection here ....- final String documentCharset = patchCharsetEncoding(theDocumentCharset);-- // testing if parsing is supported for this resource- if (!plasmaParser.supportedContent(location,mimeType)) {- final String errorMsg = "No parser available to parse mimetype '" + mimeType + "' (1)";- theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location, "wrong mime type or wrong extension");- }-- if (theLogger.isFine())- theLogger.logInfo("Parsing " + location + " with mimeType '" + mimeType +- "' and file extension '" + fileExt + "'.");-- // getting the correct parser for the given mimeType- theParser = this.getParser(mimeType);-- // if a parser was found we use it ...- plasmaParserDocument doc = null;- if (theParser != null) {- // set the content length of the resource- theParser.setContentLength(contentLength);- // parse the resource- doc = theParser.parse(location, mimeType,documentCharset,sourceStream);- } else if (HTMLParsableMimeTypesContains(mimeType)) {- doc = parseHtml(location, mimeType, documentCharset, sourceStream);- } else {- final String errorMsg = "No parser available to parse mimetype '" + mimeType + "' (2)";- theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location, "wrong mime type or wrong extension");- }-- // check result- if (doc == null) {- final String errorMsg = "Unexpected error. Parser returned null.";- theLogger.logInfo("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location);- }- return doc;-- } catch (final UnsupportedEncodingException e) {- final String errorMsg = "unsupported charset encoding: " + e.getMessage();- theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg, e);- throw new ParserException(errorMsg,location, errorMsg);- } catch (final IOException e) {- // IOExceptions may occur during html parsing when a server closes the connection during reading.- // This may happen here, because the html parser is a streaming parser- // that produces surrogates while the connection is active- final String errorMsg = "IOException - server may have closed the connection. " + e.getMessage();- theLogger.logWarning("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg, location, errorMsg);- } catch (final Exception e) {- // Interrupted- and Parser-Exceptions should pass through- if (e instanceof InterruptedException) throw (InterruptedException) e;- if (e instanceof ParserException) throw (ParserException) e;-- // log unexpected error- final String errorMsg = "Unexpected exception. " + e.getMessage();- theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg, e);- throw new ParserException(errorMsg,location,e);-- } finally {- if (theParser != null) {- theParser = null; // delete object- }- }- }-- private plasmaParserDocument parseHtml(- final yacyURL location,- final String mimeType,- final String documentCharset,- final InputStream sourceStream) throws IOException, ParserException {-- // make a scraper and transformer- final htmlFilterInputStream htmlFilter = new htmlFilterInputStream(sourceStream,documentCharset,location,null,false);- String charset = htmlFilter.detectCharset();- if (charset == null) {- charset = documentCharset;- } else {- charset = patchCharsetEncoding(charset);- }-- if (!documentCharset.equalsIgnoreCase(charset)) {- theLogger.logInfo("Charset transformation needed from '" + documentCharset + "' to '" + charset + "' for URL = " + location.toNormalform(true, true));- }-- Charset c;- try {- c = Charset.forName(charset);- } catch (IllegalCharsetNameException e) {- c = Charset.defaultCharset();- } catch (UnsupportedCharsetException e) {- c = Charset.defaultCharset();- }-- // parsing the content- final htmlFilterContentScraper scraper = new htmlFilterContentScraper(location);- final htmlFilterWriter writer = new htmlFilterWriter(null,null,scraper,null,false);- FileUtils.copy(htmlFilter, writer, c);- writer.close();- //OutputStream hfos = new htmlFilterOutputStream(null, scraper, null, false);- //serverFileUtils.copy(sourceFile, hfos);- //hfos.close();- if (writer.binarySuspect()) {- final String errorMsg = "Binary data found in resource";- theLogger.logSevere("Unable to parse '" + location + "'. " + errorMsg);- throw new ParserException(errorMsg,location);- }- return transformScraper(location, mimeType, documentCharset, scraper);- }-- public plasmaParserDocument transformScraper(final yacyURL location, final String mimeType, final String charSet, final htmlFilterContentScraper scraper) {- final String[] sections = new String[scraper.getHeadlines(1).length + scraper.getHeadlines(2).length + scraper.getHeadlines(3).length + scraper.getHeadlines(4).length];- int p = 0;- for (int i = 1; i <= 4; i++) for (int j = 0; j < scraper.getHeadlines(i).length; j++) sections[p++] = scraper.getHeadlines(i)[j];- final plasmaParserDocument ppd = new plasmaParserDocument(- location,- mimeType,- charSet,- scraper.getContentLanguages(),- scraper.getKeywords(),- scraper.getTitle(),- scraper.getAuthor(),- sections,- scraper.getDescription(),- scraper.getText(),- scraper.getAnchors(),- scraper.getImages());- //scraper.close();- ppd.setFavicon(scraper.getFavicon());- return ppd;- }-- /**- * This function is used to determine the parser class that should be used for a given- * mimetype ...- * @param mimeType MIME-Type of the resource- * @return the {@link Parser}-class that is supposed to parse the resource of- * the given MIME-Type- */- private Parser getParser(String mimeType) {-- mimeType = normalizeMimeType(mimeType);- try {-- // determining the proper parser class name for the mimeType- String parserClassName = null;- ParserInfo parserInfo = null;- synchronized (plasmaParser.availableParserList) {- if (plasmaParser.availableParserList.containsKey(mimeType)) {- parserInfo = plasmaParser.availableParserList.get(mimeType);- parserClassName = parserInfo.parserClassName;- } else {- return null;- }- }-- // fetching a new parser object from pool- final Parser theParser = makeParser(parserClassName);-- // checking if the created parser really supports the given mimetype- final Hashtable<String, String> supportedMimeTypes = theParser.getSupportedMimeTypes();- if ((supportedMimeTypes != null) && (supportedMimeTypes.containsKey(mimeType))) {- parserInfo.incUsageCounter();- return theParser;- }-- } catch (final Exception e) {- System.err.println("ERROR: Unable to load the correct parser for type " + mimeType);- }-- return null;-- }-- static Map<yacyURL, String> allReflinks(final Collection<?> links) {- // links is either a Set of Strings (with urls) or htmlFilterImageEntries- // we find all links that are part of a reference inside a url- final HashMap<yacyURL, String> v = new HashMap<yacyURL, String>();- final Iterator<?> i = links.iterator();- Object o;- yacyURL url;- String u;- int pos;- loop: while (i.hasNext()) try {- o = i.next();- if (o instanceof yacyURL) url = (yacyURL) o;- else if (o instanceof String) url = new yacyURL((String) o, null);- else if (o instanceof htmlFilterImageEntry) url = ((htmlFilterImageEntry) o).url();- else {- assert false;- continue;- }- u = url.toNormalform(true, true);- if ((pos = u.toLowerCase().indexOf("http://",7)) > 0) {- i.remove();- u = u.substring(pos);- while ((pos = u.toLowerCase().indexOf("http://",7)) > 0) u = u.substring(pos);- url = new yacyURL(u, null);- if (!(v.containsKey(url))) v.put(url, "ref");- continue loop;- }- if ((pos = u.toLowerCase().indexOf("/www.",7)) > 0) {- i.remove();- u = "http:/" + u.substring(pos);- while ((pos = u.toLowerCase().indexOf("/www.",7)) > 0) u = "http:/" + u.substring(pos);- url = new yacyURL(u, null);- if (!(v.containsKey(url))) v.put(url, "ref");- continue loop;- }- } catch (final MalformedURLException e) {}- return v;- }-- static Map<yacyURL, String> allSubpaths(final Collection<?> links) {- // links is either a Set of Strings (urls) or a Set of htmlFilterImageEntries- final HashSet<String> h = new HashSet<String>();- Iterator<?> i = links.iterator();- Object o;- yacyURL url;- String u;- int pos;- int l;- while (i.hasNext()) try {- o = i.next();- if (o instanceof yacyURL) url = (yacyURL) o;- else if (o instanceof String) url = new yacyURL((String) o, null);- else if (o instanceof htmlFilterImageEntry) url = ((htmlFilterImageEntry) o).url();- else {- assert false;- continue;- }- u = url.toNormalform(true, true);- if (u.endsWith("/")) u = u.substring(0, u.length() - 1);- pos = u.lastIndexOf('/');- while (pos > 8) {- l = u.length();- u = u.substring(0, pos + 1);- h.add(u);- u = u.substring(0, pos);- assert (u.length() < l) : "u = " + u;- pos = u.lastIndexOf('/');- }- } catch (final MalformedURLException e) {}- // now convert the strings to yacyURLs- i = h.iterator();- final HashMap<yacyURL, String> v = new HashMap<yacyURL, String>();- while (i.hasNext()) {- u = (String) i.next();- try {- url = new yacyURL(u, null);- v.put(url, "sub");- } catch (final MalformedURLException e) {}- }- return v;- }-- public static void main(final String[] args) {- //javac -sourcepath source source/de/anomic/plasma/plasmaParser.java- //java -cp source de.anomic.plasma.plasmaParser bug.html bug.out- try {- Object content = null;- yacyURL contentURL = null;- long contentLength = -1;- String contentMimeType = "application/octet-stream";- String charSet = "utf-8";-- if (args.length < 2) {- System.err.println("Usage: java de.anomic.plasma.plasmaParser (-f filename|-u URL) [-m mimeType]");- }-- final String mode = args[0];- httpResponse res = null;- plasmaParserDocument document = null;- try { // close InputStream when done- if (mode.equalsIgnoreCase("-f")) {- content = new File(args[1]);- contentURL = new yacyURL((File)content);- } else if (mode.equalsIgnoreCase("-u")) {- contentURL = new yacyURL(args[1], null);-- // downloading the document content- final httpClient client = new httpClient(5000);-- res = client.GET(args[1]);- if (res.getStatusCode() != 200) {- System.err.println("Unable to download " + contentURL + ". " + res.getStatusLine());- return;- }- content = res.getDataAsStream();- contentMimeType = res.getResponseHeader().mime();- charSet = res.getResponseHeader().getCharacterEncoding();- contentLength = res.getResponseHeader().getContentLength();- }-- if ((args.length >= 4)&&(args[2].equalsIgnoreCase("-m"))) {- contentMimeType = args[3];- }-- if ((args.length >= 6)&&(args[4].equalsIgnoreCase("-c"))) {- charSet = args[5];- }-- // creating a plasma parser- final plasmaParser theParser = new plasmaParser();-- // configuring the html parsable mimeTypes- plasmaParser.initHTMLParsableMimeTypes("application/xhtml+xml,text/html,text/plain,text/sgml");-- // parsing the content- if (content instanceof byte[]) {- document = theParser.parseSource(contentURL, contentMimeType, charSet, (byte[])content);- } else if (content instanceof File) {- document = theParser.parseSource(contentURL, contentMimeType, charSet, (File)content);- } else if (content instanceof InputStream) {- document = theParser.parseSource(contentURL, contentMimeType, charSet, contentLength, (InputStream)content);- }- } finally {- if(res != null) {- res.closeStream();- }- }-- // printing out all parsed sentences- if (document != null) {- System.out.print("Document titel: ");- System.out.println(document.dc_title());-- // found text- final Iterator<StringBuilder> sentences = document.getSentences(false);- int i = 0;- if (sentences != null) while (sentences.hasNext()) {- System.out.print("line " + i + ": ");- System.out.println(sentences.next().toString());- i++;- }-- // found links- int anchorNr = 0;- final Map<yacyURL, String> anchors = document.getAnchors();- for (Entry<yacyURL, String> anchor: anchors.entrySet()) {- final yacyURL key = anchor.getKey();- System.out.println("URL " + anchorNr + ":\t" + key.toString() + " | " + anchor.getValue());- anchorNr++;- }- document.close();- }- } catch (final Exception e) {- e.printStackTrace();- }- }-- public static boolean supportedContent(final yacyURL url, final String mimeType) {- if (url == null) throw new NullPointerException();-- final Iterator<plasmaParserConfig> configs = parserConfigList.values().iterator();- while (configs.hasNext()) {- final plasmaParserConfig currentConfig = configs.next();- synchronized (currentConfig.enabledParserList) {- if (currentConfig.supportedContent(url, mimeType)) return true;- }- }-- return false;- }-- public static boolean supportedContent(final String parserMode, final yacyURL url, final String mimeType) {- if (!PARSER_MODE.contains(parserMode)) throw new IllegalArgumentException();- if (url == null) throw new NullPointerException();-- if (parserMode.equals(PARSER_MODE_IMAGE)) return true;- final plasmaParserConfig config = parserConfigList.get(parserMode);- return (config == null)?false:config.supportedContent(url, mimeType);- }-- public static void initParseableMimeTypes(final String parserMode, final String configStr) {- if (!PARSER_MODE.contains(parserMode)) throw new IllegalArgumentException();-- plasmaParserConfig config = parserConfigList.get(parserMode);- if (config == null) {- config = new plasmaParserConfig(parserMode);- parserConfigList.put(parserMode, config);- }- config.initParseableMimeTypes(configStr);- }-- public static String[] setEnabledParserList(final String parserMode, final Set<String> mimeTypeSet) {- if (!PARSER_MODE.contains(parserMode)) throw new IllegalArgumentException();-- plasmaParserConfig config = parserConfigList.get(parserMode);- if (config == null) {- config = new plasmaParserConfig(parserMode);- parserConfigList.put(parserMode, config);- }- return config.setEnabledParserList(mimeTypeSet);- }-- public static boolean supportedFileExtContains(final String fileExt) {- final Iterator<plasmaParserConfig> configs = parserConfigList.values().iterator();- while (configs.hasNext()) {- final plasmaParserConfig currentConfig = configs.next();- synchronized (currentConfig.enabledParserList) {- if (currentConfig.supportedFileExtContains(fileExt)) return true;- }- }-- return false;- }-- public static boolean supportedMimeTypesContains(final String mimeType) {- final Iterator<plasmaParserConfig> configs = parserConfigList.values().iterator();- while (configs.hasNext()) {- final plasmaParserConfig currentConfig = configs.next();- synchronized (currentConfig.enabledParserList) {- if (currentConfig.supportedMimeTypesContains(mimeType)) return true;- }- }-- return false;- }-- public static Parser makeParser(final Object name) throws Exception {-- if (!(name instanceof String))- throw new IllegalArgumentException("The object key must be of type string.");-- // loading class by name- final Class<?> moduleClass = Class.forName((String)name);-- // instantiating class- final Parser theParser = (Parser) moduleClass.newInstance();-- // setting logger that should by used- final String parserShortName = ((String)name).substring("de.anomic.plasma.parser.".length(),((String)name).lastIndexOf("."));-- final Log theLogger = new Log("PARSER." + parserShortName.toUpperCase());- theParser.setLogger(theLogger);-- return theParser;- }--}diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.javaindex fe76bcac1..7c0ffc8ba 100644--- a/source/de/anomic/plasma/plasmaSearchEvent.java+++ b/source/de/anomic/plasma/plasmaSearchEvent.java@@ -37,6 +37,8 @@ import java.util.TreeSet;import java.util.concurrent.ConcurrentHashMap;import de.anomic.crawler.ResultURLs;+import de.anomic.document.Condenser;+import de.anomic.document.Word;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.text.Reference;@@ -49,8 +51,6 @@ import de.anomic.kelondro.util.MemoryControl;import de.anomic.kelondro.util.SetTools;import de.anomic.kelondro.util.SortStack;import de.anomic.kelondro.util.SortStore;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.plasma.plasmaSearchRankingProcess.NavigatorEntry;import de.anomic.plasma.plasmaSnippetCache.MediaSnippet;import de.anomic.search.Query;diff --git a/source/de/anomic/plasma/plasmaSearchRankingProcess.java b/source/de/anomic/plasma/plasmaSearchRankingProcess.javaindex d27e24c33..50456c5d3 100644--- a/source/de/anomic/plasma/plasmaSearchRankingProcess.java+++ b/source/de/anomic/plasma/plasmaSearchRankingProcess.java@@ -39,7 +39,9 @@ import java.util.Set;import java.util.TreeSet;import java.util.concurrent.ConcurrentHashMap;-import de.anomic.htmlFilter.htmlFilterContentScraper;+import de.anomic.document.Condenser;+import de.anomic.document.Word;+import de.anomic.document.parser.html.ContentScraper;import de.anomic.kelondro.index.BinSearch;import de.anomic.kelondro.order.Digest;import de.anomic.kelondro.text.Reference;@@ -52,8 +54,6 @@ import de.anomic.kelondro.text.referencePrototype.WordReference;import de.anomic.kelondro.text.referencePrototype.WordReferenceVars;import de.anomic.kelondro.util.SortStack;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.Query;import de.anomic.server.serverProfiling;import de.anomic.yacy.yacyURL;@@ -536,7 +536,7 @@ public final class plasmaSearchRankingProcess {// take out relevant information for reference computationif ((resultEntry.url() == null) || (resultEntry.title() == null)) return;//final String[] urlcomps = htmlFilterContentScraper.urlComps(resultEntry.url().toNormalform(true, true)); // word components of the url- final String[] descrcomps = resultEntry.title().toLowerCase().split(htmlFilterContentScraper.splitrex); // words in the description+ final String[] descrcomps = resultEntry.title().toLowerCase().split(ContentScraper.splitrex); // words in the description// add references//addTopic(urlcomps);@@ -636,8 +636,8 @@ public final class plasmaSearchRankingProcess {// apply 'common-sense' heuristic using referencesfinal String urlstring = rentry.url().toNormalform(true, true);- final String[] urlcomps = htmlFilterContentScraper.urlComps(urlstring);- final String[] descrcomps = rentry.title().toLowerCase().split(htmlFilterContentScraper.splitrex);+ final String[] urlcomps = ContentScraper.urlComps(urlstring);+ final String[] descrcomps = rentry.title().toLowerCase().split(ContentScraper.splitrex);for (int j = 0; j < urlcomps.length; j++) {if (topwords.contains(urlcomps[j])) r += Math.max(1, 256 - urlstring.length()) << query.ranking.coeff_urlcompintoplist;}diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.javaindex ae1a562f5..1abdf3cbc 100644--- a/source/de/anomic/plasma/plasmaSnippetCache.java+++ b/source/de/anomic/plasma/plasmaSnippetCache.java@@ -38,18 +38,20 @@ import java.util.TreeSet;import java.util.regex.Matcher;import java.util.regex.Pattern;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.Condenser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Word;+import de.anomic.document.Document;+import de.anomic.document.parser.html.CharacterCoding;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.http.httpClient;import de.anomic.http.httpResponseHeader;+import de.anomic.http.httpDocument;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;import de.anomic.kelondro.util.ScoreCluster;import de.anomic.kelondro.util.SetTools;-import de.anomic.plasma.parser.Document;-import de.anomic.plasma.parser.ParserException;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.Query;import de.anomic.yacy.yacySearch;import de.anomic.yacy.yacyURL;@@ -82,16 +84,13 @@ public class plasmaSnippetCache {* </pre>*/private static final HashMap<String, yacyURL> faviconCache = new HashMap<String, yacyURL>();- private static plasmaParser parser = null;private static Log log = null;private static plasmaSwitchboard sb = null;public static void init(- final plasmaParser parserx,final Log logx,final plasmaSwitchboard switchboard) {- parser = parserx;log = logx;sb = switchboard;snippetsScoreCounter = 0;@@ -231,14 +230,14 @@ public class plasmaSnippetCache {for(int k=0; k < word.length(); k++) {//is character a special character?if(p4.matcher(word.substring(k,k+1)).find()) {- if (new String(Word.word2hash(temp)).equals(new String(h))) temp = "<b>" + htmlFilterCharacterCoding.unicode2html(temp, false) + "</b>";- out = out + temp + htmlFilterCharacterCoding.unicode2html(word.substring(k,k+1), false);+ if (new String(Word.word2hash(temp)).equals(new String(h))) temp = "<b>" + CharacterCoding.unicode2html(temp, false) + "</b>";+ out = out + temp + CharacterCoding.unicode2html(word.substring(k,k+1), false);temp = "";}//last characterelse if(k == (word.length()-1)) {temp = temp + word.substring(k,k+1);- if (new String(Word.word2hash(temp)).equals(new String(h))) temp = "<b>" + htmlFilterCharacterCoding.unicode2html(temp, false) + "</b>";+ if (new String(Word.word2hash(temp)).equals(new String(h))) temp = "<b>" + CharacterCoding.unicode2html(temp, false) + "</b>";out = out + temp;temp = "";}@@ -248,11 +247,11 @@ public class plasmaSnippetCache {}//end contrib [MN]- else if (new String(Word.word2hash(word)).equals(new String(h))) word = "<b>" + htmlFilterCharacterCoding.unicode2html(word, false) + "</b>";+ else if (new String(Word.word2hash(word)).equals(new String(h))) word = "<b>" + CharacterCoding.unicode2html(word, false) + "</b>";- word = htmlFilterCharacterCoding.unicode2html(prefix, false)+ word = CharacterCoding.unicode2html(prefix, false)+ word- + htmlFilterCharacterCoding.unicode2html(postfix, false);+ + CharacterCoding.unicode2html(postfix, false);return word;}@@ -354,7 +353,7 @@ public class plasmaSnippetCache {// if not found try to download it// download resource using the crawler and keep resource in memory if possible- final Document entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, true, reindexing);+ final httpDocument entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, true, reindexing);// getting resource metadata (e.g. the http headers for http resources)if (entry != null) {@@ -388,7 +387,7 @@ public class plasmaSnippetCache {/* ===========================================================================* PARSING RESOURCE* =========================================================================== */- plasmaParserDocument document = null;+ Document document = null;try {document = parseDocument(url, resContentLength, resContent, responseHeader);} catch (final ParserException e) {@@ -447,9 +446,9 @@ public class plasmaSnippetCache {* @param timeout* @param forText* @param global the domain of the search. If global == true then the content is re-indexed- * @return the parsed document as {@link plasmaParserDocument}+ * @return the parsed document as {@link Document}*/- public static plasmaParserDocument retrieveDocument(final yacyURL url, final boolean fetchOnline, final int timeout, final boolean forText, final boolean global) {+ public static Document retrieveDocument(final yacyURL url, final boolean fetchOnline, final int timeout, final boolean forText, final boolean global) {// load resourcelong resContentLength = 0;@@ -466,7 +465,7 @@ public class plasmaSnippetCache {// if not found try to download it// download resource using the crawler and keep resource in memory if possible- final Document entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, forText, global);+ final httpDocument entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, forText, global);// getting resource metadata (e.g. the http headers for http resources)if (entry != null) {@@ -497,7 +496,7 @@ public class plasmaSnippetCache {}// parse resource- plasmaParserDocument document = null;+ Document document = null;try {document = parseDocument(url, resContentLength, resContent, responseHeader);} catch (final ParserException e) {@@ -705,7 +704,7 @@ public class plasmaSnippetCache {return new ArrayList<MediaSnippet>();}- final plasmaParserDocument document = retrieveDocument(url, fetchOnline, timeout, false, reindexing);+ final Document document = retrieveDocument(url, fetchOnline, timeout, false, reindexing);final ArrayList<MediaSnippet> a = new ArrayList<MediaSnippet>();if (document != null) {if ((mediatype == Query.CONTENTDOM_ALL) || (mediatype == Query.CONTENTDOM_AUDIO)) a.addAll(computeMediaSnippets(document, queryhashes, Query.CONTENTDOM_AUDIO));@@ -716,7 +715,7 @@ public class plasmaSnippetCache {return a;}- public static ArrayList<MediaSnippet> computeMediaSnippets(final plasmaParserDocument document, final TreeSet<byte[]> queryhashes, final int mediatype) {+ public static ArrayList<MediaSnippet> computeMediaSnippets(final Document document, final TreeSet<byte[]> queryhashes, final int mediatype) {if (document == null) return new ArrayList<MediaSnippet>();Map<yacyURL, String> media = null;@@ -749,14 +748,14 @@ public class plasmaSnippetCache {return result;}- public static ArrayList<MediaSnippet> computeImageSnippets(final plasmaParserDocument document, final TreeSet<byte[]> queryhashes) {+ public static ArrayList<MediaSnippet> computeImageSnippets(final Document document, final TreeSet<byte[]> queryhashes) {- final TreeSet<htmlFilterImageEntry> images = new TreeSet<htmlFilterImageEntry>();+ final TreeSet<ImageEntry> images = new TreeSet<ImageEntry>();images.addAll(document.getImages().values()); // iterates images in descending size order!// a measurement for the size of the images can be retrieved using the htmlFilterImageEntry.hashCode()- final Iterator<htmlFilterImageEntry> i = images.iterator();- htmlFilterImageEntry ientry;+ final Iterator<ImageEntry> i = images.iterator();+ ImageEntry ientry;yacyURL url;String desc;TreeSet<byte[]> s;@@ -824,7 +823,7 @@ public class plasmaSnippetCache {return true;}- public static plasmaParserDocument parseDocument(final yacyURL url, final long contentLength, final InputStream resourceStream) throws ParserException {+ public static Document parseDocument(final yacyURL url, final long contentLength, final InputStream resourceStream) throws ParserException {return parseDocument(url, contentLength, resourceStream, null);}@@ -837,7 +836,7 @@ public class plasmaSnippetCache {* @return the extracted data* @throws ParserException*/- public static plasmaParserDocument parseDocument(final yacyURL url, final long contentLength, final InputStream resourceStream, httpResponseHeader responseHeader) throws ParserException {+ public static Document parseDocument(final yacyURL url, final long contentLength, final InputStream resourceStream, httpResponseHeader responseHeader) throws ParserException {try {if (resourceStream == null) return null;@@ -871,25 +870,25 @@ public class plasmaSnippetCache {if ( // if no extension is available(p < 0) ||// or the extension is supported by one of the parsers- ((p >= 0) && (plasmaParser.supportedFileExtContains(filename.substring(p + 1))))+ ((p >= 0) && (ParserDispatcher.supportedFileExtContains(filename.substring(p + 1))))) {String supposedMime = "text/html";// if the mimeType Parser is installed we can set the mimeType to null to force// a mimetype detection- if (plasmaParser.supportedMimeTypesContains("application/octet-stream")) {+ if (ParserDispatcher.supportedMimeTypesContains("application/octet-stream")) {supposedMime = null;} else if (p != -1){// otherwise we try to determine the mimeType per file Extension- supposedMime = plasmaParser.getMimeTypeByFileExt(filename.substring(p + 1));+ supposedMime = ParserDispatcher.getMimeTypeByFileExt(filename.substring(p + 1));}- return parser.parseSource(url, supposedMime, null, contentLength, resourceStream);+ return ParserDispatcher.parseSource(url, supposedMime, null, contentLength, resourceStream);}return null;}- if (plasmaParser.supportedMimeTypesContains(responseHeader.mime())) {- return parser.parseSource(url, responseHeader.mime(), responseHeader.getCharacterEncoding(), contentLength, resourceStream);+ if (ParserDispatcher.supportedMimeTypesContains(responseHeader.mime())) {+ return ParserDispatcher.parseSource(url, responseHeader.mime(), responseHeader.getCharacterEncoding(), contentLength, resourceStream);}return null;} catch (final InterruptedException e) {@@ -923,7 +922,7 @@ public class plasmaSnippetCache {// if the content is not available in cache try to download it from web// try to download the resource using a crawler- final Document entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, forText, reindexing);+ final httpDocument entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, forText, reindexing);if (entry == null) return null; // not found in web// read resource body (if it is there)diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex 23ad0af72..a6c961028 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -143,12 +143,19 @@ import de.anomic.data.userDB;import de.anomic.data.wiki.wikiBoard;import de.anomic.data.wiki.wikiCode;import de.anomic.data.wiki.wikiParser;+import de.anomic.document.Condenser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Word;+import de.anomic.document.Document;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpRemoteProxyConfig;import de.anomic.http.httpRequestHeader;import de.anomic.http.httpResponseHeader;import de.anomic.http.httpd;+import de.anomic.http.httpDocument;import de.anomic.http.httpdRobotsTxtConfig;import de.anomic.kelondro.order.Digest;import de.anomic.kelondro.order.NaturalOrder;@@ -160,10 +167,6 @@ import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;import de.anomic.kelondro.util.SetTools;import de.anomic.net.UPnP;-import de.anomic.plasma.parser.Document;-import de.anomic.plasma.parser.ParserException;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.Query;import de.anomic.search.RankingProfile;import de.anomic.server.serverAbstractSwitch;@@ -181,7 +184,6 @@ import de.anomic.server.serverSystem;import de.anomic.server.serverThread;import de.anomic.tools.crypt;import de.anomic.tools.CryptoLib;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.yacyClient;import de.anomic.yacy.yacyCore;import de.anomic.yacy.yacyNewsPool;@@ -242,7 +244,6 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.public plasmaRankingDistribution rankingOwnDistribution;public plasmaRankingDistribution rankingOtherDistribution;public HashMap<String, Object[]> outgoingCookies, incomingCookies;- public plasmaParser parser;public volatile long proxyLastAccess, localSearchLastAccess, remoteSearchLastAccess;public yacyCore yc;public ResourceObserver observer;@@ -510,21 +511,16 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.// make parserlog.logConfig("Starting Parser");- this.parser = new plasmaParser();// define an extension-blacklistlog.logConfig("Parser: Initializing Extension Mappings for Media/Parser");- plasmaParser.initMediaExt(plasmaParser.extString2extList(getConfig(plasmaSwitchboardConstants.PARSER_MEDIA_EXT,"")));- plasmaParser.initSupportedHTMLFileExt(plasmaParser.extString2extList(getConfig(plasmaSwitchboardConstants.PARSER_MEDIA_EXT_PARSEABLE,"")));+ ParserDispatcher.initMediaExt(ParserDispatcher.extString2extList(getConfig(plasmaSwitchboardConstants.PARSER_MEDIA_EXT,"")));+ ParserDispatcher.initSupportedHTMLFileExt(ParserDispatcher.extString2extList(getConfig(plasmaSwitchboardConstants.PARSER_MEDIA_EXT_PARSEABLE,"")));// define a realtime parsable mimetype listlog.logConfig("Parser: Initializing Mime Types");- plasmaParser.initHTMLParsableMimeTypes(getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_HTML, "application/xhtml+xml,text/html,text/plain"));- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_PROXY, getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_PROXY, null));- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_CRAWLER, getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_CRAWLER, null));- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_ICAP, getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_ICAP, null));- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_URLREDIRECTOR, getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_URLREDIRECTOR, null));- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_IMAGE, getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_IMAGE, null));+ ParserDispatcher.initHTMLParsableMimeTypes(getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_HTML, "application/xhtml+xml,text/html,text/plain"));+ ParserDispatcher.addParseableMimeTypes(getConfig(plasmaSwitchboardConstants.PARSER_MIMETYPES_CRAWLER, null));// start a loaderlog.logConfig("Starting Crawl Loader");@@ -593,7 +589,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.// generate snippets cachelog.logConfig("Initializing Snippet Cache");- plasmaSnippetCache.init(parser, log, this);+ plasmaSnippetCache.init(log, this);// init the wikiwikiParser = new wikiCode(this.peers.mySeed().getClusterAddress());@@ -1089,7 +1085,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.return this.crawler.cleanProfiles();}- public boolean htEntryStoreProcess(final Document entry) {+ public boolean htEntryStoreProcess(final httpDocument entry) {if (entry == null) return false;@@ -1098,7 +1094,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.** Testing if the content type is supported by the available parsers* ========================================================================= */- final boolean isSupportedContent = plasmaParser.supportedContent(entry.url(),entry.getMimeType());+ final boolean isSupportedContent = ParserDispatcher.supportedContent(entry.url(),entry.getMimeType());if (log.isFinest()) log.logFinest("STORE "+ entry.url() +" content of type "+ entry.getMimeType() +" is supported: "+ isSupportedContent);/* =========================================================================@@ -1210,7 +1206,6 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.bookmarksDB.close();messageDB.close();robots.close();- parser.close();webStructure.flushCitationReference("crg");webStructure.close();crawlQueues.close();@@ -1296,7 +1291,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.}// create a queue entry- plasmaParserDocument document = surrogate.document();+ Document document = surrogate.document();queueentry = this.crawler.queuePreStack.newEntry(surrogate.url(), null, null, false, null, 0, this.crawler.defaultSurrogateProfile.handle(), null);/** public QueueEntry newEntry(final yacyURL url, final String referrer, final Date ifModifiedSince, final boolean requestWithCookie,@@ -1401,11 +1396,11 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.public static class indexingQueueEntry extends serverProcessorJob {public IndexingStack.QueueEntry queueEntry;- public plasmaParserDocument document;+ public Document document;public Condenser condenser;public indexingQueueEntry(final IndexingStack.QueueEntry queueEntry,- final plasmaParserDocument document,+ final Document document,final Condenser condenser) {super();this.queueEntry = queueEntry;@@ -1658,7 +1653,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.// debugif (log.isFinest()) log.logFinest("PARSE "+ in.queueEntry.toString());- plasmaParserDocument document = null;+ Document document = null;try {document = parseDocument(in.queueEntry);} catch (final InterruptedException e) {@@ -1673,8 +1668,8 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.return new indexingQueueEntry(in.queueEntry, document, null);}- private plasmaParserDocument parseDocument(final IndexingStack.QueueEntry entry) throws InterruptedException {- plasmaParserDocument document = null;+ private Document parseDocument(final IndexingStack.QueueEntry entry) throws InterruptedException {+ Document document = null;final int processCase = entry.processCase();if (this.log.isFine()) log.logFine("processResourceStack processCase=" + processCase +@@ -1691,10 +1686,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.try {// parse the document- document = parser.parseSource(entry.url(), entry.getMimeType(), entry.getCharacterEncoding(), plasmaHTCache.getResourceContent(entry.url()));+ document = ParserDispatcher.parseSource(entry.url(), entry.getMimeType(), entry.getCharacterEncoding(), plasmaHTCache.getResourceContent(entry.url()));assert(document != null) : "Unexpected error. Parser returned null.";} catch (final ParserException e) {- this.log.logInfo("Unable to parse the resource '" + entry.url() + "'. " + e.getMessage());+ this.log.logWarning("Unable to parse the resource '" + entry.url() + "'. " + e.getMessage());addURLtoErrorDB(entry.url(), entry.referrerHash(), entry.initiator(), entry.anchorName(), e.getErrorCode());if (document != null) {document.close();@@ -1703,7 +1698,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.return null;} finally {if (document == null) { // if you get here, comment this part out and you will possibly see a OOM in the log- this.log.logInfo("Unable to parse the resource '" + entry.url() + "'. " + "no parser result");+ this.log.logWarning("Unable to parse the resource '" + entry.url() + "'. " + "no parser result");addURLtoErrorDB(entry.url(), entry.referrerHash(), entry.initiator(), entry.anchorName(), "no parser result");return null;}@@ -1793,7 +1788,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.in.queueEntry.close();}- private void storeDocumentIndex(final IndexingStack.QueueEntry queueEntry, final plasmaParserDocument document, final Condenser condenser) {+ private void storeDocumentIndex(final IndexingStack.QueueEntry queueEntry, final Document document, final Condenser condenser) {// CREATE INDEXfinal String dc_title = document.dc_title();@@ -1934,7 +1929,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.final Long resourceContentLength = (Long) resource[1];// parse the resource- final plasmaParserDocument document = plasmaSnippetCache.parseDocument(metadata.url(), resourceContentLength.longValue(), resourceContent);+ final Document document = plasmaSnippetCache.parseDocument(metadata.url(), resourceContentLength.longValue(), resourceContent);// get the word setSet<String> words = null;diff --git a/source/de/anomic/plasma/plasmaWebStructure.java b/source/de/anomic/plasma/plasmaWebStructure.javaindex 353ff9400..07e50f363 100644--- a/source/de/anomic/plasma/plasmaWebStructure.java+++ b/source/de/anomic/plasma/plasmaWebStructure.java@@ -37,11 +37,12 @@ import java.util.SortedMap;import java.util.TreeMap;import java.util.TreeSet;+import de.anomic.document.Condenser;+import de.anomic.document.Document;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.MicroDate;import de.anomic.kelondro.util.DateFormatter;import de.anomic.kelondro.util.FileUtils;-import de.anomic.plasma.parser.Condenser;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -91,7 +92,7 @@ public class plasmaWebStructure {}}- public Integer[] /*(outlinksSame, outlinksOther)*/ generateCitationReference(final plasmaParserDocument document, final Condenser condenser, final Date docDate) {+ public Integer[] /*(outlinksSame, outlinksOther)*/ generateCitationReference(final Document document, final Condenser condenser, final Date docDate) {final yacyURL url = document.dc_source();// generate citation referencediff --git a/source/de/anomic/search/ImageCollector.java b/source/de/anomic/search/ImageCollector.javaindex 5b238dd3d..d0a5dfc2e 100644--- a/source/de/anomic/search/ImageCollector.java+++ b/source/de/anomic/search/ImageCollector.java@@ -28,22 +28,22 @@ import java.net.MalformedURLException;import java.util.HashMap;import java.util.Iterator;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterImageEntry;+import de.anomic.document.ParserException;+import de.anomic.document.Document;+import de.anomic.document.parser.html.ContentScraper;+import de.anomic.document.parser.html.ImageEntry;import de.anomic.kelondro.util.DateFormatter;-import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaSnippetCache;-import de.anomic.plasma.parser.ParserException;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;public final class ImageCollector {- private final HashMap<String, htmlFilterImageEntry> images;+ private final HashMap<String, ImageEntry> images;public ImageCollector(final long maxTime, final yacyURL url, final int depth, final boolean indexing) {final long start = System.currentTimeMillis();- this.images = new HashMap<String, htmlFilterImageEntry>();+ this.images = new HashMap<String, ImageEntry>();if (maxTime > 10) {Object[] resource = null;try {@@ -55,7 +55,7 @@ public final class ImageCollector {final InputStream res = (InputStream) resource[0];final Long resLength = (Long) resource[1];if (res != null) {- plasmaParserDocument document = null;+ Document document = null;try {// parse the documentdocument = plasmaSnippetCache.parseDocument(url, resLength.longValue(), res);@@ -68,7 +68,7 @@ public final class ImageCollector {if (document == null) return;// add the image links- htmlFilterContentScraper.addAllImages(this.images, document.getImages());+ ContentScraper.addAllImages(this.images, document.getImages());// add also links from pages one step deeper, if depth > 0if (depth > 0) {@@ -90,11 +90,11 @@ public final class ImageCollector {public void addAll(final ImageCollector m) {synchronized (m.images) {- htmlFilterContentScraper.addAllImages(this.images, m.images);+ ContentScraper.addAllImages(this.images, m.images);}}- public Iterator<htmlFilterImageEntry> entries() {+ public Iterator<ImageEntry> entries() {// returns htmlFilterImageEntry - Objectsreturn images.values().iterator();}diff --git a/source/de/anomic/search/IndexCollector.java b/source/de/anomic/search/IndexCollector.javaindex 8114ff426..c5f4add60 100644--- a/source/de/anomic/search/IndexCollector.java+++ b/source/de/anomic/search/IndexCollector.java@@ -34,6 +34,7 @@ import java.util.concurrent.BlockingQueue;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.LinkedBlockingQueue;+import de.anomic.document.Condenser;import de.anomic.kelondro.index.BinSearch;import de.anomic.kelondro.text.ReferenceContainer;import de.anomic.kelondro.text.ReferenceOrder;@@ -44,7 +45,6 @@ import de.anomic.kelondro.text.referencePrototype.WordReferenceVars;import de.anomic.kelondro.util.SortStack;import de.anomic.plasma.plasmaProfiling;import de.anomic.plasma.plasmaSearchEvent;-import de.anomic.plasma.parser.Condenser;import de.anomic.search.Query;import de.anomic.server.serverProfiling;import de.anomic.yacy.yacyURL;diff --git a/source/de/anomic/search/Query.java b/source/de/anomic/search/Query.javaindex 5872ee2fe..bd092b750 100644--- a/source/de/anomic/search/Query.java+++ b/source/de/anomic/search/Query.java@@ -26,14 +26,14 @@ import java.util.HashSet;import java.util.Iterator;import java.util.TreeSet;-import de.anomic.htmlFilter.htmlFilterAbstractScraper;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.Condenser;+import de.anomic.document.Word;+import de.anomic.document.parser.html.AbstractScraper;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.Bitfield;import de.anomic.kelondro.order.NaturalOrder;import de.anomic.kelondro.util.SetTools;-import de.anomic.plasma.parser.Word;-import de.anomic.plasma.parser.Condenser;import de.anomic.yacy.yacySeed;import de.anomic.yacy.yacySeedDB;import de.anomic.yacy.yacyURL;@@ -276,7 +276,7 @@ public final class Query {if ((querystring == null) || (querystring.length() == 0)) return new TreeSet[]{query, exclude, fullquery};// convert Umlaute- querystring = htmlFilterAbstractScraper.stripAll(querystring).toLowerCase().trim();+ querystring = AbstractScraper.stripAll(querystring).toLowerCase().trim();int c;for (int i = 0; i < seps.length(); i++) {while ((c = querystring.indexOf(seps.charAt(i))) >= 0) { querystring = querystring.substring(0, c) + (((c + 1) < querystring.length()) ? (" " + querystring.substring(c + 1)) : ""); }@@ -307,7 +307,7 @@ public final class Query {public String queryString(final boolean encodeHTML) {if(encodeHTML){- return htmlFilterCharacterCoding.unicode2html(this.queryString, true);+ return CharacterCoding.unicode2html(this.queryString, true);}return this.queryString;}diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex 7b8bd61c5..8b00f26a8 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -59,7 +59,6 @@ import javax.net.ssl.SSLSocketFactory;import de.anomic.icap.icapd;import de.anomic.kelondro.util.ByteBuffer;import de.anomic.tools.PKCS12Tool;-import de.anomic.urlRedirector.urlRedirectord;import de.anomic.yacy.logging.Log;public final class serverCore extends serverAbstractBusyThread implements serverBusyThread {diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.javaindex c1ab4182c..02048b859 100644--- a/source/de/anomic/server/serverObjects.java+++ b/source/de/anomic/server/serverObjects.java@@ -52,7 +52,7 @@ import java.util.ArrayList;import java.util.HashMap;import java.util.Map;-import de.anomic.htmlFilter.htmlFilterCharacterCoding;+import de.anomic.document.parser.html.CharacterCoding;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.tools.Formatter;@@ -172,10 +172,10 @@ public class serverObjects extends HashMap<String, String> implements Cloneable* @param key key name as String.* @param value a String that will be reencoded for HTML output.* @return the modified String that was added to the map.- * @see htmlFilterCharacterCoding#encodeUnicode2html(String, boolean)+ * @see CharacterCoding#encodeUnicode2html(String, boolean)*/public String putHTML(final String key, final String value) {- return put(key, htmlFilterCharacterCoding.unicode2html(value, true));+ return put(key, CharacterCoding.unicode2html(value, true));}public String putHTML(final String key, final byte[] value) {return putHTML(key, new String(value));@@ -188,7 +188,7 @@ public class serverObjects extends HashMap<String, String> implements Cloneable* replaced in the returned String.*/public String putXML(final String key, final String value) {- return put(key, htmlFilterCharacterCoding.unicode2xml(value, true));+ return put(key, CharacterCoding.unicode2xml(value, true));}/**diff --git a/source/de/anomic/urlRedirector/urlRedirector.pl b/source/de/anomic/server/urlRedirector.plsimilarity index 100%rename from source/de/anomic/urlRedirector/urlRedirector.plrename to source/de/anomic/server/urlRedirector.pldiff --git a/source/de/anomic/urlRedirector/urlRedirectord.java b/source/de/anomic/server/urlRedirectord.javasimilarity index 93%rename from source/de/anomic/urlRedirector/urlRedirectord.javarename to source/de/anomic/server/urlRedirectord.javaindex 14b50b4da..f1b3c8a89 100644--- a/source/de/anomic/urlRedirector/urlRedirectord.java+++ b/source/de/anomic/server/urlRedirectord.java@@ -1,4 +1,4 @@-package de.anomic.urlRedirector;+package de.anomic.server;import java.io.BufferedReader;import java.io.IOException;@@ -10,12 +10,10 @@ import java.util.Date;import de.anomic.crawler.CrawlEntry;import de.anomic.crawler.CrawlProfile;import de.anomic.data.userDB;+import de.anomic.document.ParserDispatcher;import de.anomic.http.httpClient;import de.anomic.http.httpResponseHeader;-import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.server.serverCore;-import de.anomic.server.serverHandler;import de.anomic.server.serverCore.Session;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -138,7 +136,7 @@ public class urlRedirectord implements serverHandler, Cloneable {}}} else if (line.startsWith("MEDIAEXT")) {- String transferIgnoreList = plasmaParser.getMediaExtList();+ String transferIgnoreList = ParserDispatcher.getMediaExtList();transferIgnoreList = transferIgnoreList.substring(1,transferIgnoreList.length()-1);outputWriter.print(transferIgnoreList);@@ -182,8 +180,7 @@ public class urlRedirectord implements serverHandler, Cloneable {// getting URL mimeTypefinal httpResponseHeader header = httpClient.whead(reqURL.toString());- if (plasmaParser.supportedContent(- plasmaParser.PARSER_MODE_URLREDIRECTOR,+ if (ParserDispatcher.supportedContent(reqURL,header.mime())) {diff --git a/source/de/anomic/tools/DidYouMean.java b/source/de/anomic/tools/DidYouMean.javaindex e9b490214..45c9105d0 100644--- a/source/de/anomic/tools/DidYouMean.java+++ b/source/de/anomic/tools/DidYouMean.java@@ -7,9 +7,9 @@ import java.util.Set;import java.util.TreeSet;import java.util.concurrent.LinkedBlockingQueue;+import de.anomic.document.Word;import de.anomic.kelondro.text.IndexCell;import de.anomic.kelondro.text.referencePrototype.WordReference;-import de.anomic.plasma.parser.Word;import de.anomic.yacy.logging.Log;/**diff --git a/source/de/anomic/tools/mediawikiIndex.java b/source/de/anomic/tools/mediawikiIndex.javaindex f58a6c587..45e004ea1 100644--- a/source/de/anomic/tools/mediawikiIndex.java+++ b/source/de/anomic/tools/mediawikiIndex.java@@ -58,10 +58,10 @@ import java.util.concurrent.TimeoutException;import de.anomic.data.wiki.wikiCode;import de.anomic.data.wiki.wikiParser;+import de.anomic.document.ParserDispatcher;+import de.anomic.document.ParserException;+import de.anomic.document.Document;import de.anomic.kelondro.util.ByteBuffer;-import de.anomic.plasma.plasmaParser;-import de.anomic.plasma.plasmaParserDocument;-import de.anomic.plasma.parser.ParserException;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -80,7 +80,6 @@ public class mediawikiIndex extends Thread {private static final byte[] pageendb = pageend.getBytes();protected wikiParser wparser;- protected plasmaParser hparser;protected String urlStub;public File sourcefile;public File targetdir;@@ -100,12 +99,11 @@ public class mediawikiIndex extends Thread {this.targetdir = targetdir;this.urlStub = baseURL;this.wparser = new wikiCode(new URL(baseURL).getHost());- this.hparser = new plasmaParser();this.count = 0;this.start = 0;// must be called before usage:- plasmaParser.initHTMLParsableMimeTypes("text/html");- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_CRAWLER, "text/html");+ ParserDispatcher.initHTMLParsableMimeTypes("text/html");+ ParserDispatcher.addParseableMimeTypes("text/html");}/**@@ -147,8 +145,8 @@ public class mediawikiIndex extends Thread {StringBuilder sb = new StringBuilder();boolean page = false, text = false;String title = null;- plasmaParser.initHTMLParsableMimeTypes("text/html");- plasmaParser.initParseableMimeTypes(plasmaParser.PARSER_MODE_CRAWLER, "text/html");+ ParserDispatcher.initHTMLParsableMimeTypes("text/html");+ ParserDispatcher.addParseableMimeTypes("text/html");wikiparserrecord poison = newRecord();int threads = Math.max(2, Runtime.getRuntime().availableProcessors() - 1);BlockingQueue<wikiparserrecord> in = new ArrayBlockingQueue<wikiparserrecord>(threads * 10);@@ -473,7 +471,7 @@ public class mediawikiIndex extends Thread {String source;String html;yacyURL url;- plasmaParserDocument document;+ Document document;public wikiparserrecord(String title, StringBuilder sb) {this.title = title;this.source = (sb == null) ? null : sb.toString();@@ -489,7 +487,7 @@ public class mediawikiIndex extends Thread {public void genDocument() throws InterruptedException, ParserException {try {url = new yacyURL(urlStub + title, null);- document = hparser.parseSource(url, "text/html", "utf-8", html.getBytes("UTF-8"));+ document = ParserDispatcher.parseSource(url, "text/html", "utf-8", html.getBytes("UTF-8"));// the wiki parser is not able to find the proper title in the source text, so it must be set heredocument.setTitle(title);} catch (UnsupportedEncodingException e) {diff --git a/source/de/anomic/xml/crawlHandler.java b/source/de/anomic/xml/crawlHandler.javadeleted file mode 100644index ab10b589b..000000000--- a/source/de/anomic/xml/crawlHandler.java+++ /dev/null@@ -1,280 +0,0 @@-// crawlHandler.java-// (C) 2007 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany-// first published 24.07.2007 on http://yacy.net-//-// This is a part of YaCy, a peer-to-peer based web search engine-//-// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $-// $LastChangedRevision: 1986 $-// $LastChangedBy: orbiter $-//-// LICENSE-//-// 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--package de.anomic.xml;--import java.io.InputStream;-import java.util.ArrayList;-import java.util.HashMap;-import java.util.HashSet;--import javax.xml.parsers.SAXParser;-import javax.xml.parsers.SAXParserFactory;--import org.xml.sax.helpers.DefaultHandler;--public class crawlHandler extends DefaultHandler {-- // statics for item generation and automatic categorization- static int guidcount = 0;- private static final String[] startpointTags = new String[]{- "author", //- "copyright", //- "category", //- "title", //- "link", //- "language", //- "description", //- "creator", //- "pubDate", //- "guid", //- "docs" //- };-- private static final HashSet<String> startpointTagsSet = new HashSet<String>();- static {- for (int i = 0; i < startpointTags.length; i++) {- startpointTagsSet.add(startpointTags[i]);- }- }-- // class variables- private Startpoint channel, startpoint;- private StringBuilder buffer;- private boolean parsingAttributes, parsingStartpoint;- private ArrayList<String> startpointsGUID; // a list of GUIDs, so the items can be retrieved by a specific order- private HashMap<String, Startpoint> startpoints; // a guid:Item map--- public crawlHandler(final String path) {- init();- parse(path);- }-- public crawlHandler(final InputStream stream) {- init();- parse(stream);- }-- private void init() {- startpointsGUID = new ArrayList<String>();- startpoints = new HashMap<String, Startpoint>();- buffer = new StringBuilder();- startpoint = null;- channel = null;- parsingAttributes = false;- parsingStartpoint = false;- }-- private void parse(final String path) {- try {- final SAXParserFactory factory = SAXParserFactory.newInstance();- final SAXParser saxParser = factory.newSAXParser();- saxParser.parse(path, this);- } catch (final Exception e) {- e.printStackTrace();- }- }-- private void parse(final InputStream stream) {- try {- final SAXParserFactory factory = SAXParserFactory.newInstance();- final SAXParser saxParser = factory.newSAXParser();- saxParser.parse(stream, this);- } catch (final Exception e) {- e.printStackTrace();- }- }-- public void startElement(final String tag) {- if ("channel".equals(tag)) {- channel = new Startpoint();- parsingAttributes = true;- } else if ("item".equals(tag)) {- startpoint = new Startpoint();- parsingStartpoint = true;- }- }-- public void endElement(final String uri, final String name, final String tag) {- if (tag == null) return;- if ("channel".equals(tag)) {- parsingAttributes = false;- } else if ("item".equals(tag)) {- final String guid = startpoint.getGuid();- startpointsGUID.add(guid);- startpoints.put(guid, startpoint);- parsingStartpoint = false;- } else if (parsingStartpoint) {- final String value = buffer.toString().trim();- buffer.setLength(0);- if (startpointTagsSet.contains(tag)) startpoint.setValue(tag, value);- } else if (parsingAttributes) {- final String value = buffer.toString().trim();- buffer.setLength(0);- if (startpointTagsSet.contains(tag)) channel.setValue(tag, value);- }- }-- public void characters(final char ch[], final int start, final int length) {- if (parsingStartpoint || parsingAttributes) {- buffer.append(ch, start, length);- }- }-- public Startpoint getChannel() {- return channel;- }-- public Startpoint getStartpoint(final int i) {- // retrieve item by order number- return getStartpoint(startpointsGUID.get(i));- }-- public Startpoint getStartpoint(final String guid) {- // retrieve item by guid- return startpoints.get(guid);- }-- public int startpoints() {- return startpoints.size();- }-- public static class Attributes {-- private final HashMap<String, String> map;-- public Attributes() {- this.map = new HashMap<String, String>();- }-- public void setValue(final String name, final String value) {- map.put(name, value);- }-- public String getAuthor() {- return map.get("author");- }-- public String getCopyright() {- return map.get("copyright");- }-- public String getCategory() {- return map.get("category");- }-- public String getTitle() {- return map.get("title");- }-- public String getLink() {- return map.get("link");- }-- public String getLanguage() {- return map.get("language");- }-- public String getDescription() {- return map.get("description");- }-- public String getCreator() {- return map.get("creator");- }-- public String getPubDate() {- return map.get("pubDate");- }-- public String getGuid() {- return map.get("guid");- }-- public String getDocs() {- return map.get("docs");- }- }-- public static class Startpoint {-- private final HashMap<String, String> map;-- public Startpoint() {- this.map = new HashMap<String, String>();- this.map.put("guid", Long.toHexString(System.currentTimeMillis()) + ":" + guidcount++);- }-- public void setValue(final String name, final String value) {- map.put(name, value);- }-- public String getAuthor() {- return map.get("author");- }-- public String getCopyright() {- return map.get("copyright");- }-- public String getCategory() {- return map.get("category");- }-- public String getTitle() {- return map.get("title");- }-- public String getLink() {- return map.get("link");- }-- public String getLanguage() {- return map.get("language");- }-- public String getDescription() {- return map.get("description");- }-- public String getCreator() {- return map.get("creator");- }-- public String getPubDate() {- return map.get("pubDate");- }-- public String getGuid() {- return map.get("guid");- }-- public String getDocs() {- return map.get("docs");- }- }-}\ No newline at end of filediff --git a/source/de/anomic/plasma/LogParser.java b/source/de/anomic/yacy/logging/LogParser.javasimilarity index 98%rename from source/de/anomic/plasma/LogParser.javarename to source/de/anomic/yacy/logging/LogParser.javaindex 8e96f594a..ffe4f0b29 100644--- a/source/de/anomic/plasma/LogParser.java+++ b/source/de/anomic/yacy/logging/LogParser.java@@ -23,7 +23,7 @@//along with this program; if not, write to the Free Software//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.plasma;+package de.anomic.yacy.logging;import java.util.HashSet;import java.util.Hashtable;diff --git a/source/de/anomic/yacy/logging/LogalizerHandler.java b/source/de/anomic/yacy/logging/LogalizerHandler.javaindex 38015149d..621ea9ad6 100644--- a/source/de/anomic/yacy/logging/LogalizerHandler.java+++ b/source/de/anomic/yacy/logging/LogalizerHandler.java@@ -25,30 +25,16 @@package de.anomic.yacy.logging;-import java.io.File;-import java.io.IOException;-import java.net.URISyntaxException;-import java.util.ArrayList;-import java.util.HashMap;import java.util.Hashtable;-import java.util.Iterator;-import java.util.Set;import java.util.logging.Handler;import java.util.logging.LogManager;import java.util.logging.LogRecord;-import java.util.regex.Matcher;-import java.util.regex.Pattern;-import de.anomic.plasma.LogParser;-import de.anomic.plasma.plasmaParser;-import de.anomic.tools.ListDirs;public class LogalizerHandler extends Handler {public static boolean enabled=false;public static boolean debug=false;- private String logParserPackage;- private HashMap<String, Object> parsers;public LogalizerHandler() {super();@@ -58,76 +44,11 @@ public class LogalizerHandler extends Handler {if(manager.getProperty(className + ".enabled").equalsIgnoreCase("true")) enabled = true;if(manager.getProperty(className + ".debug").equalsIgnoreCase("true")) debug = true;-- logParserPackage = manager.getProperty(className + ".parserPackage");-- parsers = new HashMap<String, Object>();- try {- if (debug) System.out.println("Searching for additional content parsers in package " + logParserPackage);- // getting an uri to the parser subpackage- final String packageURI = plasmaParser.class.getResource("/"+logParserPackage.replace('.','/')).toString();- if (debug) System.out.println("LogParser directory is " + packageURI);-- final ListDirs parserDir = new ListDirs(packageURI);- final ArrayList<String> parserDirFiles = parserDir.listFiles(".*\\.class");- if(parserDirFiles.size() == 0 && debug) {- System.out.println("Can't find any parsers in "+parserDir.toString());- }- for (final String filename: parserDirFiles) {- if (filename.endsWith("Log.class") || filename.endsWith("LogalizerHandler.class")) continue;- registerParser(filename);- }- } catch (final IOException e) {- e.printStackTrace();- } catch (final URISyntaxException e) {- e.printStackTrace();- }- }-- private void registerParser(String filename) {- try {- final Pattern patternGetClassName = Pattern.compile(".*\\"+ File.separator +"([^\\"+ File.separator +"]+)\\.class");- final Matcher matcherClassName = patternGetClassName.matcher(filename);- matcherClassName.find();- String className = matcherClassName.group(1);- final Class<?> tempClass = Class.forName(logParserPackage+"."+className);- if (tempClass.isInterface()) {- if (debug) System.out.println(tempClass.getName() + " is an Interface");- } else {- final Object theParser = tempClass.newInstance();- if (theParser instanceof LogParser) {- final LogParser theLogParser = (LogParser) theParser;- //System.out.println(bla.getName() + " is a logParser");- parsers.put(theLogParser.getParserType(), theParser);-- if (debug) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser.");- }- else {- //System.out.println(bla.getName() + " is not a logParser");- if (debug) System.out.println("Rejected " + tempClass.getName() + ". Class does not implement the logParser-Interface");-- }- }- } catch (final ClassNotFoundException e) {- e.printStackTrace();- } catch (final InstantiationException e) {- e.printStackTrace();- } catch (final IllegalAccessException e) {- e.printStackTrace();- }- }-- public void registerParser(LogParser theParser) {- final LogParser theLogParser = (LogParser) theParser;- //System.out.println(bla.getName() + " is a logParser");- parsers.put(theLogParser.getParserType(), theParser);-- if (debug) System.out.println("Added " + theLogParser.getClass().getName() + " as " + theLogParser.getParserType() + " Parser.");}public void publish(final LogRecord record) {if (enabled) {- final LogParser temp = (LogParser) parsers.get(record.getLoggerName());+ final LogParser temp = new LogParser();if (temp != null) try {final int returnV = temp.parse(record.getLevel().toString(), record.getMessage());//if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel() + " --- " + record.getMessage());@@ -137,40 +58,13 @@ public class LogalizerHandler extends Handler {flush();}- public Set<String> getParserNames() {- return parsers.keySet();- }-- public LogParser getParser(final int number) {- String o;- final Iterator<String> it = parsers.keySet().iterator();- int i = 0;- while (it.hasNext()) {- o = it.next();- if (i++ == number)- return (LogParser) parsers.get(o);- }- return null;- }-public Hashtable<String, Object> getParserResults(final LogParser parsername) {return (parsername == null) ? null : parsername.getResults();}public void close() throws SecurityException {- // TODO Auto-generated method stub-}public void flush() {- // TODO Auto-generated method stub-}- /*- private static final FilenameFilter parserNameFilter = new FilenameFilter() {- public boolean accept(File dir, String name) {- return name.matches(".*.class");- }- };- */}diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.javaindex baab59529..e2c2828fa 100644--- a/source/de/anomic/yacy/yacyClient.java+++ b/source/de/anomic/yacy/yacyClient.java@@ -61,6 +61,9 @@ import org.apache.commons.httpclient.methods.multipart.Part;import de.anomic.crawler.HTTPLoader;import de.anomic.crawler.ResultURLs;import de.anomic.data.Blacklist;+import de.anomic.document.Word;+import de.anomic.document.parser.xml.RSSFeed;+import de.anomic.document.parser.xml.RSSReader;import de.anomic.http.DefaultCharsetFilePart;import de.anomic.http.DefaultCharsetStringPart;import de.anomic.http.httpClient;@@ -83,13 +86,10 @@ import de.anomic.plasma.plasmaSearchRankingProcess;import de.anomic.plasma.plasmaSnippetCache;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;-import de.anomic.plasma.parser.Word;import de.anomic.search.RankingProfile;import de.anomic.server.serverCore;import de.anomic.server.serverDomains;import de.anomic.tools.crypt;-import de.anomic.xml.RSSFeed;-import de.anomic.xml.RSSReader;public final class yacyClient {diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.javaindex 25a612fa3..279989cac 100644--- a/source/de/anomic/yacy/yacyCore.java+++ b/source/de/anomic/yacy/yacyCore.java@@ -52,11 +52,11 @@ import java.util.List;import java.util.Map;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.kelondro.util.DateFormatter;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;import de.anomic.server.serverSemaphore;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.dht.PeerSelection;import de.anomic.yacy.logging.Log;diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.javaindex 84c0752cf..3fe6b1537 100644--- a/source/de/anomic/yacy/yacyPeerActions.java+++ b/source/de/anomic/yacy/yacyPeerActions.java@@ -28,9 +28,9 @@ import java.io.IOException;import java.util.HashMap;import de.anomic.content.RSSMessage;+import de.anomic.document.parser.xml.RSSFeed;import de.anomic.kelondro.util.DateFormatter;import de.anomic.server.serverCodings;-import de.anomic.xml.RSSFeed;import de.anomic.yacy.logging.Log;public class yacyPeerActions {diff --git a/source/de/anomic/yacy/yacyRelease.java b/source/de/anomic/yacy/yacyRelease.javaindex 07e0121f6..8765ecae6 100644--- a/source/de/anomic/yacy/yacyRelease.java+++ b/source/de/anomic/yacy/yacyRelease.java@@ -45,7 +45,7 @@ import java.util.SortedSet;import java.util.TreeSet;import de.anomic.crawler.HTTPLoader;-import de.anomic.htmlFilter.htmlFilterContentScraper;+import de.anomic.document.parser.html.ContentScraper;import de.anomic.http.httpClient;import de.anomic.http.httpHeader;import de.anomic.http.httpResponse;@@ -222,9 +222,9 @@ public final class yacyRelease extends yacyVersion {// this is done by contacting a release location,// parsing the content and filtering+parsing links// returns the version info if successful, null otherwise- htmlFilterContentScraper scraper;+ ContentScraper scraper;try {- scraper = htmlFilterContentScraper.parseResource(location.getLocationURL());+ scraper = ContentScraper.parseResource(location.getLocationURL());} catch (final IOException e) {return null;}diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.javaindex 2894af532..3441c6df8 100644--- a/source/de/anomic/yacy/yacySeed.java+++ b/source/de/anomic/yacy/yacySeed.java@@ -56,11 +56,11 @@ import java.util.Set;import java.util.TreeMap;import java.util.TreeSet;+import de.anomic.document.Word;import de.anomic.kelondro.order.Base64Order;import de.anomic.kelondro.order.Digest;import de.anomic.kelondro.util.DateFormatter;import de.anomic.net.natLib;-import de.anomic.plasma.parser.Word;import de.anomic.server.serverCodings;import de.anomic.server.serverDomains;import de.anomic.server.serverSystem;diff --git a/source/de/anomic/ymage/ymageOSM.java b/source/de/anomic/ymage/ymageOSM.javaindex 35391ed0c..11986b59f 100644--- a/source/de/anomic/ymage/ymageOSM.java+++ b/source/de/anomic/ymage/ymageOSM.java@@ -35,9 +35,9 @@ import java.net.MalformedURLException;import javax.imageio.ImageIO;+import de.anomic.http.httpDocument;import de.anomic.plasma.plasmaHTCache;import de.anomic.plasma.plasmaSwitchboard;-import de.anomic.plasma.parser.Document;import de.anomic.yacy.yacyURL;import de.anomic.yacy.logging.Log;@@ -80,7 +80,7 @@ public class ymageOSM {InputStream tileStream = plasmaHTCache.getResourceContentStream(tileURL);if (tileStream == null) {// download resource using the crawler and keep resource in memory if possible- Document entry = null;+ httpDocument entry = null;try {entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(tileURL, false, false);} catch (IOException e) {diff --git a/source/yacy.java b/source/yacy.javaindex ebb44fc3f..08a2491f8 100644--- a/source/yacy.java+++ b/source/yacy.java@@ -48,6 +48,7 @@ import java.util.zip.ZipOutputStream;import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;import de.anomic.data.translator;+import de.anomic.document.Word;import de.anomic.http.httpClient;import de.anomic.http.httpResponse;import de.anomic.http.httpRequestHeader;@@ -68,7 +69,6 @@ import de.anomic.kelondro.util.ScoreCluster;import de.anomic.kelondro.util.FileUtils;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.plasma.plasmaSwitchboardConstants;-import de.anomic.plasma.parser.Word;import de.anomic.server.serverCore;import de.anomic.server.serverSemaphore;import de.anomic.server.serverSystem;