Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added serverObjects.putJSON as JSON has very particulare encoding requirements

apfelmaennchen138a0747e3c8
diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java
index a10fc5b15..6a068518b 100644
--- a/source/de/anomic/server/serverObjects.java
+++ b/source/de/anomic/server/serverObjects.java
@@ -146,6 +146,27 @@ public class serverObjects extends HashMap<String, String> implements Cloneable
public String put(final String key, final InetAddress value) {
return this.put(key, value.toString());
}
+ /**
+ * Add a String to the map. The content of the String is escaped to be usable in JSON output.
+ * @param key key name as String.
+ * @param value a String that will be reencoded for JSON output.
+ * @return the modified String that was added to the map.
+ * @see htmlFilterCharacterCoding#encodeUnicode2json(String, boolean)
+ */
+ public String putJSON(final String key, String value) {
+ value = value.replaceAll("\"", "\\\"");
+ value = value.replaceAll("/", "\\/");
+ // value = value.replaceAll("\\", "\\\\");
+ value = value.replaceAll("\b", "\\b");
+ value = value.replaceAll("\f", "\\f");
+ value = value.replaceAll("\n", "\\r");
+ value = value.replaceAll("\r", "\\r");
+ value = value.replaceAll("\t", "\\t");
+ return put(key, value);
+ }
+ public String putJSON(final String key, final byte[] value) {
+ return putJSON(key, new String(value));
+ }
/**
* Add a String to the map. The content of the String is escaped to be usable in HTML output.