Skip to content

Commit

Permalink
reverted put-semantics back to as-usual in serverObjects and introduced
Browse files Browse the repository at this point in the history
an add-method to put in several objects for the same key
  • Loading branch information
Orbiter committed Feb 12, 2013
1 parent 0d888ff commit 16d9085
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 72 deletions.
2 changes: 1 addition & 1 deletion htroot/ViewFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
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++;
Expand Down
2 changes: 1 addition & 1 deletion htroot/yacysearchitem.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
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) {
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/server/http/HTTPDFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static void doResponse(final HashMap<String, Object> conProp, final Reque
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
Expand All @@ -392,7 +392,7 @@ public static void doResponse(final HashMap<String, Object> conProp, final Reque
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"));
Expand Down
26 changes: 13 additions & 13 deletions source/net/yacy/server/http/HTTPDemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ private boolean handleProxyAuthentication(final RequestHeader header, final Hash
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");
Expand Down Expand Up @@ -709,15 +709,15 @@ public static int parseArgs(final serverObjects args, String argsString) {
sep = argsString.indexOf("&amp;", eqp + 1);
if (sep > 0) {
// resulting equations are inserted into the property args with leading '&amp;'
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;
}
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;
Expand Down Expand Up @@ -864,14 +864,14 @@ public static Map<String, byte[]> parseMultipart(final RequestHeader header, fin
// simple text
if (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);
Expand Down Expand Up @@ -1075,25 +1075,25 @@ else if (httpVersion.equals("HTTP/1.1") && HeaderFramework.http1_1.containsKey(I
}

// 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;

// check if ip is local ip address
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);
Expand All @@ -1116,13 +1116,13 @@ else if (httpVersion.equals("HTTP/1.1") && HeaderFramework.http1_1.containsKey(I

// building the stacktrace
if (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)
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/server/http/TemplateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public static void main(final String[] args) {
// arg1 = test input; arg2 = replacement for pattern 'test'; arg3 = default replacement
try {
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();
Expand Down
87 changes: 33 additions & 54 deletions source/net/yacy/server/serverObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -99,12 +98,6 @@ public serverObjects() {
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;
Expand Down Expand Up @@ -170,16 +163,30 @@ public void putAll(Map<String, String> m) {
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
Expand All @@ -195,19 +202,19 @@ public void put(final String key, final String value) {
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
Expand All @@ -221,34 +228,6 @@ public void put(final String key, final String[] values) {
}
}

/**
* 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.
Expand Down

0 comments on commit 16d9085

Please sign in to comment.