Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) restructuring needed to support parsing of documents using various charsets - serverFileUtils.java: -- adding methods to copy from stream to writer and readers to writers -- moving httpc writeX methods into serverFileUtils class - serverCharBuffer.java: removing inheritance from Writer class - replacing htmlFilterOutputStream by htmlFilterWriter class which handles content as char stream - htmlFilterContentTransformer.java: deactivating getText mode (still needs to be migrated to use char streams instead of byte streams) - changes in several classes to use htmlFilterWriter instead of htmlFilterOutputStream - changes in Scraper and Transformer classes to operate on chars instead of bytes - httpdProxyHandler.java: bugfix. clientTimeout setting was missing in config file
theli97d2a08ef1c8
diff --git a/htroot/CacheAdmin_p.java b/htroot/CacheAdmin_p.javaindex cb9c41a39..3fbc3ccbf 100644--- a/htroot/CacheAdmin_p.java+++ b/htroot/CacheAdmin_p.java@@ -48,13 +48,15 @@import java.io.File;import java.io.OutputStream;-import de.anomic.net.URL;+import java.io.Writer;import java.util.Iterator;import java.util.Map;import java.util.TreeSet;+import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterOutputStream;+import de.anomic.htmlFilter.htmlFilterWriter;import de.anomic.http.httpHeader;+import de.anomic.net.URL;import de.anomic.plasma.plasmaHTCache;import de.anomic.plasma.plasmaParserDocument;import de.anomic.plasma.plasmaSwitchboard;@@ -112,9 +114,14 @@ public class CacheAdmin_p {info.append("<img src=\"" + "CacheResource_p.html?path=").append(pathString).append("\">");} else {final htmlFilterContentScraper scraper = new htmlFilterContentScraper(url);- final OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- serverFileUtils.copy(file, os);- final plasmaParserDocument document = switchboard.parser.transformScraper(url, "text/html", scraper);+ //final OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);+ Writer writer = new htmlFilterWriter(null,null,scraper,null,false);+ String sourceCharset = resInfo.getCharacterEncoding();+ if (sourceCharset == null) sourceCharset = "UTF-8";+ String mimeType = resInfo.getMimeType();+ serverFileUtils.copy(file, sourceCharset, writer);+ writer.close();+ final plasmaParserDocument document = switchboard.parser.transformScraper(url, mimeType, sourceCharset, scraper);info.append("<b>TITLE:</b><br>").append(scraper.getTitle()).append("<br>").append("<br>").append("<b>SECTION HEADLINES:</b><br>").append(formatTitles(document.getSectionTitles())).append("<br>").append("<b>HREF:</b><br>").append(formatAnchor(document.getHyperlinks())).append("<br>")diff --git a/htroot/IndexCreate_p.java b/htroot/IndexCreate_p.javaindex 8387e554a..9eb74eabb 100644--- a/htroot/IndexCreate_p.java+++ b/htroot/IndexCreate_p.java@@ -44,10 +44,9 @@// if the shell's current path is HTROOTimport java.io.File;-import java.io.OutputStream;import java.io.IOException;+import java.io.Writer;import java.net.MalformedURLException;-import de.anomic.net.URL;import java.util.Date;import java.util.Enumeration;import java.util.HashMap;@@ -58,9 +57,10 @@ import java.util.regex.PatternSyntaxException;import de.anomic.data.wikiCode;import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterOutputStream;+import de.anomic.htmlFilter.htmlFilterWriter;import de.anomic.http.httpHeader;import de.anomic.index.indexURL;+import de.anomic.net.URL;import de.anomic.plasma.plasmaCrawlEURL;import de.anomic.plasma.plasmaCrawlProfile;import de.anomic.plasma.plasmaSwitchboard;@@ -70,9 +70,9 @@ import de.anomic.server.serverSwitch;import de.anomic.server.serverThread;import de.anomic.tools.bitfield;import de.anomic.yacy.yacyCore;-import de.anomic.yacy.yacySeed;-import de.anomic.yacy.yacyNewsRecord;import de.anomic.yacy.yacyNewsPool;+import de.anomic.yacy.yacyNewsRecord;+import de.anomic.yacy.yacySeed;public class IndexCreate_p {@@ -234,11 +234,15 @@ public class IndexCreate_p {// getting the content of the bookmark filebyte[] fileContent = (byte[]) post.get("crawlingFile$file");+ // TODO: determine the real charset here ....+ String fileString = new String(fileContent,"UTF-8");+// parsing the bookmark file and fetching the headline and contained linkshtmlFilterContentScraper scraper = new htmlFilterContentScraper(new URL(file));- OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- serverFileUtils.write(fileContent,os);- os.close();+ //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);+ Writer writer = new htmlFilterWriter(null,null,scraper,null,false);+ serverFileUtils.write(fileString,writer);+ writer.close();//String headline = scraper.getHeadline();HashMap hyperlinks = (HashMap) scraper.getAnchors();diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.javaindex 98eba79db..a657371d2 100644--- a/source/de/anomic/data/bookmarksDB.java+++ b/source/de/anomic/data/bookmarksDB.java@@ -44,8 +44,7 @@ package de.anomic.data;import java.io.ByteArrayInputStream;import java.io.File;import java.io.IOException;-import java.io.OutputStream;-import de.anomic.net.URL;+import java.io.Writer;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;@@ -67,13 +66,15 @@ import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;+import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterOutputStream;+import de.anomic.htmlFilter.htmlFilterWriter;import de.anomic.index.indexEntryAttribute;import de.anomic.index.indexURL;import de.anomic.kelondro.kelondroDyn;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroMap;+import de.anomic.net.URL;import de.anomic.server.serverFileUtils;import de.anomic.server.logging.serverLog;@@ -441,9 +442,10 @@ public class bookmarksDB {try {//load the linkshtmlFilterContentScraper scraper = new htmlFilterContentScraper(baseURL);- OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- serverFileUtils.write(input.getBytes(),os);- os.close();+ //OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);+ Writer writer= new htmlFilterWriter(null,null,scraper, null, false);+ serverFileUtils.write(input,writer);+ writer.close();links = (HashMap) scraper.getAnchors();} catch (IOException e) {}it=links.keySet().iterator();diff --git a/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.java b/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.javaindex 0a2e8583a..092cf6514 100644--- a/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.java+++ b/source/de/anomic/htmlFilter/htmlFilterAbstractScraper.java@@ -1 +1 @@-// htmlFilterAbstractScraper.java // --------------------------- // (C) by Michael Peter Christen; [email protected] // first published on http://www.anomic.de // Frankfurt, Germany, 2004 // last major change: 18.02.2004 // // You agree that the Author(s) is (are) not responsible for cost, // loss of data or any harm that may be caused by usage of this softare or // this documentation. The usage of this software is on your own risk. The // installation and usage (starting/running) of this software may allow other // people or application to access your computer and any attached devices and // is highly dependent on the configuration of the software which must be // done by the user of the software;the author(s) is (are) also // not responsible for proper configuration and usage of the software, even // if provoked by documentation provided together with the software. // // THE SOFTWARE THAT FOLLOWS AS ART OF PROGRAMMING BELOW THIS SECTION // IS PUBLISHED UNDER THE GPL AS DOCUMENTED IN THE FILE gpl.txt ASIDE THIS // FILE AND AS IN http://www.gnu.org/licenses/gpl.txt // ANY CHANGES TO THIS FILE ACCORDING TO THE GPL CAN BE DONE TO THE // LINES THAT FOLLOWS THIS COPYRIGHT NOTICE HERE, BUT CHANGES MUST NOT // BE DONE ABOVE OR INSIDE THE COPYRIGHT NOTICE. A RE-DISTRIBUTION // MUST CONTAIN THE INTACT AND UNCHANGED COPYRIGHT NOTICE. // CONTRIBUTIONS AND CHANGES TO THE PROGRAM CODE SHOULD BE MARKED AS SUCH. package de.anomic.htmlFilter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Properties; import java.util.TreeSet; import de.anomic.server.serverByteBuffer; public abstract class htmlFilterAbstractScraper implements htmlFilterScraper { public static final byte lb = (byte) '<'; public static final byte rb = (byte) '>'; public static final byte sl = (byte) '/'; private TreeSet tags0; private TreeSet tags1; // define a translation table for html character codings private static HashMap trans = new HashMap(300); static { trans.put(""", "\""); //Anführungszeichen oben trans.put("&", "&"); //Ampersand-Zeichen, kaufmännisches Und trans.put("<", "<"); //öffnende spitze Klammer trans.put(">", ">"); //schließende spitze Klammer trans.put(" ", " "); //Erzwungenes Leerzeichen trans.put("¡", "!"); //umgekehrtes Ausrufezeichen trans.put("¢", " cent "); //Cent-Zeichen trans.put("£", " pound "); //Pfund-Zeichen trans.put("¤", " currency "); //Währungs-Zeichen trans.put("¥", " yen "); //Yen-Zeichen trans.put("¦", " "); //durchbrochener Strich trans.put("§", " paragraph "); //Paragraph-Zeichen trans.put("¨", " "); //Pünktchen oben trans.put("©", " copyright "); //Copyright-Zeichen trans.put("ª", " "); //Ordinal-Zeichen weiblich trans.put("«", " "); //angewinkelte Anführungszeichen links trans.put("¬", " not "); //Verneinungs-Zeichen trans.put("­", "-"); //kurzer Trennstrich trans.put("®", " trademark "); //Registriermarke-Zeichen trans.put("¯", " "); //Überstrich trans.put("°", " degree "); //Grad-Zeichen trans.put("±", " +/- "); //Plusminus-Zeichen trans.put("²", " square "); //Hoch-2-Zeichen trans.put("³", " 3 "); //Hoch-3-Zeichen trans.put("´", " "); //Acute-Zeichen trans.put("µ", " micro "); //Mikro-Zeichen trans.put("¶", " paragraph "); //Absatz-Zeichen trans.put("·", " "); //Mittelpunkt trans.put("¸", " "); //Häkchen unten trans.put("¹", " "); //Hoch-1-Zeichen trans.put("º", " degree "); //Ordinal-Zeichen männlich trans.put("»", " "); //angewinkelte Anführungszeichen rechts trans.put("¼", " quarter "); //ein Viertel trans.put("½", " half "); //ein Halb trans.put("¾", " 3/4 "); //drei Viertel trans.put("¿", "?"); //umgekehrtes Fragezeichen trans.put("À", "A"); //A mit Accent grave trans.put("Á", "A"); //A mit Accent acute trans.put("Â", "A"); //A mit Circumflex trans.put("Ã", "A"); //A mit Tilde trans.put("Ä", "Ae"); //A Umlaut trans.put("Å", "A"); //A mit Ring trans.put("Æ", "A"); //A mit legiertem E trans.put("Ç", "C"); //C mit Häkchen trans.put("È", "E"); //E mit Accent grave trans.put("É", "E"); //E mit Accent acute trans.put("Ê", "E"); //E mit Circumflex trans.put("Ë", "E"); //E Umlaut trans.put("Ì", "I"); //I mit Accent grave trans.put("Í", "I"); //I mit Accent acute trans.put("Î", "I"); //I mit Circumflex trans.put("Ï", "I"); //I Umlaut trans.put("Ð", "D"); //Eth (isländisch) trans.put("Ñ", "N"); //N mit Tilde trans.put("Ò", "O"); //O mit Accent grave trans.put("Ó", "O"); //O mit Accent acute trans.put("Ô", "O"); //O mit Circumflex trans.put("Õ", "O"); //O mit Tilde trans.put("Ö", "Oe"); //O Umlaut trans.put("×", " times "); //Mal-Zeichen trans.put("Ø", "O"); //O mit Schrägstrich trans.put("Ù", "U"); //U mit Accent grave trans.put("Ú", "U"); //U mit Accent acute trans.put("Û", "U"); //U mit Circumflex trans.put("Ü", "Ue"); //U Umlaut trans.put("Ý", "Y"); //Y mit Accent acute trans.put("Þ", "P"); //THORN (isländisch) trans.put("ß", "ss"); //scharfes S trans.put("à", "a"); //a mit Accent grave trans.put("á", "a"); //a mit Accent acute trans.put("â", "a"); //a mit Circumflex trans.put("ã", "a"); //a mit Tilde trans.put("ä", "ae"); //a Umlaut trans.put("å", "a"); //a mit Ring trans.put("æ", "a"); //a mit legiertem e trans.put("ç", "c"); //c mit Häkchen trans.put("è", "e"); //e mit Accent grave trans.put("é", "e"); //e mit Accent acute trans.put("ê", "e"); //e mit Circumflex trans.put("ë", "e"); //e Umlaut trans.put("ì", "i"); //i mit Accent grave trans.put("í", "i"); //i mit Accent acute trans.put("î", "i"); //i mit Circumflex trans.put("ï", "i"); //i Umlaut trans.put("ð", "d"); //eth (isländisch) trans.put("ñ", "n"); //n mit Tilde trans.put("ò", "o"); //o mit Accent grave trans.put("ó", "o"); //o mit Accent acute trans.put("ô", "o"); //o mit Circumflex trans.put("õ", "o"); //o mit Tilde trans.put("ö", "oe"); //o Umlaut trans.put("÷", "%"); //Divisions-Zeichen trans.put("ø", "o"); //o mit Schrägstrich trans.put("ù", "u"); //u mit Accent grave trans.put("ú", "u"); //u mit Accent acute trans.put("û", "u"); //u mit Circumflex trans.put("ü", "ue"); //u Umlaut trans.put("ý", "y"); //y mit Accent acute trans.put("þ", "p"); //thorn (isländisch) trans.put("ÿ", "y"); //y Umlaut trans.put("Α", " Alpha "); //Alpha groß trans.put("α", " alpha "); //alpha klein trans.put("Β", " Beta "); //Beta groß trans.put("β", " beta "); //beta klein trans.put("Γ", " Gamma "); //Gamma groß trans.put("γ", " gamma "); //gamma klein trans.put("Δ", " Delta "); //Delta groß trans.put("δ", " delta "); //delta klein trans.put("Ε", " Epsilon "); //Epsilon groß trans.put("ε", " epsilon "); //epsilon klein trans.put("Ζ", " Zeta "); //Zeta groß trans.put("ζ", " zeta "); //zeta klein trans.put("Η", " Eta "); //Eta groß trans.put("η", " eta "); //eta klein trans.put("Θ", " Theta "); //Theta groß trans.put("θ", " theta "); //theta klein trans.put("Ι", " Iota "); //Iota groß trans.put("ι", " iota "); //iota klein trans.put("Κ", " Kappa "); //Kappa groß trans.put("κ", " kappa "); //kappa klein trans.put("Λ", " Lambda "); //Lambda groß trans.put("λ", " lambda "); //lambda klein trans.put("Μ", " Mu "); //Mu groß trans.put("μ", " mu "); //mu klein trans.put("Ν", " Nu "); //Nu groß trans.put("ν", " nu "); //nu klein trans.put("Ξ", " Xi "); //Xi groß trans.put("ξ", " xi "); //xi klein trans.put("Ο", " Omicron "); //Omicron groß trans.put("ο", " omicron "); //omicron klein trans.put("Π", " Pi "); //Pi groß trans.put("π", " pi "); //pi klein trans.put("Ρ", " Rho "); //Rho groß trans.put("ρ", " rho "); //rho klein trans.put("Σ", " Sigma "); //Sigma groß trans.put("ς", " sigma "); //sigmaf klein trans.put("σ", " sigma "); //sigma klein trans.put("Τ", " Tau "); //Tau groß trans.put("τ", " tau "); //tau klein trans.put("Υ", " Ypsilon "); //Upsilon groß trans.put("υ", " ypsilon "); //upsilon klein trans.put("Φ", " Phi "); //Phi groß trans.put("φ", " phi "); //phi klein trans.put("Χ", " Chi "); //Chi groß trans.put("χ", " chi "); //chi klein trans.put("Ψ", " Psi "); //Psi groß trans.put("ψ", " psi "); //psi klein trans.put("Ω", " Omega "); //Omega groß trans.put("ω", " omega "); //omega klein trans.put("ϑ", " theta "); //theta Symbol trans.put("ϒ", " ypsilon "); //upsilon mit Haken trans.put("ϖ", " pi "); //pi Symbol trans.put("∀", " for all "); //für alle trans.put("∂", " part of "); //teilweise trans.put("∃", " exists "); //existiert trans.put("∅", " null "); //leer trans.put("∇", " nabla "); //nabla trans.put("∈", " element of "); //Element von trans.put("∉", " not element of "); //kein Element von trans.put("∋", " contains "); //enthält als Element trans.put("∏", " product "); //Produkt trans.put("∑", " sum "); //Summe trans.put("−", " minus "); //minus trans.put("∗", " times "); //Asterisk trans.put("√", " sqare root "); //Quadratwurzel trans.put("∝", " proportional to "); //proportional zu trans.put("∞", " unlimited "); //unendlich trans.put("∠", " angle "); //Winkel trans.put("∧", " and "); //und trans.put("∨", " or "); //oder trans.put("∩", " "); //Schnittpunkt trans.put("∪", " unity "); //Einheit trans.put("∫", " integral "); //Integral trans.put("∴", " cause "); //deshalb trans.put("∼", " similar to "); //ähnlich wie trans.put("≅", " equal "); //annähernd gleich trans.put("≈", " equal "); //beinahe gleich trans.put("≠", " not equal "); //ungleich trans.put("≡", " identical "); //identisch mit trans.put("≤", " smaller or equal than "); //kleiner gleich trans.put("≥", " greater or equal than "); //größer gleich trans.put("⊂", " subset of "); //Untermenge von trans.put("⊃", " superset of "); //Obermenge von trans.put("⊄", " not subset of "); //keine Untermenge von trans.put("⊆", ""); //Untermenge von oder gleich mit trans.put("⊇", ""); //Obermenge von oder gleich mit trans.put("⊕", ""); //Direktsumme trans.put("⊗", ""); //Vektorprodukt trans.put("⊥", ""); //senkrecht zu trans.put("⋅", ""); //Punkt-Operator trans.put("◊", ""); //Raute trans.put("⌈", ""); //links oben trans.put("⌉", ""); //rechts oben trans.put("⌊", ""); //links unten trans.put("⌋", ""); //rechts unten trans.put("⟨", ""); //spitze Klammer links trans.put("⟩", ""); //spitze Klammer rechts trans.put("←", ""); //Pfeil links trans.put("↑", ""); //Pfeil oben trans.put("→", ""); //Pfeil rechts trans.put("↓", ""); //Pfeil unten trans.put("↔", ""); //Pfeil links/rechts trans.put("↵", ""); //Pfeil unten-Knick-links trans.put("⇐", ""); //Doppelpfeil links trans.put("⇑", ""); //Doppelpfeil oben trans.put("⇒", ""); //Doppelpfeil rechts trans.put("⇓", ""); //Doppelpfeil unten trans.put("⇔", ""); //Doppelpfeil links/rechts trans.put("•", ""); //Bullet-Zeichen trans.put("…", ""); //Horizontale Ellipse trans.put("′", ""); //Minutenzeichen trans.put("‾", ""); //Überstrich trans.put("⁄", ""); //Bruchstrich trans.put("℘", ""); //Weierstrass p trans.put("ℑ", ""); //Zeichen für "imaginär" trans.put("ℜ", ""); //Zeichen für "real" trans.put("™", ""); //Trademark-Zeichen trans.put("€", ""); //Euro-Zeichen trans.put("ℵ", ""); //Alef-Symbol trans.put("♠", ""); //Pik-Zeichen trans.put("♣", ""); //Kreuz-Zeichen trans.put("♥", ""); //Herz-Zeichen trans.put("♦", ""); //Karo-Zeichen trans.put(" ", ""); //Leerzeichen Breite n trans.put(" ", ""); //Leerzeichen Breite m trans.put(" ", ""); //Schmales Leerzeichen trans.put("‌", ""); //null breiter Nichtverbinder trans.put("‍", ""); //null breiter Verbinder trans.put("‎", ""); //links-nach-rechts-Zeichen trans.put("‏", ""); //rechts-nach-links-Zeichen trans.put("–", ""); //Gedankenstrich Breite n trans.put("—", ""); //Gedankenstrich Breite m trans.put("‘", ""); //einfaches Anführungszeichen links trans.put("’", ""); //einfaches Anführungszeichen rechts trans.put("‚", ""); //einfaches low-9-Zeichen trans.put("“", ""); //doppeltes Anführungszeichen links trans.put("”", ""); //doppeltes Anführungszeichen rechts trans.put("„", ""); //doppeltes low-9-Zeichen rechts trans.put("†", ""); //Kreuz trans.put("‡", ""); //Doppelkreuz trans.put("‰", ""); //zu tausend trans.put("‹", ""); //angewinkeltes einzelnes Anf.zeichen links trans.put("›", ""); //angewinkeltes einzelnes Anf.zeichen rechts } public htmlFilterAbstractScraper(TreeSet tags0, TreeSet tags1) { this.tags0 = tags0; this.tags1 = tags1; } public boolean isTag0(String tag) { return (tags0 != null) && (tags0.contains(tag)); } public boolean isTag1(String tag) { return (tags1 != null) && (tags1.contains(tag)); } //the 'missing' method that shall be implemented: public abstract void scrapeText(byte[] text); // the other methods must take into account to construct the return value correctly public void scrapeTag0(String tagname, Properties tagopts) { } public void scrapeTag1(String tagname, Properties tagopts, byte[] text) { } // string conversions private static String code_iso8859s(int c) { switch (c & 0xff) { // german umlaute and ligaturen case 0xc4: return "AE"; case 0xd6: return "OE"; case 0xdc: return "UE"; case 0xe4: return "ae"; case 0xf6: return "oe"; case 0xfc: return "ue"; case 0xdf: return "ss"; // accent on letters; i.e. french characters case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc5: return "A"; case 0xc6: return "AE"; case 0xc7: return "C"; case 0xc8: case 0xc9: case 0xca: return "E"; case 0xcc: case 0xcd: case 0xce: case 0xcf: return "I"; case 0xd0: return "D"; case 0xd1: return "N"; case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd8: return "O"; case 0xd7: return "x"; case 0xd9: case 0xda: case 0xdb: return "U"; case 0xdd: return "Y"; case 0xde: return "p"; case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe5: return "a"; case 0xe6: return "ae"; case 0xe7: return "c"; case 0xe8: case 0xe9: case 0xea: return "e"; case 0xec: case 0xed: case 0xee: case 0xef: return "i"; case 0xf0: return "d"; case 0xf1: return "n"; case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf8: return "o"; case 0xf7: return "%"; case 0xf9: case 0xfa: case 0xfb: return "u"; case 0xfd: case 0xff: return "y"; case 0xfe: return "p"; // special characters case 0xa4: return " euro "; default: return null; } } public static serverByteBuffer convertUmlaute(serverByteBuffer bb) { serverByteBuffer t = new serverByteBuffer(bb.length() + 20); int b0, b1, b2; String z; int i = 0; while (i < bb.length()) { b0 = bb.byteAt(i) & 0xff; // check utf-8 encoding if ((b0 < 128) || (i + 1 == bb.length())) { t.append(b0); i++; } else { b1 = bb.byteAt(i + 1) & 0xff; if (b1 > 0x3f) { z = code_iso8859s(b0); i++; } else if ((b0 > 0xbf) && (b0 < 0xe0)) { z = code_iso8859s(((b0 & 0x1f) << 0x6) | (b1 & 0x3f)); i += 2; } else { if (i + 2 >= bb.length()) { z = null; i++; } else { b2 = bb.byteAt(i + 2) & 0xff; if (b2 > 0x3f) { z = code_iso8859s(b0); i++; } else { z = code_iso8859s(((b0 & 0xf) << 0xc) | ((b1 & 0x3f) << 0x6) | (b2 & 0x3f)); i += 3; } } } if (z == null) t.append(b0); else t.append(z); } } return t; } private static byte[] transscript(byte[] code) { String t; try { // TODO: use the source encoding here to get the tag name from the byte array t = (String) trans.get(new String(code, "UTF-8")); } catch (UnsupportedEncodingException e) { t = null; } if (t == null) return new byte[0]; // TODO: use the source encoding to convert the string properly to the original document encoding return t.getBytes(); } protected static serverByteBuffer transscriptAll(serverByteBuffer bb) { int p0 = 0, p1; byte[] t; while ((p0 = bb.indexOf((byte) '&', p0)) >= 0) { p1 = bb.indexOf((byte) ';', p0); if (p1 >= 0) { t = transscript(bb.getBytes(p0, p1 + 1)); bb = new serverByteBuffer(bb.getBytes(0, p0), bb.length() + p0 - p1 + t.length).append(t).append(bb.getBytes(p1 + 1)); } else { bb = new serverByteBuffer(bb.getBytes(0, p0), bb.length()).append(bb.getBytes(p0 + 1)); } } t = null; return bb; } protected static serverByteBuffer stripAllTags(serverByteBuffer bb) { // TODO: trim() does not work with other charsets int p0 = 0, p1; while ((p0 = bb.indexOf(lb, p0)) >= 0) { p1 = bb.indexOf(rb, p0); if (p1 >= 0) { bb = new serverByteBuffer(bb.getBytes(0, p0), bb.length() + p0 - p1 + 1).trim().append((byte) 32).append(new serverByteBuffer(bb.getBytes(p1 + 1)).trim()); } else { bb = new serverByteBuffer(bb.getBytes(0, p0), bb.length()).trim().append(new serverByteBuffer(bb.getBytes(p0 + 1)).trim()); } } return bb.trim(); } public static serverByteBuffer stripAll(serverByteBuffer bb) { //return stripAllTags(s); return convertUmlaute(transscriptAll(stripAllTags(bb))); } public void close() { // free resources tags0 = null; tags1 = null; } public void finalize() { close(); } }\ No newline at end of file+// htmlFilterAbstractScraper.java // --------------------------- // (C) by Michael Peter Christen; [email protected] // first published on http://www.anomic.de // Frankfurt, Germany, 2004 // last major change: 18.02.2004 // // You agree that the Author(s) is (are) not responsible for cost, // loss of data or any harm that may be caused by usage of this softare or // this documentation. The usage of this software is on your own risk. The // installation and usage (starting/running) of this software may allow other // people or application to access your computer and any attached devices and // is highly dependent on the configuration of the software which must be // done by the user of the software;the author(s) is (are) also // not responsible for proper configuration and usage of the software, even // if provoked by documentation provided together with the software. // // THE SOFTWARE THAT FOLLOWS AS ART OF PROGRAMMING BELOW THIS SECTION // IS PUBLISHED UNDER THE GPL AS DOCUMENTED IN THE FILE gpl.txt ASIDE THIS // FILE AND AS IN http://www.gnu.org/licenses/gpl.txt // ANY CHANGES TO THIS FILE ACCORDING TO THE GPL CAN BE DONE TO THE // LINES THAT FOLLOWS THIS COPYRIGHT NOTICE HERE, BUT CHANGES MUST NOT // BE DONE ABOVE OR INSIDE THE COPYRIGHT NOTICE. A RE-DISTRIBUTION // MUST CONTAIN THE INTACT AND UNCHANGED COPYRIGHT NOTICE. // CONTRIBUTIONS AND CHANGES TO THE PROGRAM CODE SHOULD BE MARKED AS SUCH. package de.anomic.htmlFilter; import java.util.HashMap; import java.util.Properties; import java.util.TreeSet; import de.anomic.server.serverCharBuffer; public abstract class htmlFilterAbstractScraper implements htmlFilterScraper { public static final char lb = '<'; public static final char rb = '>'; public static final char sl = '/'; private TreeSet tags0; private TreeSet tags1; // define a translation table for html character codings private static HashMap trans = new HashMap(300); static { trans.put(""", "\""); //Anführungszeichen oben trans.put("&", "&"); //Ampersand-Zeichen, kaufmännisches Und trans.put("<", "<"); //öffnende spitze Klammer trans.put(">", ">"); //schließende spitze Klammer trans.put(" ", " "); //Erzwungenes Leerzeichen trans.put("¡", "!"); //umgekehrtes Ausrufezeichen trans.put("¢", " cent "); //Cent-Zeichen trans.put("£", " pound "); //Pfund-Zeichen trans.put("¤", " currency "); //Währungs-Zeichen trans.put("¥", " yen "); //Yen-Zeichen trans.put("¦", " "); //durchbrochener Strich trans.put("§", " paragraph "); //Paragraph-Zeichen trans.put("¨", " "); //Pünktchen oben trans.put("©", " copyright "); //Copyright-Zeichen trans.put("ª", " "); //Ordinal-Zeichen weiblich trans.put("«", " "); //angewinkelte Anführungszeichen links trans.put("¬", " not "); //Verneinungs-Zeichen trans.put("­", "-"); //kurzer Trennstrich trans.put("®", " trademark "); //Registriermarke-Zeichen trans.put("¯", " "); //Überstrich trans.put("°", " degree "); //Grad-Zeichen trans.put("±", " +/- "); //Plusminus-Zeichen trans.put("²", " square "); //Hoch-2-Zeichen trans.put("³", " 3 "); //Hoch-3-Zeichen trans.put("´", " "); //Acute-Zeichen trans.put("µ", " micro "); //Mikro-Zeichen trans.put("¶", " paragraph "); //Absatz-Zeichen trans.put("·", " "); //Mittelpunkt trans.put("¸", " "); //Häkchen unten trans.put("¹", " "); //Hoch-1-Zeichen trans.put("º", " degree "); //Ordinal-Zeichen männlich trans.put("»", " "); //angewinkelte Anführungszeichen rechts trans.put("¼", " quarter "); //ein Viertel trans.put("½", " half "); //ein Halb trans.put("¾", " 3/4 "); //drei Viertel trans.put("¿", "?"); //umgekehrtes Fragezeichen trans.put("À", "A"); //A mit Accent grave trans.put("Á", "A"); //A mit Accent acute trans.put("Â", "A"); //A mit Circumflex trans.put("Ã", "A"); //A mit Tilde trans.put("Ä", "Ae"); //A Umlaut trans.put("Å", "A"); //A mit Ring trans.put("Æ", "A"); //A mit legiertem E trans.put("Ç", "C"); //C mit Häkchen trans.put("È", "E"); //E mit Accent grave trans.put("É", "E"); //E mit Accent acute trans.put("Ê", "E"); //E mit Circumflex trans.put("Ë", "E"); //E Umlaut trans.put("Ì", "I"); //I mit Accent grave trans.put("Í", "I"); //I mit Accent acute trans.put("Î", "I"); //I mit Circumflex trans.put("Ï", "I"); //I Umlaut trans.put("Ð", "D"); //Eth (isländisch) trans.put("Ñ", "N"); //N mit Tilde trans.put("Ò", "O"); //O mit Accent grave trans.put("Ó", "O"); //O mit Accent acute trans.put("Ô", "O"); //O mit Circumflex trans.put("Õ", "O"); //O mit Tilde trans.put("Ö", "Oe"); //O Umlaut trans.put("×", " times "); //Mal-Zeichen trans.put("Ø", "O"); //O mit Schrägstrich trans.put("Ù", "U"); //U mit Accent grave trans.put("Ú", "U"); //U mit Accent acute trans.put("Û", "U"); //U mit Circumflex trans.put("Ü", "Ue"); //U Umlaut trans.put("Ý", "Y"); //Y mit Accent acute trans.put("Þ", "P"); //THORN (isländisch) trans.put("ß", "ss"); //scharfes S trans.put("à", "a"); //a mit Accent grave trans.put("á", "a"); //a mit Accent acute trans.put("â", "a"); //a mit Circumflex trans.put("ã", "a"); //a mit Tilde trans.put("ä", "ae"); //a Umlaut trans.put("å", "a"); //a mit Ring trans.put("æ", "a"); //a mit legiertem e trans.put("ç", "c"); //c mit Häkchen trans.put("è", "e"); //e mit Accent grave trans.put("é", "e"); //e mit Accent acute trans.put("ê", "e"); //e mit Circumflex trans.put("ë", "e"); //e Umlaut trans.put("ì", "i"); //i mit Accent grave trans.put("í", "i"); //i mit Accent acute trans.put("î", "i"); //i mit Circumflex trans.put("ï", "i"); //i Umlaut trans.put("ð", "d"); //eth (isländisch) trans.put("ñ", "n"); //n mit Tilde trans.put("ò", "o"); //o mit Accent grave trans.put("ó", "o"); //o mit Accent acute trans.put("ô", "o"); //o mit Circumflex trans.put("õ", "o"); //o mit Tilde trans.put("ö", "oe"); //o Umlaut trans.put("÷", "%"); //Divisions-Zeichen trans.put("ø", "o"); //o mit Schrägstrich trans.put("ù", "u"); //u mit Accent grave trans.put("ú", "u"); //u mit Accent acute trans.put("û", "u"); //u mit Circumflex trans.put("ü", "ue"); //u Umlaut trans.put("ý", "y"); //y mit Accent acute trans.put("þ", "p"); //thorn (isländisch) trans.put("ÿ", "y"); //y Umlaut trans.put("Α", " Alpha "); //Alpha groß trans.put("α", " alpha "); //alpha klein trans.put("Β", " Beta "); //Beta groß trans.put("β", " beta "); //beta klein trans.put("Γ", " Gamma "); //Gamma groß trans.put("γ", " gamma "); //gamma klein trans.put("Δ", " Delta "); //Delta groß trans.put("δ", " delta "); //delta klein trans.put("Ε", " Epsilon "); //Epsilon groß trans.put("ε", " epsilon "); //epsilon klein trans.put("Ζ", " Zeta "); //Zeta groß trans.put("ζ", " zeta "); //zeta klein trans.put("Η", " Eta "); //Eta groß trans.put("η", " eta "); //eta klein trans.put("Θ", " Theta "); //Theta groß trans.put("θ", " theta "); //theta klein trans.put("Ι", " Iota "); //Iota groß trans.put("ι", " iota "); //iota klein trans.put("Κ", " Kappa "); //Kappa groß trans.put("κ", " kappa "); //kappa klein trans.put("Λ", " Lambda "); //Lambda groß trans.put("λ", " lambda "); //lambda klein trans.put("Μ", " Mu "); //Mu groß trans.put("μ", " mu "); //mu klein trans.put("Ν", " Nu "); //Nu groß trans.put("ν", " nu "); //nu klein trans.put("Ξ", " Xi "); //Xi groß trans.put("ξ", " xi "); //xi klein trans.put("Ο", " Omicron "); //Omicron groß trans.put("ο", " omicron "); //omicron klein trans.put("Π", " Pi "); //Pi groß trans.put("π", " pi "); //pi klein trans.put("Ρ", " Rho "); //Rho groß trans.put("ρ", " rho "); //rho klein trans.put("Σ", " Sigma "); //Sigma groß trans.put("ς", " sigma "); //sigmaf klein trans.put("σ", " sigma "); //sigma klein trans.put("Τ", " Tau "); //Tau groß trans.put("τ", " tau "); //tau klein trans.put("Υ", " Ypsilon "); //Upsilon groß trans.put("υ", " ypsilon "); //upsilon klein trans.put("Φ", " Phi "); //Phi groß trans.put("φ", " phi "); //phi klein trans.put("Χ", " Chi "); //Chi groß trans.put("χ", " chi "); //chi klein trans.put("Ψ", " Psi "); //Psi groß trans.put("ψ", " psi "); //psi klein trans.put("Ω", " Omega "); //Omega groß trans.put("ω", " omega "); //omega klein trans.put("ϑ", " theta "); //theta Symbol trans.put("ϒ", " ypsilon "); //upsilon mit Haken trans.put("ϖ", " pi "); //pi Symbol trans.put("∀", " for all "); //für alle trans.put("∂", " part of "); //teilweise trans.put("∃", " exists "); //existiert trans.put("∅", " null "); //leer trans.put("∇", " nabla "); //nabla trans.put("∈", " element of "); //Element von trans.put("∉", " not element of "); //kein Element von trans.put("∋", " contains "); //enthält als Element trans.put("∏", " product "); //Produkt trans.put("∑", " sum "); //Summe trans.put("−", " minus "); //minus trans.put("∗", " times "); //Asterisk trans.put("√", " sqare root "); //Quadratwurzel trans.put("∝", " proportional to "); //proportional zu trans.put("∞", " unlimited "); //unendlich trans.put("∠", " angle "); //Winkel trans.put("∧", " and "); //und trans.put("∨", " or "); //oder trans.put("∩", " "); //Schnittpunkt trans.put("∪", " unity "); //Einheit trans.put("∫", " integral "); //Integral trans.put("∴", " cause "); //deshalb trans.put("∼", " similar to "); //ähnlich wie trans.put("≅", " equal "); //annähernd gleich trans.put("≈", " equal "); //beinahe gleich trans.put("≠", " not equal "); //ungleich trans.put("≡", " identical "); //identisch mit trans.put("≤", " smaller or equal than "); //kleiner gleich trans.put("≥", " greater or equal than "); //größer gleich trans.put("⊂", " subset of "); //Untermenge von trans.put("⊃", " superset of "); //Obermenge von trans.put("⊄", " not subset of "); //keine Untermenge von trans.put("⊆", ""); //Untermenge von oder gleich mit trans.put("⊇", ""); //Obermenge von oder gleich mit trans.put("⊕", ""); //Direktsumme trans.put("⊗", ""); //Vektorprodukt trans.put("⊥", ""); //senkrecht zu trans.put("⋅", ""); //Punkt-Operator trans.put("◊", ""); //Raute trans.put("⌈", ""); //links oben trans.put("⌉", ""); //rechts oben trans.put("⌊", ""); //links unten trans.put("⌋", ""); //rechts unten trans.put("⟨", ""); //spitze Klammer links trans.put("⟩", ""); //spitze Klammer rechts trans.put("←", ""); //Pfeil links trans.put("↑", ""); //Pfeil oben trans.put("→", ""); //Pfeil rechts trans.put("↓", ""); //Pfeil unten trans.put("↔", ""); //Pfeil links/rechts trans.put("↵", ""); //Pfeil unten-Knick-links trans.put("⇐", ""); //Doppelpfeil links trans.put("⇑", ""); //Doppelpfeil oben trans.put("⇒", ""); //Doppelpfeil rechts trans.put("⇓", ""); //Doppelpfeil unten trans.put("⇔", ""); //Doppelpfeil links/rechts trans.put("•", ""); //Bullet-Zeichen trans.put("…", ""); //Horizontale Ellipse trans.put("′", ""); //Minutenzeichen trans.put("‾", ""); //Überstrich trans.put("⁄", ""); //Bruchstrich trans.put("℘", ""); //Weierstrass p trans.put("ℑ", ""); //Zeichen für "imaginär" trans.put("ℜ", ""); //Zeichen für "real" trans.put("™", ""); //Trademark-Zeichen trans.put("€", ""); //Euro-Zeichen trans.put("ℵ", ""); //Alef-Symbol trans.put("♠", ""); //Pik-Zeichen trans.put("♣", ""); //Kreuz-Zeichen trans.put("♥", ""); //Herz-Zeichen trans.put("♦", ""); //Karo-Zeichen trans.put(" ", ""); //Leerzeichen Breite n trans.put(" ", ""); //Leerzeichen Breite m trans.put(" ", ""); //Schmales Leerzeichen trans.put("‌", ""); //null breiter Nichtverbinder trans.put("‍", ""); //null breiter Verbinder trans.put("‎", ""); //links-nach-rechts-Zeichen trans.put("‏", ""); //rechts-nach-links-Zeichen trans.put("–", ""); //Gedankenstrich Breite n trans.put("—", ""); //Gedankenstrich Breite m trans.put("‘", ""); //einfaches Anführungszeichen links trans.put("’", ""); //einfaches Anführungszeichen rechts trans.put("‚", ""); //einfaches low-9-Zeichen trans.put("“", ""); //doppeltes Anführungszeichen links trans.put("”", ""); //doppeltes Anführungszeichen rechts trans.put("„", ""); //doppeltes low-9-Zeichen rechts trans.put("†", ""); //Kreuz trans.put("‡", ""); //Doppelkreuz trans.put("‰", ""); //zu tausend trans.put("‹", ""); //angewinkeltes einzelnes Anf.zeichen links trans.put("›", ""); //angewinkeltes einzelnes Anf.zeichen rechts } public htmlFilterAbstractScraper(TreeSet tags0, TreeSet tags1) { this.tags0 = tags0; this.tags1 = tags1; } public boolean isTag0(String tag) { return (tags0 != null) && (tags0.contains(tag)); } public boolean isTag1(String tag) { return (tags1 != null) && (tags1.contains(tag)); } //the 'missing' method that shall be implemented: public abstract void scrapeText(char[] text); // the other methods must take into account to construct the return value correctly public abstract void scrapeTag0(String tagname, Properties tagopts); public abstract void scrapeTag1(String tagname, Properties tagopts, char[] text); // string conversions private static String code_iso8859s(char c) { switch (c) { // german umlaute and ligaturen case 0xc4: return "AE"; case 0xd6: return "OE"; case 0xdc: return "UE"; case 0xe4: return "ae"; case 0xf6: return "oe"; case 0xfc: return "ue"; case 0xdf: return "ss"; // accent on letters; i.e. french characters case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc5: return "A"; case 0xc6: return "AE"; case 0xc7: return "C"; case 0xc8: case 0xc9: case 0xca: return "E"; case 0xcc: case 0xcd: case 0xce: case 0xcf: return "I"; case 0xd0: return "D"; case 0xd1: return "N"; case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd8: return "O"; case 0xd7: return "x"; case 0xd9: case 0xda: case 0xdb: return "U"; case 0xdd: return "Y"; case 0xde: return "p"; case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe5: return "a"; case 0xe6: return "ae"; case 0xe7: return "c"; case 0xe8: case 0xe9: case 0xea: return "e"; case 0xec: case 0xed: case 0xee: case 0xef: return "i"; case 0xf0: return "d"; case 0xf1: return "n"; case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf8: return "o"; case 0xf7: return "%"; case 0xf9: case 0xfa: case 0xfb: return "u"; case 0xfd: case 0xff: return "y"; case 0xfe: return "p"; // special characters case 0xa4: return " euro "; default: return null; } } public static serverCharBuffer convertUmlaute(serverCharBuffer bb) { if (bb.length() == 0) return bb; serverCharBuffer t = new serverCharBuffer(bb.length() + 20); char c; for (int i = 0; i < bb.length(); i++) { c = bb.charAt(i); String z = code_iso8859s(c); if (z == null) t.append(c); else t.append(z); } return t; // serverByteBuffer t = new serverByteBuffer(bb.length() + 20); // int b0, b1, b2; // String z; // int i = 0; // while (i < bb.length()) { // b0 = bb.byteAt(i) & 0xff; // // check utf-8 encoding // if ((b0 < 128) || (i + 1 == bb.length())) { // t.append(b0); // i++; // } else { // b1 = bb.byteAt(i + 1) & 0xff; // if (b1 > 0x3f) { // z = code_iso8859s(b0); // i++; // } else if ((b0 > 0xbf) && (b0 < 0xe0)) { // z = code_iso8859s(((b0 & 0x1f) << 0x6) | (b1 & 0x3f)); // i += 2; // } else { // if (i + 2 >= bb.length()) { // z = null; // i++; // } else { // b2 = bb.byteAt(i + 2) & 0xff; // if (b2 > 0x3f) { // z = code_iso8859s(b0); // i++; // } else { // z = code_iso8859s(((b0 & 0xf) << 0xc) | ((b1 & 0x3f) << 0x6) | (b2 & 0x3f)); // i += 3; // } // } // } // if (z == null) t.append(b0); else t.append(z); // } // } // return t; } private static char[] transscript(char[] code) { String t = (String) trans.get(new String(code)); if (t == null) return new char[0]; return t.toCharArray(); } protected static serverCharBuffer transscriptAll(serverCharBuffer bb) { int p0 = 0, p1; char[] t; while ((p0 = bb.indexOf('&', p0)) >= 0) { p1 = bb.indexOf(';', p0); if (p1 >= 0) { t = transscript(bb.getChars(p0, p1 + 1)); bb = new serverCharBuffer(bb.getChars(0, p0), bb.length() + p0 - p1 + t.length).append(t).append(bb.getChars(p1 + 1)); } else { bb = new serverCharBuffer(bb.getChars(0, p0), bb.length()).append(bb.getChars(p0 + 1)); } } t = null; return bb; } protected static serverCharBuffer stripAllTags(serverCharBuffer bb) { int p0 = 0, p1; while ((p0 = bb.indexOf(lb, p0)) >= 0) { p1 = bb.indexOf(rb, p0); if (p1 >= 0) { bb = ((serverCharBuffer)new serverCharBuffer(bb.getChars(0, p0), bb.length() + p0 - p1 + 1).trim().append(32)).append(new serverCharBuffer(bb.getChars(p1 + 1)).trim()); } else { bb = new serverCharBuffer(bb.getChars(0, p0), bb.length()).trim().append(new serverCharBuffer(bb.getChars(p0 + 1)).trim()); } } return bb.trim(); } public static serverCharBuffer stripAll(serverCharBuffer bb) { //return stripAllTags(s); return convertUmlaute(transscriptAll(stripAllTags(bb))); } public void close() { // free resources tags0 = null; tags1 = null; } public void finalize() { close(); } }\ No newline at end of filediff --git a/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.java b/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.javaindex fa8bcdc91..fcb4cb5f5 100644--- a/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.java+++ b/source/de/anomic/htmlFilter/htmlFilterAbstractTransformer.java@@ -62,7 +62,7 @@ public abstract class htmlFilterAbstractTransformer implements htmlFilterTransfo}//the 'missing' method that shall be implemented:- public abstract byte[] transformText(byte[] text);+ public abstract char[] transformText(char[] text);/* could be easily implemented as:{return text;@@ -70,12 +70,12 @@ public abstract class htmlFilterAbstractTransformer implements htmlFilterTransfo*/// the other methods must take into account to construct the return value correctly- public byte[] transformTag0(String tagname, Properties tagopts, byte quotechar) {- return htmlFilterOutputStream.genTag0(tagname, tagopts, quotechar);+ public char[] transformTag0(String tagname, Properties tagopts, char quotechar) {+ return htmlFilterWriter.genTag0(tagname, tagopts, quotechar);}- public byte[] transformTag1(String tagname, Properties tagopts, byte[] text, byte quotechar) {- return htmlFilterOutputStream.genTag1(tagname, tagopts, text, quotechar);+ public char[] transformTag1(String tagname, Properties tagopts, char[] text, char quotechar) {+ return htmlFilterWriter.genTag1(tagname, tagopts, text, quotechar);}public void close() {diff --git a/source/de/anomic/htmlFilter/htmlFilterContentScraper.java b/source/de/anomic/htmlFilter/htmlFilterContentScraper.javaindex 3ffd42eb1..b41d97ca6 100644--- a/source/de/anomic/htmlFilter/htmlFilterContentScraper.java+++ b/source/de/anomic/htmlFilter/htmlFilterContentScraper.java@@ -43,9 +43,6 @@package de.anomic.htmlFilter;-import de.anomic.server.serverByteBuffer;-import de.anomic.net.URL;-import java.io.UnsupportedEncodingException;import java.net.MalformedURLException;import java.nio.charset.Charset;@@ -59,6 +56,9 @@ import java.util.Map;import java.util.Properties;import java.util.TreeSet;+import de.anomic.net.URL;+import de.anomic.server.serverCharBuffer;+public class htmlFilterContentScraper extends htmlFilterAbstractScraper implements htmlFilterScraper {// statics: for initialisation of the HTMLFilterAbstractScraper@@ -95,10 +95,9 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenprivate String title;//private String headline;private List[] headlines;- private serverByteBuffer content;+ private serverCharBuffer content;private URL root;- private String charset = "UTF-8";public htmlFilterContentScraper(URL root) {// the root value here will not be used to load the resource.@@ -111,27 +110,13 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implementhis.title = "";this.headlines = new ArrayList[4];for (int i = 0; i < 4; i++) headlines[i] = new ArrayList();- this.content = new serverByteBuffer(1024);- }-- public void setCharset(String charset) throws UnsupportedCharsetException {- if (charset == null) return;-- // testing if charset exists- Charset.forName(charset);-- // remember it- this.charset = charset;- }-- public String getCharset() {- return this.charset;+ this.content = new serverCharBuffer(1024);}- public void scrapeText(byte[] newtext) {+ public void scrapeText(char[] newtext) {// System.out.println("SCRAPE: " + new String(newtext));- if ((content.length() != 0) && (content.byteAt(content.length() - 1) != 32)) content.append(32);- content.append(super.stripAll(new serverByteBuffer(newtext, newtext.length + 1)).trim()).append(32);+ if ((content.length() != 0) && (content.charAt(content.length() - 1) != 32)) content.append(32);+ content.append(super.stripAll(new serverCharBuffer(newtext, newtext.length + 1)).trim()).append(32);}public static final String splitrex = " |/|\\(|\\)|-|\\:|_|\\.|,|\\?|!|'|" + '"';@@ -188,31 +173,31 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemen}}- public void scrapeTag1(String tagname, Properties tagopts, byte[] text) {+ public void scrapeTag1(String tagname, Properties tagopts, char[] text) {// System.out.println("ScrapeTag1: tagname=" + tagname + ", opts=" + tagopts.toString() + ", text=" + new String(text));if ((tagname.equalsIgnoreCase("a")) && (text.length < 2048)) {String href = tagopts.getProperty("href", "");- if (href.length() > 0) anchors.put(absolutePath(href), super.stripAll(new serverByteBuffer(text)).trim().toString(this.charset));+ if (href.length() > 0) anchors.put(absolutePath(href), super.stripAll(new serverCharBuffer(text)).trim().toString());}String h;if ((tagname.equalsIgnoreCase("h1")) && (text.length < 1024)) {- h = cleanLine(super.stripAll(new serverByteBuffer(text)).toString(this.charset));+ h = cleanLine(super.stripAll(new serverCharBuffer(text)).toString());if (h.length() > 0) headlines[0].add(h);}if ((tagname.equalsIgnoreCase("h2")) && (text.length < 1024)) {- h = cleanLine(super.stripAll(new serverByteBuffer(text)).toString(this.charset));+ h = cleanLine(super.stripAll(new serverCharBuffer(text)).toString());if (h.length() > 0) headlines[1].add(h);}if ((tagname.equalsIgnoreCase("h3")) && (text.length < 1024)) {- h = cleanLine(super.stripAll(new serverByteBuffer(text)).toString(this.charset));+ h = cleanLine(super.stripAll(new serverCharBuffer(text)).toString());if (h.length() > 0) headlines[2].add(h);}if ((tagname.equalsIgnoreCase("h4")) && (text.length < 1024)) {- h = cleanLine(super.stripAll(new serverByteBuffer(text)).toString(this.charset));+ h = cleanLine(super.stripAll(new serverCharBuffer(text)).toString());if (h.length() > 0) headlines[3].add(h);}if ((tagname.equalsIgnoreCase("title")) && (text.length < 1024))- title = cleanLine(super.stripAll(new serverByteBuffer(text)).toString(this.charset));+ title = cleanLine(super.stripAll(new serverCharBuffer(text)).toString());}private static String cleanLine(String s) {@@ -250,13 +235,9 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemen// extract headline from contentif (content.length() > 80) {- try {- return cleanLine(new String(content.getBytes(), 0, 80,this.charset));- } catch (UnsupportedEncodingException e) {- return cleanLine(new String(content.getBytes(), 0, 80));- }+ return cleanLine(new String(content.getChars(), 0, 80));}- return cleanLine(content.trim().toString(this.charset));+ return cleanLine(content.trim().toString());}public String[] getHeadlines(int i) {@@ -267,7 +248,11 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemen}public byte[] getText() {- return content.getBytes();+ try {+ return content.toString().getBytes("UTF-8");+ } catch (UnsupportedEncodingException e) {+ return content.toString().getBytes();+ }}public Map getAnchors() {@@ -359,7 +344,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemenSystem.out.println("ANCHORS :" + anchors.toString());System.out.println("IMAGES :" + images.toString());System.out.println("METAS :" + metas.toString());- System.out.println("TEXT :" + new String(content.getBytes()));+ System.out.println("TEXT :" + content.toString());}diff --git a/source/de/anomic/htmlFilter/htmlFilterContentTransformer.java b/source/de/anomic/htmlFilter/htmlFilterContentTransformer.javaindex 838ad8e16..d39a0b9fc 100644--- a/source/de/anomic/htmlFilter/htmlFilterContentTransformer.java+++ b/source/de/anomic/htmlFilter/htmlFilterContentTransformer.java@@ -46,7 +46,6 @@ package de.anomic.htmlFilter;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;-import java.io.UnsupportedEncodingException;import java.text.Collator;import java.util.ArrayList;import java.util.Locale;@@ -55,6 +54,7 @@ import java.util.TreeSet;import de.anomic.http.httpTemplate;import de.anomic.server.serverByteBuffer;+import de.anomic.server.serverCharBuffer;public class htmlFilterContentTransformer extends htmlFilterAbstractTransformer implements htmlFilterTransformer {@@ -111,25 +111,20 @@ public class htmlFilterContentTransformer extends htmlFilterAbstractTransformerreturn (bluelist.size() == 0) && (!gettext);}- private static byte[] genBlueLetters(int length) {- serverByteBuffer bb = new serverByteBuffer(" <FONT COLOR=#0000FF>".getBytes());+ private static char[] genBlueLetters(int length) {+ serverCharBuffer bb = new serverCharBuffer(" <FONT COLOR=#0000FF>".toCharArray());length = length / 2;if (length > 10) length = 7;while (length-- > 0) {- bb.append((byte) 'X');+ bb.append('X');}- bb.append("</FONT> ".getBytes());- return bb.getBytes();+ bb.append("</FONT> ");+ return bb.getChars();}- private boolean bluelistHit(byte[] text) {+ private boolean bluelistHit(char[] text) {if (text == null || bluelist == null) return false;- String lc;- try {- lc = new String(text, "UTF-8").toLowerCase();- } catch (UnsupportedEncodingException e) {- lc = new String(text).toLowerCase();- }+ String lc = new String(text).toLowerCase();for (int i = 0; i < bluelist.size(); i++) {if (lc.indexOf((String) bluelist.get(i)) >= 0) return true;}@@ -158,65 +153,64 @@ public class htmlFilterContentTransformer extends htmlFilterAbstractTransformer}return result;}- public byte[] transformText(byte[] text) {+ public char[] transformText(char[] text) {if (gettext) {- serverByteBuffer sbb = new serverByteBuffer(text);- //if (sbb.length() > 0) System.out.println(" TEXT: " + sbb.toString());- serverByteBuffer[] sbbs = httpTemplate.splitQuotations(sbb);- sbb = new serverByteBuffer();- for (int i = 0; i < sbbs.length; i++) {- if (sbbs[i].isWhitespace(true)) {- sbb.append(sbbs[i]);- } else if ((sbbs[i].byteAt(0) == httpTemplate.hash) ||- (sbbs[i].startsWith(httpTemplate.dpdpa))) {- // this is a template or a part of a template- sbb.append(sbbs[i]);- } else {- // this is a text fragment, generate gettext quotation- int ws = sbbs[i].whitespaceStart(true);- int we = sbbs[i].whitespaceEnd(true);- sbb.append(sbbs[i].getBytes(0, ws));- sbb.append('_');- sbb.append('(');- sbb.append(sbbs[i].getBytes(ws, we));- sbb.append(')');- sbb.append(sbbs[i].getBytes(we));- }- }- //if (sbb.length() > 0) System.out.println("GETTEXT: " + sbb.toString());- return sbb.getBytes();+// serverCharBuffer sbb = new serverCharBuffer(text);+// //if (sbb.length() > 0) System.out.println(" TEXT: " + sbb.toString());+// serverCharBuffer[] sbbs = httpTemplate.splitQuotations(sbb);+// sbb = new serverCharBuffer();+// for (int i = 0; i < sbbs.length; i++) {+// if (sbbs[i].isWhitespace(true)) {+// sbb.append(sbbs[i]);+// } else if ((sbbs[i].byteAt(0) == httpTemplate.hash) ||+// (sbbs[i].startsWith(httpTemplate.dpdpa))) {+// // this is a template or a part of a template+// sbb.append(sbbs[i]);+// } else {+// // this is a text fragment, generate gettext quotation+// int ws = sbbs[i].whitespaceStart(true);+// int we = sbbs[i].whitespaceEnd(true);+// sbb.append(sbbs[i].getBytes(0, ws));+// sbb.append('_');+// sbb.append('(');+// sbb.append(sbbs[i].getBytes(ws, we));+// sbb.append(')');+// sbb.append(sbbs[i].getBytes(we));+// }+// }+// //if (sbb.length() > 0) System.out.println("GETTEXT: " + sbb.toString());+// return sbb.getChars();}if (bluelist != null) {if (bluelistHit(text)) {// System.out.println("FILTERHIT: " + text);return genBlueLetters(text.length);- } else {- return text;}+ return text;}return text;}- public byte[] transformTag0(String tagname, Properties tagopts, byte quotechar) {+ public char[] transformTag0(String tagname, Properties tagopts, char quotechar) {if (tagname.equals("img")) {// check bluelist- if (bluelistHit(tagopts.getProperty("src","").getBytes())) return genBlueLetters(5);- if (bluelistHit(tagopts.getProperty("alt","").getBytes())) return genBlueLetters(5);+ if (bluelistHit(tagopts.getProperty("src","").toCharArray())) return genBlueLetters(5);+ if (bluelistHit(tagopts.getProperty("alt","").toCharArray())) return genBlueLetters(5);// replace image alternative name- tagopts.setProperty("alt", new String(transformText(tagopts.getProperty("alt","").getBytes())));+ tagopts.setProperty("alt", new String(transformText(tagopts.getProperty("alt","").toCharArray())));}if ((tagname.equals("input")) && (tagopts.getProperty("type").equals("submit"))) {// rewrite button name- tagopts.setProperty("value", new String(transformText(tagopts.getProperty("value","").getBytes())));+ tagopts.setProperty("value", new String(transformText(tagopts.getProperty("value","").toCharArray())));}- return htmlFilterOutputStream.genTag0(tagname, tagopts, quotechar);+ return htmlFilterWriter.genTag0(tagname, tagopts, quotechar);}- public byte[] transformTag1(String tagname, Properties tagopts, byte[] text, byte quotechar) {- if (bluelistHit(tagopts.getProperty("href","").getBytes())) return genBlueLetters(text.length);+ public char[] transformTag1(String tagname, Properties tagopts, char[] text, char quotechar) {+ if (bluelistHit(tagopts.getProperty("href","").toCharArray())) return genBlueLetters(text.length);if (bluelistHit(text)) return genBlueLetters(text.length);- return htmlFilterOutputStream.genTag1(tagname, tagopts, text, quotechar);+ return htmlFilterWriter.genTag1(tagname, tagopts, text, quotechar);}public void close() {diff --git a/source/de/anomic/htmlFilter/htmlFilterScraper.java b/source/de/anomic/htmlFilter/htmlFilterScraper.javaindex a4f494591..ad054233d 100644--- a/source/de/anomic/htmlFilter/htmlFilterScraper.java+++ b/source/de/anomic/htmlFilter/htmlFilterScraper.java@@ -40,7 +40,6 @@package de.anomic.htmlFilter;-import java.nio.charset.UnsupportedCharsetException;import java.util.Properties;public interface htmlFilterScraper {@@ -49,22 +48,11 @@ public interface htmlFilterScraper {public boolean isTag1(String tag);- public void scrapeText(byte[] text);+ public void scrapeText(char[] text);public void scrapeTag0(String tagname, Properties tagopts);- public void scrapeTag1(String tagname, Properties tagopts, byte[] text);+ public void scrapeTag1(String tagname, Properties tagopts, char[] text);public void close();-- /**- * @param charset the charset of the source document- * @throws UnsupportedCharsetException- */- public void setCharset(String charset) throws UnsupportedCharsetException;-- /**- * @return charset the charset of the source document- */- public String getCharset();}diff --git a/source/de/anomic/htmlFilter/htmlFilterTransformer.java b/source/de/anomic/htmlFilter/htmlFilterTransformer.javaindex a255c255f..e28e8fd2d 100644--- a/source/de/anomic/htmlFilter/htmlFilterTransformer.java+++ b/source/de/anomic/htmlFilter/htmlFilterTransformer.java@@ -65,13 +65,13 @@ public interface htmlFilterTransformer {// method that is called with any text between tags// the returned text replaces the given text// if the text shall not be changed, it must be returned as called- public byte[] transformText(byte[] text);+ public char[] transformText(char[] text);// method that is called when a body-less tag occurs- public byte[] transformTag0(String tagname, Properties tagopts, byte quotechar);+ public char[] transformTag0(String tagname, Properties tagopts, char quotechar);// method that is called when a body-containing text occurs- public byte[] transformTag1(String tagname, Properties tagopts, byte[] text, byte quotechar);+ public char[] transformTag1(String tagname, Properties tagopts, char[] text, char quotechar);public void close();}diff --git a/source/de/anomic/htmlFilter/htmlFilterOutputStream.java b/source/de/anomic/htmlFilter/htmlFilterWriter.javasimilarity index 62%rename from source/de/anomic/htmlFilter/htmlFilterOutputStream.javarename to source/de/anomic/htmlFilter/htmlFilterWriter.javaindex bf168739a..a232be49a 100644--- a/source/de/anomic/htmlFilter/htmlFilterOutputStream.java+++ b/source/de/anomic/htmlFilter/htmlFilterWriter.java@@ -4,9 +4,9 @@// first published on http://www.anomic.de// Frankfurt, Germany, 2004, 2005//-// $LastChangedDate$-// $LastChangedRevision$-// $LastChangedBy$+// $LastChangedDate: 2006-09-15 17:01:25 +0200 (Fr, 15 Sep 2006) $+// $LastChangedRevision: 2598 $+// $LastChangedBy: theli $//// 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@@ -50,34 +50,37 @@package de.anomic.htmlFilter;-import de.anomic.net.URL;-import java.io.File;-import java.io.FileInputStream;import java.io.FileOutputStream;+import java.io.FileReader;import java.io.IOException;-import java.io.InputStream;import java.io.OutputStream;+import java.io.OutputStreamWriter;+import java.io.Reader;import java.io.UnsupportedEncodingException;+import java.io.Writer;import java.net.MalformedURLException;import java.util.Enumeration;import java.util.Properties;-import de.anomic.server.serverByteBuffer;-public final class htmlFilterOutputStream extends OutputStream {+import de.anomic.net.URL;+import de.anomic.server.serverCharBuffer;++public final class htmlFilterWriter extends Writer {- public static final byte lb = (byte) '<';- public static final byte rb = (byte) '>';- public static final byte dash = (byte) '-';- public static final byte excl = (byte) '!';- public static final byte singlequote = (byte) 39;- public static final byte doublequote = (byte) 34;+ public static final char lb = '<';+ public static final char rb = '>';+ public static final char dash = '-';+ public static final char excl = '!';+ public static final char singlequote = '\'';+ public static final char doublequote = '"';- private OutputStream out;- private serverByteBuffer buffer;+ private OutputStream outStream;+ private OutputStreamWriter out;+ private serverCharBuffer buffer;private String filterTag;private Properties filterOpts;- private serverByteBuffer filterCont;+ private serverCharBuffer filterCont;private htmlFilterScraper scraper;private htmlFilterTransformer transformer;private boolean inSingleQuote;@@ -87,13 +90,17 @@ public final class htmlFilterOutputStream extends OutputStream {private boolean binaryUnsuspect;private boolean passbyIfBinarySuspect;- public htmlFilterOutputStream(OutputStream out, htmlFilterScraper scraper,- htmlFilterTransformer transformer,- boolean passbyIfBinarySuspect) {- this.out = out;+ public htmlFilterWriter(+ OutputStream outStream,+ String outputStreamCharset,+ htmlFilterScraper scraper,+ htmlFilterTransformer transformer,+ boolean passbyIfBinarySuspect+ ) throws UnsupportedEncodingException {+ this.outStream = outStream;this.scraper = scraper;this.transformer = transformer;- this.buffer = new serverByteBuffer(1024);+ this.buffer = new serverCharBuffer(1024);this.filterTag = null;this.filterOpts = null;this.filterCont = null;@@ -103,74 +110,77 @@ public final class htmlFilterOutputStream extends OutputStream {this.inScript = false;this.binaryUnsuspect = true;this.passbyIfBinarySuspect = passbyIfBinarySuspect;++ if (this.outStream != null) {+ this.out = new OutputStreamWriter(this.outStream,(outputStreamCharset == null)?"UTF-8":outputStreamCharset);+ }}- public static byte[] genTag0raw(String tagname, boolean opening, byte[] tagopts) {- serverByteBuffer bb = new serverByteBuffer(tagname.length() + tagopts.length + 3);- bb.append((byte) '<');+ public static char[] genTag0raw(String tagname, boolean opening, char[] tagopts) {+ serverCharBuffer bb = new serverCharBuffer(tagname.length() + tagopts.length + 3);+ bb.append('<');if (!opening) {- bb.append((byte) '/');+ bb.append('/');}- bb.append(tagname.getBytes());+ bb.append(tagname);if (tagopts.length > 0) {// if (tagopts[0] == (byte) 32)bb.append(tagopts);// else bb.append((byte) 32).append(tagopts);}- bb.append((byte) '>');- return bb.getBytes();+ bb.append('>');+ return bb.getChars();}- public static byte[] genTag1raw(String tagname, byte[] tagopts, byte[] text) {- serverByteBuffer bb = new serverByteBuffer(2 * tagname.length() + tagopts.length + text.length + 5);- bb.append((byte) '<').append(tagname.getBytes());+ public static char[] genTag1raw(String tagname, char[] tagopts, char[] text) {+ serverCharBuffer bb = new serverCharBuffer(2 * tagname.length() + tagopts.length + text.length + 5);+ bb.append('<').append(tagname);if (tagopts.length > 0) {// if (tagopts[0] == (byte) 32)bb.append(tagopts);// else bb.append((byte) 32).append(tagopts);}- bb.append((byte) '>');+ bb.append('>');bb.append(text);- bb.append((byte) '<').append((byte) '/').append(tagname.getBytes()).append((byte) '>');- return bb.getBytes();+ bb.append('<').append('/').append(tagname).append('>');+ return bb.getChars();}- public static byte[] genTag0(String tagname, Properties tagopts, byte quotechar) {- byte[] tagoptsx = (tagopts.size() == 0) ? null : genOpts(tagopts, quotechar);- serverByteBuffer bb = new serverByteBuffer(tagname.length() + ((tagoptsx == null) ? 0 : (tagoptsx.length + 1)) + tagname.length() + 2).append((byte) '<').append(tagname.getBytes());+ public static char[] genTag0(String tagname, Properties tagopts, char quotechar) {+ char[] tagoptsx = (tagopts.size() == 0) ? null : genOpts(tagopts, quotechar);+ serverCharBuffer bb = new serverCharBuffer(tagname.length() + ((tagoptsx == null) ? 0 : (tagoptsx.length + 1)) + tagname.length() + 2);+ bb.append('<').append(tagname);if (tagoptsx != null) {- bb = bb.append((byte) 32).append(tagoptsx);+ bb.append(32);+ bb.append(tagoptsx);}- bb = bb.append((byte) '>');- return bb.getBytes();+ bb.append('>');+ return bb.getChars();}- public static byte[] genTag1(String tagname, Properties tagopts, byte[] text, byte quotechar) {- byte[] gt0 = genTag0(tagname, tagopts, quotechar);- return new serverByteBuffer(gt0, gt0.length + text.length + tagname.length() + 3).append(text).append(("</" + tagname + ">").getBytes()).getBytes();+ public static char[] genTag1(String tagname, Properties tagopts, char[] text, char quotechar) {+ char[] gt0 = genTag0(tagname, tagopts, quotechar);+ serverCharBuffer cb = new serverCharBuffer(gt0, gt0.length + text.length + tagname.length() + 3);+ cb.append(text).append('<').append('/').append(tagname).append('>');+ return cb.getChars();}// a helper method for pretty-printing of properties for html tags- public static byte[] genOpts(Properties prop, byte quotechar) {+ public static char[] genOpts(Properties prop, char quotechar) {Enumeration e = prop.propertyNames();- serverByteBuffer bb = new serverByteBuffer(prop.size() * 40);+ serverCharBuffer bb = new serverCharBuffer(prop.size() * 40);String key;while (e.hasMoreElements()) {key = (String) e.nextElement();- bb = bb.append((byte) 32).append(key.getBytes()).append((byte) '=');- bb = bb.append(quotechar);- try {- bb.append(prop.getProperty(key).getBytes("UTF-8"));- } catch (UnsupportedEncodingException e1) {- bb.append(prop.getProperty(key).getBytes());- }+ bb.append(32).append(key).append('=').append(quotechar);+ bb.append(prop.getProperty(key));bb.append(quotechar);}- if (bb.length() > 0) return bb.getBytes(1);- return bb.getBytes();+ if (bb.length() > 0) return bb.getChars(1);+ return bb.getChars();}- private byte[] filterTag(String tag, boolean opening, byte[] content, byte quotechar) {+ private char[] filterTag(String tag, boolean opening, char[] content, char quotechar) {// System.out.println("FILTER1: filterTag=" + ((filterTag == null) ? "null" : filterTag) + ", tag=" + tag + ", opening=" + ((opening) ? "true" : "false") + ", content=" + new String(content)); // debugif (filterTag == null) {// we are not collection tag text@@ -185,18 +195,18 @@ public final class htmlFilterOutputStream extends OutputStream {if (opening) {if ((scraper != null) && (scraper.isTag0(tag))) {// this single tag is collected at once here- scraper.scrapeTag0(tag, new serverByteBuffer(content).propParser(scraper.getCharset()));+ scraper.scrapeTag0(tag, new serverCharBuffer(content).propParser());}if ((transformer != null) && (transformer.isTag0(tag))) {// this single tag is collected at once here- return transformer.transformTag0(tag, new serverByteBuffer(content).propParser(scraper.getCharset()), quotechar);+ return transformer.transformTag0(tag, new serverCharBuffer(content).propParser(), quotechar);} else if (((scraper != null) && (scraper.isTag1(tag))) ||((transformer != null) && (transformer.isTag1(tag)))) {// ok, start collectingfilterTag = tag;- filterOpts = new serverByteBuffer(content).propParser(scraper.getCharset());- filterCont = new serverByteBuffer();- return new byte[0];+ filterOpts = new serverCharBuffer(content).propParser();+ filterCont = new serverCharBuffer();+ return new char[0];} else {// we ignore that thing and return it againreturn genTag0raw(tag, true, content);@@ -217,23 +227,23 @@ public final class htmlFilterOutputStream extends OutputStream {} else {filterCont.append(content);}- return new byte[0];+ return new char[0];}// it's a tag! which one?if ((opening) || (!(tag.equals(filterTag)))) {// this tag is not our concern. just add itfilterCont.append(genTag0raw(tag, opening, content));- return new byte[0];+ return new char[0];}// it's our closing tag! return complete result.- byte[] ret;- if (scraper != null) scraper.scrapeTag1(filterTag, filterOpts, filterCont.getBytes());+ char[] ret;+ if (scraper != null) scraper.scrapeTag1(filterTag, filterOpts, filterCont.getChars());if (transformer != null) {- ret = transformer.transformTag1(filterTag, filterOpts, filterCont.getBytes(), quotechar);+ ret = transformer.transformTag1(filterTag, filterOpts, filterCont.getChars(), quotechar);} else {- ret = genTag1(filterTag, filterOpts, filterCont.getBytes(), quotechar);+ ret = genTag1(filterTag, filterOpts, filterCont.getChars(), quotechar);}filterTag = null;filterOpts = null;@@ -241,18 +251,18 @@ public final class htmlFilterOutputStream extends OutputStream {return ret;}- private byte[] filterFinalize(byte quotechar) {+ private char[] filterFinalize(char quotechar) {if (filterTag == null) {- return new byte[0];+ return new char[0];}// it's our closing tag! return complete result.- byte[] ret;- if (scraper != null) scraper.scrapeTag1(filterTag, filterOpts, filterCont.getBytes());+ char[] ret;+ if (scraper != null) scraper.scrapeTag1(filterTag, filterOpts, filterCont.getChars());if (transformer != null) {- ret = transformer.transformTag1(filterTag, filterOpts, filterCont.getBytes(), quotechar);+ ret = transformer.transformTag1(filterTag, filterOpts, filterCont.getChars(), quotechar);} else {- ret = genTag1(filterTag, filterOpts, filterCont.getBytes(), quotechar);+ ret = genTag1(filterTag, filterOpts, filterCont.getChars(), quotechar);}filterTag = null;filterOpts = null;@@ -260,7 +270,7 @@ public final class htmlFilterOutputStream extends OutputStream {return ret;}- private byte[] filterSentence(byte[] in, byte quotechar) {+ private char[] filterSentence(char[] in, char quotechar) {if (in.length == 0) return in;// System.out.println("FILTER0: " + new String(in)); // debug// scan the string and parse structure@@ -272,16 +282,16 @@ public final class htmlFilterOutputStream extends OutputStream {if (in[1] == '/') {// a closing tagtagend = tagEnd(in, 2);- tag = new String(in, 2, tagend - 2); // TODO: bugfix needed for other charsets- byte[] text = new byte[in.length - tagend - 1];+ tag = new String(in, 2, tagend - 2);+ char[] text = new char[in.length - tagend - 1];System.arraycopy(in, tagend, text, 0, in.length - tagend - 1);return filterTag(tag, false, text, quotechar);}// an opening tagtagend = tagEnd(in, 1);- tag = new String(in, 1, tagend - 1); // TODO: bugfix needed for other charsets- byte[] text = new byte[in.length - tagend - 1];+ tag = new String(in, 1, tagend - 1);+ char[] text = new char[in.length - tagend - 1];System.arraycopy(in, tagend, text, 0, in.length - tagend - 1);return filterTag(tag, true, text, quotechar);}@@ -290,10 +300,10 @@ public final class htmlFilterOutputStream extends OutputStream {return filterTag(null, true, in, quotechar);}- private static int tagEnd(byte[] tag, int start) {+ private static int tagEnd(char[] tag, int start) {char c;for (int i = start; i < tag.length; i++) {- c = (char) tag[i];+ c = tag[i];if (c != '!' && c != '-' &&(c < '0' || c > '9') &&(c < 'a' || c > 'z') &&@@ -303,145 +313,141 @@ public final class htmlFilterOutputStream extends OutputStream {return tag.length - 1;}- public void write(int b) throws IOException {- write((byte) (b & 0xff));- }-- private void write(byte b) throws IOException {+ public void write(int c) throws IOException {// System.out.println((char) b);- if ((binaryUnsuspect) && (binaryHint(b))) {+ if ((binaryUnsuspect) && (binaryHint((char)c))) {binaryUnsuspect = false;if (passbyIfBinarySuspect) finalize();}if (binaryUnsuspect || !passbyIfBinarySuspect) {- byte[] filtered;+ char[] filtered;if (inSingleQuote) {- buffer.append(b);- if (b == singlequote) inSingleQuote = false;+ buffer.append(c);+ if (c == singlequote) inSingleQuote = false;// check error cases- if ((b == rb) && (buffer.byteAt(0) == lb)) {+ if ((c == rb) && (buffer.charAt(0) == lb)) {inSingleQuote = false;// the tag ends here. after filtering: pass on- filtered = filterSentence(buffer.getBytes(), singlequote);+ filtered = filterSentence(buffer.getChars(), singlequote);if (out != null) { out.write(filtered); }// buffer = new serverByteBuffer();buffer.reset();}} else if (inDoubleQuote) {- buffer.append(b);- if (b == doublequote) inDoubleQuote = false;+ buffer.append(c);+ if (c == doublequote) inDoubleQuote = false;// check error cases- if (b == rb && buffer.byteAt(0) == lb) {+ if (c == rb && buffer.charAt(0) == lb) {inDoubleQuote = false;// the tag ends here. after filtering: pass on- filtered = filterSentence(buffer.getBytes(), doublequote);+ filtered = filterSentence(buffer.getChars(), doublequote);if (out != null) out.write(filtered);// buffer = new serverByteBuffer();buffer.reset();}} else if (inComment) {- buffer.append(b);- if (b == rb &&+ buffer.append(c);+ if (c == rb &&buffer.length() > 6 &&- buffer.byteAt(buffer.length() - 3) == dash) {+ buffer.charAt(buffer.length() - 3) == dash) {// comment is at endinComment = false;- if (out != null) out.write(buffer.getBytes());+ if (out != null) out.write(buffer.getChars());// buffer = new serverByteBuffer();buffer.reset();}} else if (inScript) {- buffer.append(b);+ buffer.append(c);int bufferLength = buffer.length();- if ((b == rb) && (bufferLength > 14) &&- (buffer.byteAt(bufferLength - 8) == (byte) '/') &&- (buffer.byteAt(bufferLength - 7) == (byte) 's') &&- (buffer.byteAt(bufferLength - 6) == (byte) 'c') &&- (buffer.byteAt(bufferLength - 5) == (byte) 'r') &&- (buffer.byteAt(bufferLength - 4) == (byte) 'i') &&- (buffer.byteAt(bufferLength - 3) == (byte) 'p') &&- (buffer.byteAt(bufferLength - 2) == (byte) 't')) {+ if ((c == rb) && (bufferLength > 14) &&+ (buffer.charAt(bufferLength - 8) == '/') &&+ (buffer.charAt(bufferLength - 7) == 's') &&+ (buffer.charAt(bufferLength - 6) == 'c') &&+ (buffer.charAt(bufferLength - 5) == 'r') &&+ (buffer.charAt(bufferLength - 4) == 'i') &&+ (buffer.charAt(bufferLength - 3) == 'p') &&+ (buffer.charAt(bufferLength - 2) == 't')) {// script is at endinScript = false;- if (out != null) out.write(buffer.getBytes());+ if (out != null) out.write(buffer.getChars());// buffer = new serverByteBuffer();buffer.reset();}} else {if (buffer.length() == 0) {- if (b == rb) {+ if (c == rb) {// very strange error case; we just let it pass- if (out != null) out.write(b);+ if (out != null) out.write(c);} else {- buffer.append(b);+ buffer.append(c);}- } else if (buffer.byteAt(0) == lb) {- if (b == singlequote) inSingleQuote = true;- if (b == doublequote) inDoubleQuote = true;+ } else if (buffer.charAt(0) == lb) {+ if (c == singlequote) inSingleQuote = true;+ if (c == doublequote) inDoubleQuote = true;// fill in tag text- if ((buffer.length() == 3) && (buffer.byteAt(1) == excl) &&- (buffer.byteAt(2) == dash) && (b == dash)) {+ if ((buffer.length() == 3) && (buffer.charAt(1) == excl) &&+ (buffer.charAt(2) == dash) && (c == dash)) {// this is the start of a commentinComment = true;- buffer.append(b);+ buffer.append(c);} else if ((buffer.length() == 6) &&- (buffer.byteAt(1) == (byte) 's') &&- (buffer.byteAt(2) == (byte) 'c') &&- (buffer.byteAt(3) == (byte) 'r') &&- (buffer.byteAt(4) == (byte) 'i') &&- (buffer.byteAt(5) == (byte) 'p') &&- (b == (byte) 't')) {+ (buffer.charAt(1) == 's') &&+ (buffer.charAt(2) == 'c') &&+ (buffer.charAt(3) == 'r') &&+ (buffer.charAt(4) == 'i') &&+ (buffer.charAt(5) == 'p') &&+ (c == 't')) {// this is the start of a commentinScript = true;- buffer.append(b);- } else if (b == rb) {- buffer.append(b);+ buffer.append(c);+ } else if (c == rb) {+ buffer.append(c);// the tag ends here. after filtering: pass on- filtered = filterSentence(buffer.getBytes(), doublequote);+ filtered = filterSentence(buffer.getChars(), doublequote);if (out != null) out.write(filtered);// buffer = new serverByteBuffer();buffer.reset();- } else if (b == lb) {+ } else if (c == lb) {// this is an error case// we consider that there is one rb missingif (buffer.length() > 0) {- filtered = filterSentence(buffer.getBytes(), doublequote);+ filtered = filterSentence(buffer.getChars(), doublequote);if (out != null) out.write(filtered);}// buffer = new serverByteBuffer();buffer.reset();- buffer.append(b);+ buffer.append(c);} else {- buffer.append(b);+ buffer.append(c);}} else {// fill in plain text- if (b == lb) {+ if (c == lb) {// the text ends hereif (buffer.length() > 0) {- filtered = filterSentence(buffer.getBytes(), doublequote);+ filtered = filterSentence(buffer.getChars(), doublequote);if (out != null) out.write(filtered);}// buffer = new serverByteBuffer();buffer.reset();- buffer.append(b);+ buffer.append(c);} else {// simply append- buffer.append(b);+ buffer.append(c);}}}} else {- out.write(b);+ out.write(c);}}- public void write(byte b[]) throws IOException {- this.write(b, 0, b.length);+ public void write(char b[]) throws IOException {+ write(b, 0, b.length);}- public void write(byte b[], int off, int len) throws IOException {+ public void write(char b[], int off, int len) throws IOException {// System.out.println(new String(b, off, len));if ((off | len | (b.length - (len + off)) | (off + len)) < 0) throw new IndexOutOfBoundsException();for (int i = off ; i < (len - off) ; i++) this.write(b[i]);@@ -462,15 +468,15 @@ public final class htmlFilterOutputStream extends OutputStream {}public void close() throws IOException {- byte quotechar = (inSingleQuote) ? singlequote : doublequote;+ char quotechar = (inSingleQuote) ? singlequote : doublequote;if (buffer != null) {if (buffer.length() > 0) {- byte[] filtered = filterSentence(buffer.getBytes(), quotechar);+ char[] filtered = filterSentence(buffer.getChars(), quotechar);if (out != null) out.write(filtered);}buffer = null;}- byte[] finalized = filterFinalize(quotechar);+ char[] finalized = filterFinalize(quotechar);if (out != null) {if (finalized != null) out.write(finalized);out.flush();@@ -483,10 +489,11 @@ public final class htmlFilterOutputStream extends OutputStream {// if (transformer != null) {transformer.close(); transformer = null;}}- private static boolean binaryHint(byte b) {- if (b < 0) return false;- if (b > 31) return false;- if ((b == 8) || (b == 9) || (b == 10) || (b == 13)) return false;+ private static boolean binaryHint(char c) {+// return Character.isDefined(c);+ if (c < 0) return false;+ if (c > 31) return false;+ if ((c == 8) || (c == 9) || (c == 10) || (c == 13)) return false;// return false;// System.out.println("BINARY HINT: " + (int) b);return true;@@ -499,14 +506,16 @@ public final class htmlFilterOutputStream extends OutputStream {public static void main(String[] args) {// takes one argument: a file nameif (args.length != 1) return;- byte[] buffer = new byte[512];+ char[] buffer = new char[512];try {htmlFilterContentScraper scraper = new htmlFilterContentScraper(new URL("http://localhost:8080"));- htmlFilterTransformer transformer = new htmlFilterContentTransformer();+ htmlFilterTransformer transformer = new htmlFilterContentTransformer();+ // TODO: this does not work at the moment+ System.exit(0);transformer.init("gettext");- InputStream is = new FileInputStream(args[0]);+ Reader is = new FileReader(args[0]);FileOutputStream fos = new FileOutputStream(new File(args[0] + ".out"));- OutputStream os = new htmlFilterOutputStream(fos, scraper, transformer, false);+ Writer os = new htmlFilterWriter(fos, "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/http/httpc.java b/source/de/anomic/http/httpc.javaindex acd86f72a..e9c7a4bbe 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -48,6 +48,7 @@ import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PushbackInputStream;+import java.io.Writer;import java.lang.Math;import java.net.InetAddress;import java.net.InetSocketAddress;@@ -86,6 +87,7 @@ import de.anomic.kelondro.kelondroMScoreCluster;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverByteBuffer;import de.anomic.server.serverCore;+import de.anomic.server.serverFileUtils;import de.anomic.server.serverObjects;import de.anomic.server.logging.serverLog;@@ -1586,65 +1588,65 @@ do upload}}- /**- * This method outputs the input stream to either an output socket or an- * file or both. If the length of the input stream is given in the- * header, exactly that lenght is written. Otherwise the stream is- * written, till it is closed. If this instance is zipped, stream the- * input stream through gzip to unzip it on the fly.- *- * @param procOS OutputStream where the stream is to be written. If null- * no write happens.- * @param bufferOS OutputStream where the stream is to be written too.- * If null no write happens.- * @param clientInput InputStream where the content is to be read from.- * @throws IOException- */- public static void writeContentX(InputStream clientInput, boolean usegzip, long length, OutputStream procOS, OutputStream bufferOS) throws IOException {- // we write length bytes, but if length == -1 (or < 0) then we- // write until the input stream closes- // procOS == null -> no write to procOS- // file == null -> no write to file- // If the Content-Encoding is gzip, we gunzip on-the-fly- // and change the Content-Encoding and Content-Length attributes in the header- byte[] buffer = new byte[2048];- int l;- long len = 0;-- // using the proper intput stream- InputStream dis = (usegzip) ? (InputStream) new GZIPInputStream(clientInput) : (InputStream) clientInput;-- // we have three methods of reading: length-based, length-based gzip and connection-close-based- try {- if (length > 0) {- // we read exactly 'length' bytes- while ((len < length) && ((l = dis.read(buffer)) >= 0)) {- if (procOS != null) procOS.write(buffer, 0, l);- if (bufferOS != null) bufferOS.write(buffer, 0, l);- len += l;- }- } else {- // no content-length was given, thus we read until the connection closes- while ((l = dis.read(buffer, 0, buffer.length)) >= 0) {- if (procOS != null) procOS.write(buffer, 0, l);- if (bufferOS != null) bufferOS.write(buffer, 0, l);- }- }- } catch (java.net.SocketException e) {- throw new IOException("Socket exception: " + e.getMessage());- } catch (java.net.SocketTimeoutException e) {- throw new IOException("Socket time-out: " + e.getMessage());- } finally {- // close the streams- if (procOS != null) {- if (procOS instanceof httpChunkedOutputStream)- ((httpChunkedOutputStream)procOS).finish();- procOS.flush();- }- if (bufferOS != null) bufferOS.flush();- buffer = null;- }- }+// /**+// * This method outputs the input stream to either an output socket or an+// * file or both. If the length of the input stream is given in the+// * header, exactly that lenght is written. Otherwise the stream is+// * written, till it is closed. If this instance is zipped, stream the+// * input stream through gzip to unzip it on the fly.+// *+// * @param procOS OutputStream where the stream is to be written. If null+// * no write happens.+// * @param bufferOS OutputStream where the stream is to be written too.+// * If null no write happens.+// * @param clientInput InputStream where the content is to be read from.+// * @throws IOException+// */+// private static void writeContentX(InputStream clientInput, boolean usegzip, long length, OutputStream procOS, OutputStream bufferOS) throws IOException {+// // we write length bytes, but if length == -1 (or < 0) then we+// // write until the input stream closes+// // procOS == null -> no write to procOS+// // file == null -> no write to file+// // If the Content-Encoding is gzip, we gunzip on-the-fly+// // and change the Content-Encoding and Content-Length attributes in the header+// byte[] buffer = new byte[2048];+// int l;+// long len = 0;+//+// // using the proper intput stream+// InputStream dis = (usegzip) ? (InputStream) new GZIPInputStream(clientInput) : (InputStream) clientInput;+//+// // we have three methods of reading: length-based, length-based gzip and connection-close-based+// try {+// if (length > 0) {+// // we read exactly 'length' bytes+// while ((len < length) && ((l = dis.read(buffer)) >= 0)) {+// if (procOS != null) procOS.write(buffer, 0, l);+// if (bufferOS != null) bufferOS.write(buffer, 0, l);+// len += l;+// }+// } else {+// // no content-length was given, thus we read until the connection closes+// while ((l = dis.read(buffer, 0, buffer.length)) >= 0) {+// if (procOS != null) procOS.write(buffer, 0, l);+// if (bufferOS != null) bufferOS.write(buffer, 0, l);+// }+// }+// } catch (java.net.SocketException e) {+// throw new IOException("Socket exception: " + e.getMessage());+// } catch (java.net.SocketTimeoutException e) {+// throw new IOException("Socket time-out: " + e.getMessage());+// } finally {+// // close the streams+// if (procOS != null) {+// if (procOS instanceof httpChunkedOutputStream)+// ((httpChunkedOutputStream)procOS).finish();+// procOS.flush();+// }+// if (bufferOS != null) bufferOS.flush();+// buffer = null;+// }+// }/**@@ -1799,18 +1801,40 @@ do uploadreturn ((this.status.charAt(0) == '2') || (this.status.charAt(0) == '3'));}+ /**+ * Returns a {@link InputStream} to read the response body. If the response was encoded using <code>Content-Encoding: gzip</code>+ * a {@link GZIPInputStream} is returned. If the <code>Content-Length</code> header was set,+ * a {@link httpContentLengthInputStream} is returned which returns <code>-1</code> if the end of the+ * response body was reached.+ *+ * @return+ * @throws IOException+ */+ public InputStream getContentInputStream() throws IOException {+ if (this.gzip) {+ // use a gzip input stream for Content-Encoding: gzip+ return new GZIPInputStream(httpc.this.clientInput);+ } else if (this.responseHeader.contentLength() != -1) {+ // use a httpContentLengthInputStream to read until the end of the response body is reached+ return new httpContentLengthInputStream(httpc.this.clientInput,this.responseHeader.contentLength());+ }+ // no Content-Lenght was set. In this case we can read until EOF+ return httpc.this.clientInput;+ }+/*** This method just output the found content into an byte-array and* returns it.*- * @return+ * @return* @throws IOException*/public byte[] writeContent() throws IOException {- int contentLength = (int) this.responseHeader.contentLength();- serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength);- writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), null, sbb);- return sbb.getBytes();+// int contentLength = (int) this.responseHeader.contentLength();+// serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength);+// writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), null, sbb);+// return sbb.getBytes();+ return serverFileUtils.read(this.getContentInputStream());}/**@@ -1821,12 +1845,23 @@ do upload* @return* @throws IOException*/- public byte[] writeContent(OutputStream procOS) throws IOException {+ public byte[] writeContent(Object procOS) throws IOException {int contentLength = (int) this.responseHeader.contentLength();serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength);- writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, sbb);++ if (procOS instanceof OutputStream) {+ //writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, sbb);+ serverFileUtils.writeX(this.getContentInputStream(), (OutputStream)procOS, sbb);+ } else if (procOS instanceof Writer) {+ String charSet = this.responseHeader.getCharacterEncoding();+ if (charSet == null) charSet = "UTF-8";+ serverFileUtils.writeX(this.getContentInputStream(), charSet, (Writer)procOS, sbb, charSet);+ } else {+ throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");+ }+return sbb.getBytes();- }+ }/*** This method writes the input stream to either another output stream@@ -1836,13 +1871,22 @@ do upload* @param file* @throws IOException*/- public void writeContent(OutputStream procOS, File file) throws IOException {+ public void writeContent(Object procOS, File file) throws IOException {// this writes the input stream to either another output stream or// a file or both.FileOutputStream bufferOS = null;try {if (file != null) bufferOS = new FileOutputStream(file);- writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, bufferOS);+ if (procOS instanceof OutputStream) {+ serverFileUtils.writeX(this.getContentInputStream(), (OutputStream) procOS, bufferOS);+ //writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, bufferOS);+ } else if (procOS instanceof Writer) {+ String charSet = this.responseHeader.getCharacterEncoding();+ if (charSet == null) charSet = "UTF-8";+ serverFileUtils.writeX(this.getContentInputStream(), charSet, (Writer)procOS, bufferOS, charSet);+ } else {+ throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");+ }} finally {if (bufferOS != null) {bufferOS.close();diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex 4de724b49..3c7bcc3ed 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -70,6 +70,7 @@ import java.io.InputStreamReader;import java.io.OutputStream;import java.io.PrintWriter;import java.io.PushbackInputStream;+import java.io.Writer;import java.net.BindException;import java.net.ConnectException;import java.net.InetAddress;@@ -77,7 +78,6 @@ import java.net.MalformedURLException;import java.net.NoRouteToHostException;import java.net.Socket;import java.net.SocketTimeoutException;-import de.anomic.net.URL;import java.net.UnknownHostException;import java.util.Arrays;import java.util.Date;@@ -89,9 +89,11 @@ import java.util.logging.Level;import java.util.logging.LogManager;import java.util.logging.Logger;import java.util.zip.GZIPOutputStream;+import de.anomic.htmlFilter.htmlFilterContentTransformer;-import de.anomic.htmlFilter.htmlFilterOutputStream;import de.anomic.htmlFilter.htmlFilterTransformer;+import de.anomic.htmlFilter.htmlFilterWriter;+import de.anomic.net.URL;import de.anomic.plasma.plasmaHTCache;import de.anomic.plasma.plasmaParser;import de.anomic.plasma.plasmaSwitchboard;@@ -225,7 +227,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// remoteProxyNoProxyPatterns = remoteProxyNoProxy.split(",");// set timeout- timeout = Integer.parseInt(switchboard.getConfig("clientTimeout", "10000"));+ timeout = Integer.parseInt(switchboard.getConfig("proxy.clientTimeout", "10000"));// create a htRootPath: system pagesif (htRootPath == null) {@@ -502,7 +504,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httGZIPOutputStream gzippedOut = null;httpChunkedOutputStream chunkedOut = null;- OutputStream hfos = null;+ Object hfos = null;httpc remote = null;httpc.response res = null;@@ -562,7 +564,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httres.status.startsWith("304")) {res.responseHeader.put(httpHeader.CONTENT_LENGTH,"0");} else {- if (httpVer.equals("HTTP/0.9") || httpVer.equals("HTTP/1.0")) {+ if (httpVer.equals(httpHeader.HTTP_VERSION_0_9) || httpVer.equals(httpHeader.HTTP_VERSION_1_0)) {conProp.setProperty(httpHeader.CONNECTION_PROP_PERSISTENT,"close");} else {chunkedOut = new httpChunkedOutputStream(respond);@@ -609,7 +611,10 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt) {// make a transformerthis.theLogger.logFine("create transformer for URL " + url);- hfos = new htmlFilterOutputStream((gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond), null, transformer, (ext.length() == 0));+ //hfos = new htmlFilterOutputStream((gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond), null, transformer, (ext.length() == 0));+ String charSet = res.responseHeader.getCharacterEncoding();+ if (charSet == null) charSet = "UTF-8";+ hfos = new htmlFilterWriter((gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond),charSet, null, transformer, (ext.length() == 0));} else {// simply pass through without parsingthis.theLogger.logFine("create passthrough for URL " + url + ", extension '" + ext + "', mime-type '" + res.responseHeader.mime() + "'");@@ -660,7 +665,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httbyte[] cacheArray = res.writeContent(hfos);this.theLogger.logFine("writeContent of " + url + " produced cacheArray = " + ((cacheArray == null) ? "null" : ("size=" + cacheArray.length)));- if (hfos instanceof htmlFilterOutputStream) ((htmlFilterOutputStream) hfos).finalize();+ if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();if (sizeBeforeDelete == -1) {// totally fresh file@@ -686,7 +691,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// write to file right here.cacheFile.getParentFile().mkdirs();res.writeContent(hfos, cacheFile);- if (hfos instanceof htmlFilterOutputStream) ((htmlFilterOutputStream) hfos).finalize();+ if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();this.theLogger.logFine("for write-file of " + url + ": contentLength = " + contentLength + ", sizeBeforeDelete = " + sizeBeforeDelete);cacheManager.writeFileAnnouncement(cacheFile);if (sizeBeforeDelete == -1) {@@ -716,7 +721,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt" SupportetContent=" + isSupportedContent);res.writeContent(hfos, null);- if (hfos instanceof htmlFilterOutputStream) ((htmlFilterOutputStream) hfos).finalize();+ if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();if (sizeBeforeDelete == -1) {// no old file and no load. just data passing//cacheEntry.status = plasmaHTCache.CACHE_PASSING;@@ -760,7 +765,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htthttpChunkedOutputStream chunkedOut = null;GZIPOutputStream gzippedOut = null;- OutputStream hfos = null;+ Object hfos = null;// we respond on the request by using the cache, the cache is freshtry {@@ -809,20 +814,28 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htthttpd.sendRespondHeader(conProp,respond,httpVer,203,cachedResponseHeader);//respondHeader(respond, "203 OK", cachedResponseHeader); // respond with 'non-authoritative'+ // determine the content charset+ String charSet = cachedResponseHeader.getCharacterEncoding();+ if (charSet == null) charSet = "UTF-8";+// make a transformerif ((!(transformer.isIdentityTransformer())) &&((ext == null) || (!(plasmaParser.supportedRealtimeFileExtContains(url)))) &&((cachedResponseHeader == null) || (plasmaParser.realtimeParsableMimeTypesContains(cachedResponseHeader.mime())))) {- hfos = new htmlFilterOutputStream((chunkedOut != null) ? chunkedOut : respond, null, transformer, (ext.length() == 0));+ hfos = new htmlFilterWriter((chunkedOut != null) ? chunkedOut : respond, charSet, null, transformer, (ext.length() == 0));} else {hfos = (gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond);}// send also the complete body now from the cache// simply read the file and transfer to out socket- serverFileUtils.copy(cacheFile,hfos);+ if (hfos instanceof OutputStream) {+ serverFileUtils.copy(cacheFile,(OutputStream)hfos);+ } else if (hfos instanceof Writer) {+ serverFileUtils.copy(cacheFile,charSet,(Writer)hfos);+ }- if (hfos instanceof htmlFilterOutputStream) ((htmlFilterOutputStream) hfos).finalize();+ if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();if (gzippedOut != null) gzippedOut.finish();if (chunkedOut != null) chunkedOut.finish();}diff --git a/source/de/anomic/plasma/cache/IResourceInfo.java b/source/de/anomic/plasma/cache/IResourceInfo.javaindex 81cfc2491..efa22767c 100644--- a/source/de/anomic/plasma/cache/IResourceInfo.java+++ b/source/de/anomic/plasma/cache/IResourceInfo.java@@ -86,7 +86,7 @@ public interface IResourceInfo {* Returns the charset of the resource* @return returns the name of the charset or <code>null</code> if unknown*/- public String getCharSet();+ public String getCharacterEncoding();/*** Returns the modification date of the cached objectdiff --git a/source/de/anomic/plasma/cache/ftp/ResourceInfo.java b/source/de/anomic/plasma/cache/ftp/ResourceInfo.javaindex dfbc32ccd..89b86b357 100644--- a/source/de/anomic/plasma/cache/ftp/ResourceInfo.java+++ b/source/de/anomic/plasma/cache/ftp/ResourceInfo.java@@ -161,7 +161,7 @@ public class ResourceInfo implements IResourceInfo {return responseStatus != null && responseStatus.equalsIgnoreCase("OK");}- public String getCharSet() {+ public String getCharacterEncoding() {return null;}diff --git a/source/de/anomic/plasma/cache/http/ResourceInfo.java b/source/de/anomic/plasma/cache/http/ResourceInfo.javaindex ec3768fd1..aeb52d3ab 100644--- a/source/de/anomic/plasma/cache/http/ResourceInfo.java+++ b/source/de/anomic/plasma/cache/http/ResourceInfo.java@@ -111,13 +111,9 @@ public class ResourceInfo implements IResourceInfo {return ((pos < 0) ? mimeType : mimeType.substring(0, pos));}- public String getCharSet() {+ public String getCharacterEncoding() {if (this.responseHeader == null) return null;-- String mimeType = this.responseHeader.mime();-- int pos = mimeType.indexOf(';');- return ((pos < 0) ? null : mimeType.substring(pos));+ return this.responseHeader.getCharacterEncoding();}/**diff --git a/source/de/anomic/plasma/parser/rss/rssParser.java b/source/de/anomic/plasma/parser/rss/rssParser.javaindex 05209cc75..299e3f865 100644--- a/source/de/anomic/plasma/parser/rss/rssParser.java+++ b/source/de/anomic/plasma/parser/rss/rssParser.java@@ -45,8 +45,7 @@ package de.anomic.plasma.parser.rss;import java.io.ByteArrayInputStream;import java.io.InputStream;-import java.io.OutputStream;-import de.anomic.net.URL;+import java.io.Writer;import java.util.Collection;import java.util.HashMap;import java.util.Hashtable;@@ -58,12 +57,14 @@ import java.util.TreeSet;import de.anomic.htmlFilter.htmlFilterAbstractScraper;import de.anomic.htmlFilter.htmlFilterContentScraper;import de.anomic.htmlFilter.htmlFilterImageEntry;-import de.anomic.htmlFilter.htmlFilterOutputStream;+import de.anomic.htmlFilter.htmlFilterWriter;+import de.anomic.net.URL;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.serverByteBuffer;+import de.anomic.server.serverCharBuffer;import de.anomic.server.serverFileUtils;import de.nava.informa.core.ChannelIF;import de.nava.informa.core.ImageIF;@@ -148,14 +149,14 @@ public class rssParser extends AbstractParser implements Parser {anchors.put(itemURL.toString(),itemTitle);if ((text.length() != 0) && (text.byteAt(text.length() - 1) != 32)) text.append((byte) 32);- text.append(new serverByteBuffer(htmlFilterAbstractScraper.stripAll(new serverByteBuffer(itemDescr.getBytes("UTF-8")))).trim()).append((byte) ' '); // TODO: this does not work for utf-8+ text.append(new serverCharBuffer(htmlFilterAbstractScraper.stripAll(new serverCharBuffer(itemDescr.toCharArray()))).trim()).append(' '); // TODO: this does not work for utf-8String itemContent = item.getElementValue("content");if ((itemContent != null) && (itemContent.length() > 0)) {htmlFilterContentScraper scraper = new htmlFilterContentScraper(itemURL);- OutputStream os = new htmlFilterOutputStream(null, scraper, null, false);- serverFileUtils.copy(new ByteArrayInputStream(itemContent.getBytes("UTF-8")), os);+ Writer writer = new htmlFilterWriter(null, null, scraper, null, false);+ serverFileUtils.copy(new ByteArrayInputStream(itemContent.getBytes("UTF-8")), writer, "UTF-8");String itemHeadline = scraper.getTitle();if ((itemHeadline != null) && (itemHeadline.length() > 0)) {diff --git a/source/de/anomic/plasma/plasmaCondenser.java b/source/de/anomic/plasma/plasmaCondenser.javaindex 2da1d87cf..6ca5bfc63 100644--- a/source/de/anomic/plasma/plasmaCondenser.java+++ b/source/de/anomic/plasma/plasmaCondenser.java@@ -47,7 +47,6 @@ package de.anomic.plasma;import java.io.BufferedReader;import java.io.ByteArrayInputStream;import java.io.File;-import java.io.FileInputStream;import java.io.FileWriter;import java.io.IOException;import java.io.InputStream;@@ -60,8 +59,6 @@ import java.util.Map;import java.util.TreeMap;import java.util.TreeSet;-import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterOutputStream;import de.anomic.kelondro.kelondroMSetTools;public final class plasmaCondenser {@@ -682,47 +679,47 @@ public final class plasmaCondenser {}public static void main(String[] args) {- if ((args.length == 0) || (args.length > 3))- System.out.println("wrong number of arguments: plasmaCondenser -text|-html <infile> <outfile>");- else- try {- plasmaCondenser pc = null;-- // read and analyse file- File file = new File(args[1]);- InputStream textStream = null;- if (args[0].equals("-text")) {- // read a text file- textStream = new FileInputStream(file);- } else if (args[0].equals("-html")) {- // read a html file- htmlFilterContentScraper cs = new htmlFilterContentScraper(new de.anomic.net.URL("http://localhost/"));- htmlFilterOutputStream fos = new htmlFilterOutputStream(null, cs, null, false);- FileInputStream fis = new FileInputStream(file);- byte[] buffer = new byte[512];- int i;- while ((i = fis.read(buffer)) > 0) fos.write(buffer, 0, i);- fis.close();- fos.close();- // cs.print();- // System.out.println("TEXT:" + new String(cs.getText()));- textStream = new ByteArrayInputStream(cs.getText());- } else {- System.out.println("first argument must be either '-text' or '-html'");- System.exit(-1);- }-- // call condenser- pc = new plasmaCondenser(textStream, 1, 0);- textStream.close();-- // output result- pc.writeMapToFile(new File(args[2]));- pc.print();- //System.out.println("ANALYSIS:" + pc.getAnalysis().toString());- } catch (IOException e) {- System.out.println("Problem with input file: " + e.getMessage());- }+// if ((args.length == 0) || (args.length > 3))+// System.out.println("wrong number of arguments: plasmaCondenser -text|-html <infile> <outfile>");+// else+// try {+// plasmaCondenser pc = null;+//+// // read and analyse file+// File file = new File(args[1]);+// InputStream textStream = null;+// if (args[0].equals("-text")) {+// // read a text file+// textStream = new FileInputStream(file);+// } else if (args[0].equals("-html")) {+// // read a html file+// htmlFilterContentScraper cs = new htmlFilterContentScraper(new de.anomic.net.URL("http://localhost/"));+// htmlFilterOutputStream fos = new htmlFilterOutputStream(null, cs, null, false);+// FileInputStream fis = new FileInputStream(file);+// byte[] buffer = new byte[512];+// int i;+// while ((i = fis.read(buffer)) > 0) fos.write(buffer, 0, i);+// fis.close();+// fos.close();+// // cs.print();+// // System.out.println("TEXT:" + new String(cs.getText()));+// textStream = new ByteArrayInputStream(cs.getText());+// } else {+// System.out.println("first argument must be either '-text' or '-html'");+// System.exit(-1);+// }+//+// // call condenser+// pc = new plasmaCondenser(textStream, 1, 0);+// textStream.close();+//+// // output result+// pc.writeMapToFile(new File(args[2]));+// pc.print();+// //System.out.println("ANALYSIS:" + pc.getAnalysis().toString());+// } catch (IOException e) {+// System.out.println("Problem with input file: " + e.getMessage());+// }}}diff --git a/source/de/anomic/plasma/plasmaParser.java b/source/de/anomic/plasma/plasmaParser.javaindex a92c7222d..02c360b38 100644--- a/source/de/anomic/plasma/plasmaParser.java+++ b/source/de/anomic/plasma/plasmaParser.java@@ -50,7 +50,7 @@ import java.io.FileFilter;import java.io.FileInputStream;import java.io.FilenameFilter;import java.io.IOException;-import java.io.OutputStream;+import java.io.Writer;import java.net.MalformedURLException;import java.net.URI;@@ -66,19 +66,20 @@ import java.util.Map;import java.util.Properties;import java.util.Set;+import org.apache.commons.pool.KeyedPoolableObjectFactory;+import org.apache.commons.pool.impl.GenericKeyedObjectPool;+import org.apache.commons.pool.impl.GenericObjectPool;+import de.anomic.htmlFilter.htmlFilterContentScraper;-import de.anomic.htmlFilter.htmlFilterOutputStream;+import de.anomic.htmlFilter.htmlFilterWriter;import de.anomic.http.httpc;+import de.anomic.net.URL;import de.anomic.plasma.parser.Parser;import de.anomic.plasma.parser.ParserException;import de.anomic.plasma.parser.ParserInfo;import de.anomic.server.serverFileUtils;import de.anomic.server.logging.serverLog;-import org.apache.commons.pool.impl.GenericKeyedObjectPool;-import org.apache.commons.pool.KeyedPoolableObjectFactory;-import org.apache.commons.pool.impl.GenericObjectPool;-public final class plasmaParser {public static final String PARSER_MODE_PROXY = "PROXY";public static final String PARSER_MODE_CRAWLER = "CRAWLER";@@ -482,13 +483,21 @@ public final class plasmaParser {}- public plasmaParserDocument parseSource(URL location, String mimeType, String charset, File sourceFile) throws InterruptedException {+ public plasmaParserDocument parseSource(URL location, String mimeType, String documentCharset, File sourceFile) throws InterruptedException {Parser theParser = null;try {+ // getting the mimetype of the documentmimeType = getRealMimeType(mimeType);++ // getting the file extension of the documentString fileExt = getFileExt(location);+ // getting the charset of the document+ if (documentCharset == null)+ // TODO: do a charset detection here ....+ documentCharset = "ISO-8859-1";+if (this.theLogger.isFine())this.theLogger.logFine("Parsing " + location + " with mimeType '" + mimeType +"' and file extension '" + fileExt + "'.");@@ -547,7 +556,7 @@ public final class plasmaParser {// if a parser was found we use it ...if (theParser != null) {- return theParser.parse(location, mimeType,charset,sourceFile);+ return theParser.parse(location, mimeType,documentCharset,sourceFile);} else if (realtimeParsableMimeTypesContains(mimeType)) {// ...otherwise we make a scraper and transformerhtmlFilterContentScraper scraper = new htmlFilterContentScraper(location);@@ -561,11 +570,17 @@ public final class plasmaParser {return null;}}*/-- OutputStream hfos = new htmlFilterOutputStream(null, scraper, null, false);- serverFileUtils.copy(sourceFile, hfos);- hfos.close();- return transformScraper(location, mimeType, scraper);+ htmlFilterWriter writer = new htmlFilterWriter(null,null,scraper,null,false);+ serverFileUtils.copy(sourceFile, documentCharset, writer);+ writer.close();+ //OutputStream hfos = new htmlFilterOutputStream(null, scraper, null, false);+ //serverFileUtils.copy(sourceFile, hfos);+ //hfos.close();+ if (writer.binarySuspect()) {+ this.theLogger.logInfo("Binary data found in URL " + location);+ return null;+ }+ return transformScraper(location, mimeType, documentCharset, scraper);} else {serverLog.logWarning("PARSER", "parseSource2: wrong mime type");return null;@@ -581,13 +596,13 @@ public final class plasmaParser {}}- public plasmaParserDocument transformScraper(URL location, String mimeType, htmlFilterContentScraper scraper) {+ public plasmaParserDocument transformScraper(URL location, String mimeType, String charSet, htmlFilterContentScraper scraper) {try {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];plasmaParserDocument ppd = new plasmaParserDocument(new URL(location.toNormalform()),- mimeType, scraper.getCharset(), scraper.getKeywords(),+ mimeType, charSet, scraper.getKeywords(),scraper.getTitle(), scraper.getTitle(),sections, scraper.getDescription(),scraper.getText(), scraper.getAnchors(), scraper.getImages());diff --git a/source/de/anomic/plasma/plasmaSearchQuery.java b/source/de/anomic/plasma/plasmaSearchQuery.javaindex 1e65779e9..9d28c0ffb 100644--- a/source/de/anomic/plasma/plasmaSearchQuery.java+++ b/source/de/anomic/plasma/plasmaSearchQuery.java@@ -51,6 +51,7 @@ import de.anomic.htmlFilter.htmlFilterAbstractScraper;import de.anomic.index.indexEntryAttribute;import de.anomic.kelondro.kelondroNaturalOrder;import de.anomic.server.serverByteBuffer;+import de.anomic.server.serverCharBuffer;public final class plasmaSearchQuery {@@ -136,7 +137,7 @@ public final class plasmaSearchQuery {public static TreeSet cleanQuery(String words) {// convert Umlaute- words = htmlFilterAbstractScraper.convertUmlaute(new serverByteBuffer(words.getBytes())).toString();+ words = htmlFilterAbstractScraper.convertUmlaute(new serverCharBuffer(words.toCharArray())).toString();// remove funny symbolsfinal String seps = "' .,:/-&";diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.javaindex ff78a663a..60e4f3e60 100644--- a/source/de/anomic/plasma/plasmaSnippetCache.java+++ b/source/de/anomic/plasma/plasmaSnippetCache.java@@ -413,7 +413,7 @@ public class plasmaSnippetCache {return null;}if (plasmaParser.supportedMimeTypesContains(docInfo.getMimeType())) {- return this.parser.parseSource(url, docInfo.getMimeType(), docInfo.getCharSet(), resource);+ return this.parser.parseSource(url, docInfo.getMimeType(), docInfo.getCharacterEncoding(), resource);}return null;} catch (InterruptedException e) {diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex e6e90ed42..dc557ff2b 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -1397,7 +1397,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser// the mimetype of this entryString mimeType = entry.getMimeType();- String charset = entry.getCharSet();+ String charset = entry.getCharacterEncoding();// the parser loggerserverLog parserLogger = parser.getLogger();diff --git a/source/de/anomic/plasma/plasmaSwitchboardQueue.java b/source/de/anomic/plasma/plasmaSwitchboardQueue.javaindex ff77eb002..a75055aaa 100644--- a/source/de/anomic/plasma/plasmaSwitchboardQueue.java+++ b/source/de/anomic/plasma/plasmaSwitchboardQueue.java@@ -320,9 +320,9 @@ public class plasmaSwitchboardQueue {return (info == null) ? null : info.getMimeType();}- public String getCharSet() {+ public String getCharacterEncoding() {IResourceInfo info = this.getCachedObjectInfo();- return (info == null) ? null : info.getCharSet();+ return (info == null) ? null : info.getCharacterEncoding();}public Date getModificationDate() {diff --git a/source/de/anomic/server/serverCharBuffer.java b/source/de/anomic/server/serverCharBuffer.javaindex 1d8a37de0..7d9687a9d 100644--- a/source/de/anomic/server/serverCharBuffer.java+++ b/source/de/anomic/server/serverCharBuffer.java@@ -50,7 +50,7 @@ import java.io.IOException;import java.io.Writer;import java.util.Properties;-public final class serverCharBuffer extends Writer {+public final class serverCharBuffer /* extends Writer */ {public static final char singlequote = '\'';public static final char doublequote = '"';@@ -164,12 +164,12 @@ public final class serverCharBuffer extends Writer {length += le;}- public Writer append(char b) {+ public serverCharBuffer append(char b) {write(b);return this;}- public Writer append(int i) {+ public serverCharBuffer append(int i) {write((char) (i));return this;}@@ -198,11 +198,11 @@ public final class serverCharBuffer extends Writer {return append(bb.buffer, bb.offset, bb.length);}- public serverCharBuffer append(Object o) {- if (o instanceof String) return append((String) o);- if (o instanceof char[]) return append((char[]) o);- return null;- }+// public serverCharBuffer append(Object o) {+// if (o instanceof String) return append((String) o);+// if (o instanceof char[]) return append((char[]) o);+// return null;+// }public char charAt(int pos) {if (pos < 0) throw new IndexOutOfBoundsException();diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.javaindex 495ee7edb..22b531513 100644--- a/source/de/anomic/server/serverFileUtils.java+++ b/source/de/anomic/server/serverFileUtils.java@@ -52,8 +52,12 @@ import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;+import java.io.OutputStreamWriter;import java.io.PrintWriter;+import java.io.Reader;+import java.io.Writer;import java.util.StringTokenizer;+import java.util.zip.GZIPInputStream;import java.util.zip.GZIPOutputStream;import java.util.zip.ZipEntry;import java.util.zip.ZipOutputStream;@@ -93,6 +97,75 @@ public final class serverFileUtils {return total;}++ public static void writeX(InputStream source, OutputStream procOS, OutputStream bufferOS) throws IOException {+ byte[] buffer = new byte[2048];+ int l;++ while ((l = source.read(buffer, 0, buffer.length)) >= 0) {+ if (procOS != null) procOS.write(buffer, 0, l);+ if (bufferOS != null) bufferOS.write(buffer, 0, l);+ }++ // flush the streams+ if (procOS != null) procOS.flush();+ if (bufferOS != null) bufferOS.flush();+ buffer = null;+ }++ public static void writeX(Reader source, Writer procOS, Writer bufferOS) throws IOException {+ char[] buffer = new char[2048];+ int l;++ while ((l = source.read(buffer, 0, buffer.length)) >= 0) {+ if (procOS != null) procOS.write(buffer, 0, l);+ if (bufferOS != null) bufferOS.write(buffer, 0, l);+ }++ // flush the streams+ if (procOS != null) procOS.flush();+ if (bufferOS != null) bufferOS.flush();+ buffer = null;+ }++ public static void writeX(InputStream source, String inputCharset, Writer procOS, OutputStream bufferOS, String outputCharset) throws IOException {+ InputStreamReader sourceReader = new InputStreamReader(source,inputCharset);+ OutputStreamWriter bufferOSWriter = new OutputStreamWriter(bufferOS,outputCharset);+ writeX(sourceReader,procOS,bufferOSWriter);+ }+++ public static int copy (File source, String inputCharset, Writer dest) throws IOException {+ InputStream fis = null;+ try {+ fis = new FileInputStream(source);+ return copy(fis, dest, inputCharset);+ } finally {+ if (fis != null) try { fis.close(); } catch (Exception e) {}+ }+ }++ public static int copy (InputStream source, Writer dest, String inputCharset) throws IOException {+ InputStreamReader reader = new InputStreamReader(source,inputCharset);+ return copy(reader,dest);+ }++ public static int copy (String source, Writer dest) throws IOException {+ dest.write(source);+ dest.flush();+ return source.length();+ }++ public static int copy (Reader source, Writer dest) throws IOException {+ char[] buffer = new char[4096];+ int count = 0;+ int n = 0;+ while (-1 != (n = source.read(buffer))) {+ dest.write(buffer, 0, n);+ count += n;+ }+ return count;+ }/*** Copies an InputStream to a File.@@ -231,6 +304,10 @@ public final class serverFileUtils {if (zipOut != null) try { zipOut.close(); } catch (Exception e) {}}}++ public static void write(String source, Writer dest) throws IOException {+ copy(source,dest);+ }public static void write(byte[] source, OutputStream dest) throws IOException {copy(new ByteArrayInputStream(source), dest);diff --git a/yacy.init b/yacy.initindex db8cb3090..51e681d5e 100644--- a/yacy.init+++ b/yacy.init@@ -599,6 +599,9 @@ isTransparentProxy=false# Specifies if yacy should use the http connection keep-alive featureconnectionKeepAliveSupport=true+# Specifies the timeout the proxy sould use+proxy.clientTimeout = 10000+# Specifies if the proxy should send the via header according to RFCproxy.sendViaHeader=true