From 138a0747e3c8ef0628c2f292cc6ab6428842ba19 Mon Sep 17 00:00:00 2001 From: apfelmaennchen Date: Sat, 25 Apr 2009 20:56:29 +0000 Subject: [PATCH] added serverObjects.putJSON as JSON has very particulare encoding requirements git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5877 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/server/serverObjects.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 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.