Skip to content

Commit

Permalink
added serverObjects.putJSON as JSON has very particulare encoding req…
Browse files Browse the repository at this point in the history
…uirements

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5877 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
apfelmaennchen committed Apr 25, 2009
1 parent 557c2a3 commit 138a074
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions source/de/anomic/server/serverObjects.java
Expand Up @@ -146,6 +146,27 @@ public String put(final String key, final DateFormatter value) {
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.
Expand Down

0 comments on commit 138a074

Please sign in to comment.