Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
reverted put-semantics back to as-usual in serverObjects and introduced an add-method to put in several objects for the same key
Michael Peter Christen16d90859b75f
diff --git a/htroot/ViewFile.java b/htroot/ViewFile.javaindex 26087953c..244a9fddb 100644--- a/htroot/ViewFile.java+++ b/htroot/ViewFile.java@@ -290,7 +290,7 @@ public class ViewFile {token = tokens.nextElement();if (token.length() > 0) {prop.put("viewMode_words_" + i + "_nr", i + 1);- prop.put("viewMode_words_" + i + "_word", token);+ prop.put("viewMode_words_" + i + "_word", token.toString());prop.put("viewMode_words_" + i + "_dark", dark ? "1" : "0");dark = !dark;i++;diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.javaindex c66a5c891..5e80889e3 100644--- a/htroot/yacysearchitem.java+++ b/htroot/yacysearchitem.java@@ -101,7 +101,7 @@ public class yacysearchitem {prop.put("remoteResourceSize", Formatter.number(theSearch.query.remote_stored.get(), true));prop.put("remoteIndexCount", Formatter.number(theSearch.query.remote_available.get(), true));prop.put("remotePeerCount", Formatter.number(theSearch.query.remote_peerCount.get(), true));- prop.put("navurlBase", QueryParams.navurlBase("html", theSearch.query, null));+ prop.put("navurlBase", QueryParams.navurlBase("html", theSearch.query, null).toString());final String target_special_pattern = sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, "");if (theSearch.query.contentdom == Classification.ContentDomain.TEXT || theSearch.query.contentdom == Classification.ContentDomain.ALL) {diff --git a/source/net/yacy/server/http/HTTPDFileHandler.java b/source/net/yacy/server/http/HTTPDFileHandler.javaindex 50ab3d2c2..b33e38d07 100644--- a/source/net/yacy/server/http/HTTPDFileHandler.java+++ b/source/net/yacy/server/http/HTTPDFileHandler.java@@ -366,7 +366,7 @@ public final class HTTPDFileHandler {serverCore.bfHost.remove(conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));// parse arguments- serverObjects args = new serverObjects(true);+ serverObjects args = new serverObjects();int argc = 0;if (argsString == null) {// no args here, maybe a POST with multipart extension@@ -392,7 +392,7 @@ public final class HTTPDFileHandler {Map.Entry<String, byte[]> entry;while (fit.hasNext()) {entry = fit.next();- args.put(entry.getKey() + "$file", entry.getValue());+ args.add(entry.getKey() + "$file", entry.getValue());}}argc = Integer.parseInt(requestHeader.get("ARGC"));diff --git a/source/net/yacy/server/http/HTTPDemon.java b/source/net/yacy/server/http/HTTPDemon.javaindex ee6309338..e2b13c47c 100644--- a/source/net/yacy/server/http/HTTPDemon.java+++ b/source/net/yacy/server/http/HTTPDemon.java@@ -329,10 +329,10 @@ public final class HTTPDemon implements serverHandler, Cloneable {if (returncode == UserDB.Entry.PROXY_ALLOK) {return true;}- final serverObjects tp = new serverObjects(true);+ final serverObjects tp = new serverObjects();if (returncode == UserDB.Entry.PROXY_TIMELIMIT_REACHED) {tp.put("limit", "1");//time per day- tp.put("limit_timelimit", entry.getTimeLimit());+ tp.put("limit_timelimit", Long.toString(entry.getTimeLimit()));sendRespondError(prop, session.out, 403, "Internet-Timelimit reached", new File("proxymsg/proxylimits.inc"), tp, null);} else if (returncode == UserDB.Entry.PROXY_NORIGHT){tp.put("limit", "0");@@ -709,7 +709,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {sep = argsString.indexOf("&", eqp + 1);if (sep > 0) {// resulting equations are inserted into the property args with leading '&'- args.put(parseArg(argsString.substring(0, eqp)), parseArg(argsString.substring(eqp + 1, sep)));+ args.add(parseArg(argsString.substring(0, eqp)), parseArg(argsString.substring(eqp + 1, sep)));argsString = argsString.substring(sep + 5);argc++;continue;@@ -717,7 +717,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {sep = argsString.indexOf('&', eqp + 1);if (sep > 0) {// resulting equations are inserted into the property args with leading '&'- args.put(parseArg(argsString.substring(0, eqp)), parseArg(argsString.substring(eqp + 1, sep)));+ args.add(parseArg(argsString.substring(0, eqp)), parseArg(argsString.substring(eqp + 1, sep)));argsString = argsString.substring(sep + 1);argc++;continue;@@ -864,14 +864,14 @@ public final class HTTPDemon implements serverHandler, Cloneable {// simple textif (item.getContentType() == null || !item.getContentType().contains("charset")) {// old yacy clients use their local default charset, on most systems UTF-8 (I hope ;)- args.put(item.getFieldName(), item.getString("UTF-8"));+ args.add(item.getFieldName(), item.getString("UTF-8"));} else {// use default encoding (given as header or ISO-8859-1)- args.put(item.getFieldName(), item.getString());+ args.add(item.getFieldName(), item.getString());}} else {// file- args.put(item.getFieldName(), item.getName());+ args.add(item.getFieldName(), item.getName());fileContent = FileUtils.read(item.getInputStream(), (int) item.getSize());item.getInputStream().close();files.put(item.getFieldName(), fileContent);@@ -1075,7 +1075,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {}// set rewrite values- final serverObjects tp = new serverObjects(true);+ final serverObjects tp = new serverObjects();String clientIP = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); if (clientIP == null) clientIP = Domains.LOCALHOST;@@ -1083,17 +1083,17 @@ public final class HTTPDemon implements serverHandler, Cloneable {final InetAddress hostAddress = Domains.dnsResolve(clientIP);if (hostAddress == null) {tp.put("host", Domains.myPublicLocalIP().getHostAddress());- tp.put("port", serverCore.getPortNr(switchboard.getConfig("port", "8090")));+ tp.put("port", Integer.toString(serverCore.getPortNr(switchboard.getConfig("port", "8090"))));} else if (hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress()) {tp.put("host", Domains.myPublicLocalIP().getHostAddress());- tp.put("port", serverCore.getPortNr(switchboard.getConfig("port", "8090")));+ tp.put("port", Integer.toString(serverCore.getPortNr(switchboard.getConfig("port", "8090"))));} else {tp.put("host", switchboard.myPublicIP());tp.put("port", Integer.toString(serverCore.getPortNr(switchboard.getConfig("port", "8090"))));}tp.put("peerName", (getAlternativeResolver() == null) ? "" : getAlternativeResolver().myName());- tp.put("errorMessageType", errorcase);+ tp.put("errorMessageType", Integer.toString(errorcase));tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText);tp.put("requestMethod", (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD));tp.put("requestURL", urlString);@@ -1116,13 +1116,13 @@ public final class HTTPDemon implements serverHandler, Cloneable {// building the stacktraceif (stackTrace != null) {- tp.put("printStackTrace",1);+ tp.put("printStackTrace", "1");final ByteBuffer errorMsg = new ByteBuffer(100);stackTrace.printStackTrace(new PrintStream(errorMsg));tp.put("printStackTrace_exception", stackTrace.toString());tp.put("printStackTrace_stacktrace", UTF8.String(errorMsg.getBytes()));} else {- tp.put("printStackTrace", 0);+ tp.put("printStackTrace", "0");}// Generated Tue, 23 Aug 2005 11:19:14 GMT by brain.wg (squid/2.5.STABLE3)diff --git a/source/net/yacy/server/http/TemplateEngine.java b/source/net/yacy/server/http/TemplateEngine.javaindex 9cd9d7293..11b73b037 100644--- a/source/net/yacy/server/http/TemplateEngine.java+++ b/source/net/yacy/server/http/TemplateEngine.java@@ -511,7 +511,7 @@ public final class TemplateEngine {// arg1 = test input; arg2 = replacement for pattern 'test'; arg3 = default replacementtry {final InputStream i = new ByteArrayInputStream(UTF8.getBytes(args[0]));- final serverObjects h = new serverObjects(true);+ final serverObjects h = new serverObjects();h.put("test", args[1]);writeTemplate(new PushbackInputStream(i, 100), System.out, h, UTF8.getBytes(args[2]));System.out.flush();diff --git a/source/net/yacy/server/serverObjects.java b/source/net/yacy/server/serverObjects.javaindex a7e67cedb..75796a24f 100644--- a/source/net/yacy/server/serverObjects.java+++ b/source/net/yacy/server/serverObjects.java@@ -89,7 +89,6 @@ public class serverObjects implements Serializable, Cloneable {private final static Pattern patternT = Pattern.compile("\t");private boolean localized = true;- private boolean allowMultipleEntries = false;private final static char BOM = '\uFEFF'; // ByteOrderMark character that may appear at beginnings of Strings (Browser may append that)private final MultiMapSolrParams map;@@ -99,12 +98,6 @@ public class serverObjects implements Serializable, Cloneable {this.map = new MultiMapSolrParams(new HashMap<String, String[]>());}- public serverObjects(final boolean allowMultipleEntries) {- super();- this.allowMultipleEntries = allowMultipleEntries;- this.map = new MultiMapSolrParams(new HashMap<String, String[]>());- }-protected serverObjects(serverObjects o) {super();this.map = o.map;@@ -170,16 +163,30 @@ public class serverObjects implements Serializable, Cloneable {put(e.getKey(), e.getValue());}}++ public void add(final String key, final String value) {+ if (key == null) {+ // this does nothing+ return;+ }+ if (value == null) {+ return;+ }+ String[] a = map.getMap().get(key);+ if (a == null) {+ map.getMap().put(key, new String[]{value});+ return;+ }+ for (int i = 0; i < a.length; i++) {+ if (a[i].equals(value)) return;+ }+ String[] aa = new String[a.length + 1];+ System.arraycopy(a, 0, aa, 0, a.length);+ aa[a.length] = value;+ map.getMap().put(key, aa);+ return;+ }- /**- * Add a key-value pair of Objects to the map.- * @param key This method will do nothing if the key is <code>null</code>.- * @param value The value that should be mapped to the key.- * If value is <code>null</code>, then the element at <code>key</code>- * is removed from the map.- * @return The value that was added to the map.- * @see java.util.Hashtable#insert(K, V)- */public void put(final String key, final String value) {if (key == null) {// this does nothing@@ -195,19 +202,19 @@ public class serverObjects implements Serializable, Cloneable {map.getMap().put(key, new String[]{value});return;}- if (this.allowMultipleEntries) {- for (int i = 0; i < a.length; i++) {- if (a[i].equals(value)) return;- }- String[] aa = new String[a.length + 1];- System.arraycopy(a, 0, aa, 0, a.length);- aa[a.length] = value;- map.getMap().put(key, aa);- return;- }map.getMap().put(key, new String[]{value});}+ public void add(final String key, final byte[] value) {+ if (value == null) return;+ add(key, UTF8.String(value));+ }++ public void put(final String key, final byte[] value) {+ if (value == null) return;+ put(key, UTF8.String(value));+ }+public void put(final String key, final String[] values) {if (key == null) {// this does nothing@@ -221,34 +228,6 @@ public class serverObjects implements Serializable, Cloneable {}}- /**- * Add a key-value pair of Objects to the map.- * @param key This method will do nothing if the key is <code>null</code>.- * @param value The value that should be mapped to the key.- * If value is <code>null</code>, then the element at <code>key</code>- * is removed from the map.- * @return The value that was added to the map.- * @see java.util.Hashtable#insert(K, V)- */- public void put(final String key, final StringBuilder value) {- if (key == null) {- // this does nothing- return;- }- put(key, value.toString());- }-- /**- * Add byte array to the map, value is kept as it is.- * @param key key name as String.- * @param value mapped value as a byte array.- * @return the previous value as String.- */- public void put(final String key, final byte[] value) {- if (value == null) return;- put(key, UTF8.String(value));- }-/*** Add an unformatted String representation of a double/float value* to the map.