Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- the wiki-parser works for remote wiki-code now, not displaying links anymore as if they were local (ViewProfile comment) - fixed wrong link to CrawlStart on Status-page
karlchenofhellf05ca437806a
diff --git a/htroot/Status.html b/htroot/Status.htmlindex f3d8572f0..bd24b3544 100644--- a/htroot/Status.html+++ b/htroot/Status.html@@ -90,7 +90,7 @@#(hintCrawlStart)#::<dt class="hintIcon"><img src="env/grafics/idea.png" width="32" height="32" alt="idea"/></dt>- <dd class="hint">Your Web Page Indexer is idle. You can start your own web crawl <a href="IndexCreate_p.html">here</a>+ <dd class="hint">Your Web Page Indexer is idle. You can start your own web crawl <a href="CrawlStartSimple_p.html">here</a></dd>#(/hintCrawlStart)#diff --git a/htroot/ViewProfile.java b/htroot/ViewProfile.javaindex b9a47366e..0ec3f0ce2 100644--- a/htroot/ViewProfile.java+++ b/htroot/ViewProfile.java@@ -86,6 +86,7 @@ public class ViewProfile {// get the profileHashMap profile = null;+ String address = null;if (hash.equals("localhash")) {// read the profile from local peerProperties p = new Properties();@@ -102,6 +103,7 @@ public class ViewProfile {prop.put("localremotepeer", 0);prop.put("success_peername", yacyCore.seedDB.mySeed.getName());prop.put("success_peerhash", yacyCore.seedDB.mySeed.hash);+ address = yacyCore.seedDB.mySeed.getPublicAddress();} else {// read the profile from remote peeryacySeed seed = yacyCore.seedDB.getConnected(hash);@@ -128,6 +130,7 @@ public class ViewProfile {}prop.put("success_peername", seed.getName());prop.put("success_peerhash", seed.hash);+ address = seed.getPublicAddress();}prop.put("localremotepeer", 1);}@@ -156,7 +159,7 @@ public class ViewProfile {while (it.hasNext()) {prop.put("success_" + (String) it.next(), 0);}-+//number of not explicitly recognized but displayed itemsint numUnknown = 0;while (i.hasNext()) {@@ -175,7 +178,8 @@ public class ViewProfile {if(key.equals("comment")){prop.putWiki("success_" + key + "_value",- ((String) entry.getValue()).replaceAll("\r", "").replaceAll("\\\\n", "\n")+ ((String) entry.getValue()).replaceAll("\r", "").replaceAll("\\\\n", "\n"),+ address);prop.putASIS("success_" + key + "_b64value",kelondroBase64Order.standardCoder.encodeString((String) entry.getValue()));}else{diff --git a/source/de/anomic/data/wiki/abstractWikiParser.java b/source/de/anomic/data/wiki/abstractWikiParser.javaindex ac038c6a6..8715ebc03 100644--- a/source/de/anomic/data/wiki/abstractWikiParser.java+++ b/source/de/anomic/data/wiki/abstractWikiParser.java@@ -8,16 +8,17 @@ import java.io.StringReader;import java.io.UnsupportedEncodingException;import de.anomic.plasma.plasmaSwitchboard;+import de.anomic.yacy.yacyCore;public abstract class abstractWikiParser implements wikiParser {- protected plasmaSwitchboard sb;+ private plasmaSwitchboard sb;public abstractWikiParser(plasmaSwitchboard sb) {this.sb = sb;}- protected abstract String transform(BufferedReader reader, int length, plasmaSwitchboard sb) throws IOException;+ protected abstract String transform(BufferedReader reader, int length, String publicAddress, plasmaSwitchboard sb) throws IOException;public String transform(String content) {return transform(content, this.sb);@@ -25,12 +26,28 @@ public abstract class abstractWikiParser implements wikiParser {public String transform(String content, plasmaSwitchboard sb) {try {- return transform(new BufferedReader(new StringReader(content)), content.length(), sb);+ return transform(+ new BufferedReader(new StringReader(content)),+ content.length(),+ yacyCore.seedDB.mySeed.getPublicAddress(),+ sb);} catch (IOException e) {return "internal error: " + e.getMessage();}}-++ public String transform(String content, String publicAddress) {+ try {+ return transform(+ new BufferedReader(new StringReader(content)),+ content.length(),+ publicAddress,+ null);+ } catch (IOException e) {+ return "internal error: " + e.getMessage();+ }+ }+public String transform(byte[] content) throws UnsupportedEncodingException {return transform(content, "UTF-8", this.sb);}@@ -39,10 +56,27 @@ public abstract class abstractWikiParser implements wikiParser {return transform(content, encoding, this.sb);}+ public String transform(byte[] content, String encoding, String publicAddress) throws UnsupportedEncodingException {+ ByteArrayInputStream bais = new ByteArrayInputStream(content);+ try {+ return transform(+ new BufferedReader(new InputStreamReader(bais, encoding)),+ content.length,+ publicAddress,+ null);+ } catch (IOException e) {+ return "internal error: " + e.getMessage();+ }+ }+public String transform(byte[] content, String encoding, plasmaSwitchboard switchboard) throws UnsupportedEncodingException {ByteArrayInputStream bais = new ByteArrayInputStream(content);try {- return transform(new BufferedReader(new InputStreamReader(bais, encoding)), content.length, switchboard);+ return transform(+ new BufferedReader(new InputStreamReader(bais, encoding)),+ content.length,+ yacyCore.seedDB.mySeed.getPublicAddress(),+ switchboard);} catch (IOException e) {return "internal error: " + e.getMessage();}diff --git a/source/de/anomic/data/wiki/knwikiParser.java b/source/de/anomic/data/wiki/knwikiParser.javaindex eb502ca77..1b0ac8791 100644--- a/source/de/anomic/data/wiki/knwikiParser.java+++ b/source/de/anomic/data/wiki/knwikiParser.java@@ -106,39 +106,47 @@ public class knwikiParser implements wikiParser {String t = "[=] ein fucking [= test =]-text[=,ne?!=] joa, [=alles=]wunderbar," +"[=denk ich=] mal =]";long l = System.currentTimeMillis();- t = new knwikiParser(null).parse((args.length > 0) ? args[0] : text);+ t = new knwikiParser(null).parse((args.length > 0) ? args[0] : text, "localhost:8080");System.out.println("parsing time: " + (System.currentTimeMillis() - l) + " ms");System.out.println("--- --- ---");System.out.println(t);}public String transform(String content) {- return parse(content);+ return parse(content, null);}public String transform(String content, plasmaSwitchboard sb) {- return parse(content);+ return parse(content, null);}public String transform(byte[] content) throws UnsupportedEncodingException {- return parse(new String(content, "UTF-8"));+ return parse(new String(content, "UTF-8"), null);}public String transform(byte[] content, String encoding,plasmaSwitchboard switchboard) throws UnsupportedEncodingException {- return parse(new String(content, encoding));+ return parse(new String(content, encoding), null);}public String transform(byte[] content, String encoding) throws UnsupportedEncodingException {- return parse(new String(content, encoding));+ return parse(new String(content, encoding), null);+ }++ public String transform(byte[] text, String encoding, String publicAddress) throws UnsupportedEncodingException {+ return parse(new String(text, encoding), publicAddress);+ }++ public String transform(String text, String publicAddress) {+ return parse(text, publicAddress);}- public String parse(String text) {+ public String parse(String text, String publicAddress) {tokens = new Token[] {new SimpleToken('=', '=', new String[][] { null, { "h2" }, { "h3" }, { "h4" } }, true),new SimpleToken('\'', '\'', new String[][] { null, { "i" }, { "b" }, null, { "b", "i" } }, false),- new LinkToken(yacyCore.seedDB.mySeed.getPublicAddress(), "Wiki.html?page=", sb),+ new LinkToken((publicAddress == null) ? yacyCore.seedDB.mySeed.getPublicAddress() : publicAddress, "Wiki.html?page=", sb),new ListToken('*', "ul"),new ListToken('#', "ol"),new ListToken(':', "blockquote", null),diff --git a/source/de/anomic/data/wiki/wikiParser.java b/source/de/anomic/data/wiki/wikiParser.javaindex dc2d82038..9ce6020b2 100644--- a/source/de/anomic/data/wiki/wikiParser.java+++ b/source/de/anomic/data/wiki/wikiParser.java@@ -8,7 +8,9 @@ public interface wikiParser {public String transform(String text);public String transform(String text, plasmaSwitchboard switchboard);+ public String transform(String text, String publicAddress);public String transform(byte[] text) throws UnsupportedEncodingException;public String transform(byte[] text, String encoding) throws UnsupportedEncodingException;public String transform(byte[] text, String encoding, plasmaSwitchboard switchboard) throws UnsupportedEncodingException;+ public String transform(byte[] text, String encoding, String publicAddress) throws UnsupportedEncodingException;}diff --git a/source/de/anomic/data/wikiCode.java b/source/de/anomic/data/wikiCode.javaindex 6031ff075..bcb058ed0 100644--- a/source/de/anomic/data/wikiCode.java+++ b/source/de/anomic/data/wikiCode.java@@ -56,7 +56,6 @@ import de.anomic.data.wiki.abstractWikiParser;import de.anomic.data.wiki.wikiParser;import de.anomic.plasma.plasmaSwitchboard;import de.anomic.server.serverCore;-import de.anomic.yacy.yacyCore;/** This class provides methods to handle texts that have been posted in the yacyWiki or other* parts of YaCy that use this class, like the blog or the profile.@@ -107,11 +106,12 @@ public class wikiCode extends abstractWikiParser implements wikiParser {protected String transform(BufferedReader reader,int length,+ String publicAddress,plasmaSwitchboard switchboard) throws IOException {StringBuffer out = new StringBuffer(length);String line;while ((line = reader.readLine()) != null)- out.append(transformLine(line, switchboard)).append(serverCore.crlfString);+ out.append(transformLine(line, publicAddress, switchboard)).append(serverCore.crlfString);return out.insert(0, directory()).toString();}@@ -395,7 +395,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {/** This method processes links and images.*///contributed by [AS] except where stated otherwise- private String linksAndImages(String result, plasmaSwitchboard switchboard){+ private String linksAndImages(String result, String publicAddress, plasmaSwitchboard switchboard) {// create linksString kl, kv, alt, align;@@ -448,7 +448,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {// or an image DATA/HTDOCS/grafics/kaskelix.jpg with [[Image:grafics/kaskelix.jpg]]// you are free to use other sub-paths of DATA/HTDOCSif (kl.indexOf("://")<1) {- kl = "http://" + yacyCore.seedDB.mySeed.getPublicAddress().trim() + "/" + kl;+ kl = "http://" + publicAddress.trim() + "/" + kl;}result = result.substring(0, p0) + "<img src=\"" + kl + "\"" + align + alt + ">" + result.substring(p1 + 2);@@ -463,10 +463,11 @@ public class wikiCode extends abstractWikiParser implements wikiParser {} else {kv = kl;}- if (switchboard.wikiDB.read(kl) != null)+ if (switchboard != null && switchboard.wikiDB.read(kl) != null) {result = result.substring(0, p0) + "<a class=\"known\" href=\"Wiki.html?page=" + kl + "\">" + kv + "</a>" + result.substring(p1 + 2);- else+ } else {result = result.substring(0, p0) + "<a class=\"unknown\" href=\"Wiki.html?page=" + kl + "&edit=Edit\">" + kv + "</a>" + result.substring(p1 + 2);+ }}}@@ -488,8 +489,8 @@ public class wikiCode extends abstractWikiParser implements wikiParser {// using the wikicode [share/page.html]// or a file DATA/HTDOCS/www/page.html with [www/page.html]// you are free to use other sub-paths of DATA/HTDOCS- if (kl.indexOf("://")<1) {- kl = "http://" + yacyCore.seedDB.mySeed.getPublicAddress().trim() + "/" + kl;+ if (kl.indexOf("://") < 1) {+ kl = "http://" + publicAddress.trim() + "/" + kl;}result = result.substring(0, p0) + "<a class=\"extern\" href=\"" + kl + "\">" + kv + "</a>" + result.substring(p1 + 1);}@@ -498,7 +499,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {/** This method handles the escape tags [= =] *///contributed by [MN]- private String escapeTag(String result, plasmaSwitchboard switchboard){+ private String escapeTag(String result, String publicAddress, plasmaSwitchboard switchboard){int p0 = 0;int p1 = 0;//both [= and =] in the same line@@ -506,16 +507,16 @@ public class wikiCode extends abstractWikiParser implements wikiParser {if(p0<p1){String escapeText = result.substring(p0+2,p1);escapeText = escapeText.replaceAll("!esc!", "!esc!!");- result = transformLine(result.substring(0,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!"+result.substring(p1+2).replaceAll("!esc!", "!esc!!"), switchboard);+ result = transformLine(result.substring(0,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!"+result.substring(p1+2).replaceAll("!esc!", "!esc!!"), publicAddress, switchboard);result = result.replaceAll("!esc!txt!", escapeText);result = result.replaceAll("!esc!!", "!esc!");}//handles cases like [=[= =]=] [= =] that would cause an exception otherwiseelse{escape = true;- String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", switchboard);+ String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", publicAddress, switchboard);nolist = true;- String temp2 = transformLine(result.substring(p0), switchboard);+ String temp2 = transformLine(result.substring(p0), publicAddress, switchboard);nolist = false;result = temp1.replaceAll("!tmp!txt!",temp2);result = result.replaceAll("!tmp!!", "!tmp!");@@ -535,7 +536,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {escindented++;bq = bq + "<blockquote>";}- result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", switchboard);+ result = transformLine(result.substring(escindented,p0).replaceAll("!esc!", "!esc!!")+"!esc!txt!", publicAddress, switchboard);result = bq + result.replaceAll("!esc!txt!", escapeText);result = result.replaceAll("!esc!!", "!esc!");escape = false;@@ -553,7 +554,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {bq = bq + "</blockquote>";escindented--;}- result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), switchboard);+ result = transformLine("!esc!txt!"+result.substring(p0+2).replaceAll("!esc!", "!esc!!"), publicAddress, switchboard);result = result.replaceAll("!esc!txt!", escapeText) + bq;result = result.replaceAll("!esc!!", "!esc!");escaped = false;@@ -563,14 +564,14 @@ public class wikiCode extends abstractWikiParser implements wikiParser {while((p0 = result.indexOf("=]"))>=0){result = result.substring(0,p0)+result.substring(p0+2);}- result = transformLine(result, switchboard);+ result = transformLine(result, publicAddress, switchboard);}return result;}/** This method handles the preformatted tags <pre> </pre> *///contributed by [MN]- private String preformattedTag(String result, plasmaSwitchboard switchboard){+ private String preformattedTag(String result, String publicAddress, plasmaSwitchboard switchboard){int p0 = 0;int p1 = 0;//implementation very similar to escape code (see above)@@ -579,16 +580,16 @@ public class wikiCode extends abstractWikiParser implements wikiParser {if(p0<p1){String preformattedText = "<pre style=\"border:dotted;border-width:thin\">"+result.substring(p0+11,p1)+"</pre>";preformattedText = preformattedText.replaceAll("!pre!", "!pre!!");- result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), switchboard);+ result = transformLine(result.substring(0,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!"+result.substring(p1+12).replaceAll("!pre!", "!pre!!"), publicAddress, switchboard);result = result.replaceAll("!pre!txt!", preformattedText);result = result.replaceAll("!pre!!", "!pre!");}//handles cases like <pre><pre> </pre></pre> <pre> </pre> that would cause an exception otherwiseelse{preformatted = true;- String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", switchboard);+ String temp1 = transformLine(result.substring(0,p0-1).replaceAll("!tmp!","!tmp!!")+"!tmp!txt!", publicAddress, switchboard);nolist = true;- String temp2 = transformLine(result.substring(p0), switchboard);+ String temp2 = transformLine(result.substring(p0), publicAddress, switchboard);nolist = false;result = temp1.replaceAll("!tmp!txt!",temp2);result = result.replaceAll("!tmp!!", "!tmp!");@@ -607,7 +608,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {preindented++;bq = bq + "<blockquote>";}- result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", switchboard);+ result = transformLine(result.substring(preindented,p0).replaceAll("!pre!", "!pre!!")+"!pre!txt!", publicAddress, switchboard);result = bq + result.replaceAll("!pre!txt!", preformattedText);result = result.replaceAll("!pre!!", "!pre!");preformattedSpan = true;@@ -624,7 +625,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {bq = bq + "</blockquote>";preindented--;}- result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), switchboard);+ result = transformLine("!pre!txt!"+result.substring(p0+12).replaceAll("!pre!", "!pre!!"), publicAddress, switchboard);result = result.replaceAll("!pre!txt!", preformattedText) + bq;result = result.replaceAll("!pre!!", "!pre!");preformatted = false;@@ -634,7 +635,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {while((p0 = result.indexOf("</pre>"))>=0){result = result.substring(0,p0)+result.substring(p0+12);}- result = transformLine(result, switchboard);+ result = transformLine(result, publicAddress, switchboard);}return result;}@@ -773,7 +774,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {* @param switchboard* @return the line of text with HTML tags instead of wiki tags*/- public String transformLine(String result, plasmaSwitchboard switchboard) {+ public String transformLine(String result, String publicAddress, plasmaSwitchboard switchboard) {//If HTML has not bee replaced yet (can happen if method gets called in recursion), replace now!if (!replacedHTML || preformattedSpan){result = htmlTools.replaceXMLEntities(result);@@ -787,12 +788,12 @@ public class wikiCode extends abstractWikiParser implements wikiParser {//check if line contains escape symbols([= =]) or if we are in an escape sequence already.if ((result.indexOf("[=")>=0)||(result.indexOf("=]")>=0)||(escapeSpan)){- result = escapeTag(result, switchboard);+ result = escapeTag(result, publicAddress, switchboard);}//check if line contains preformatted symbols or if we are in a preformatted sequence already.else if ((result.indexOf("<pre>")>=0)||(result.indexOf("</pre>")>=0)||(preformattedSpan)){- result = preformattedTag(result, switchboard);+ result = preformattedTag(result, publicAddress, switchboard);}//transform page as usual@@ -831,7 +832,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {result = orderedList(result);result = definitionList(result);- result = linksAndImages(result, switchboard);+ result = linksAndImages(result, publicAddress, switchboard);}diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.javaindex 1c0d00872..1d55daa47 100644--- a/source/de/anomic/server/serverObjects.java+++ b/source/de/anomic/server/serverObjects.java@@ -132,6 +132,16 @@ public class serverObjects extends Hashtable implements Cloneable {return this.putASIS(key, "Internal error pasting wiki-code: " + e.getMessage());}}+ public String putWiki(Object key, String wikiCode, String publicAddress) {+ return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode, publicAddress));+ }+ public String putWiki(Object key, byte[] wikiCode, String publicAddress) {+ try {+ return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode, "UTF-8", publicAddress));+ } catch (UnsupportedEncodingException e) {+ return this.putASIS(key, "Internal error pasting wiki-code: " + e.getMessage());+ }+ }// long variantpublic long put(String key, long value) {