JSONUtil.java
2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.apache.sling.commons.json.io.JSONWriter
*/
package com.adobe.granite.xss;
import com.adobe.granite.xss.ProtectionContext;
import com.adobe.granite.xss.XSSFilter;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.io.JSONWriter;
@Deprecated
public class JSONUtil {
public static final String KEY_SUFFIX_XSS = "_xss";
public static void putProtected(JSONObject object, String key, String value, XSSFilter xss) throws JSONException {
String xssValue = xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, value);
object.put(key, (Object)xssValue);
}
public static void putWithProtected(JSONObject object, String key, String value, XSSFilter xss) throws JSONException {
JSONUtil.putProtected(object, key + "_xss", value, xss);
object.put(key, (Object)value);
}
public static void writeProtected(JSONWriter writer, String key, String value, XSSFilter xss) throws JSONException {
String xssValue = xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, value);
writer.key(key).value((Object)xssValue);
}
public static void writeProtected(JSONWriter writer, String key, String[] values, XSSFilter xss) throws JSONException {
writer.key(key);
writer.array();
for (String value : values) {
String xssValue = xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, value);
writer.value((Object)xssValue);
}
writer.endArray();
}
public static void writeWithProtected(JSONWriter writer, String key, String value, XSSFilter xss) throws JSONException {
JSONUtil.writeProtected(writer, key + "_xss", value, xss);
writer.key(key).value((Object)value);
}
public static void writeWithProtected(JSONWriter writer, String key, String[] values, XSSFilter xss) throws JSONException {
JSONUtil.writeProtected(writer, key + "_xss", values, xss);
writer.key(key);
writer.array();
for (String value : values) {
writer.value((Object)value);
}
writer.endArray();
}
}