Package com.day.cq.commons
Class JSONWriterUtil
- java.lang.Object
-
- com.day.cq.commons.JSONWriterUtil
-
public class JSONWriterUtil extends java.lang.Object
JSON writer utilitiesEnables to specify a write mode while adding a JSON property. According to the provided write mode, the property value may be encoded through the XSS protection service
- Since:
- 5.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSONWriterUtil.WriteMode
JSON write modes
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_SUFFIX_XSS
Key suffix for XSS protected properties
-
Constructor Summary
Constructors Constructor Description JSONWriterUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
put(JSONObject object, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss)
Puts a value into a JSON object according to provided write mode.static void
putOptional(JSONObject object, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss)
Puts an optional value into a JSON object according to provided write mode.static void
write(JSONWriter writer, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss)
Writes a value to JSON writer according to provided write mode.static void
writeOptional(JSONWriter writer, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss)
Writes an optional value to JSON writer according to provided write mode.
-
-
-
Field Detail
-
KEY_SUFFIX_XSS
public static final java.lang.String KEY_SUFFIX_XSS
Key suffix for XSS protected properties- See Also:
- Constant Field Values
-
-
Method Detail
-
put
public static void put(JSONObject object, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException
Puts a value into a JSON object according to provided write mode.- Parameters:
object
- JSON objectkey
- Key to writevalue
- Value to writewriteMode
- Write modexss
- XSS protection service- Throws:
JSONException
- If value could not be put into the object
-
putOptional
public static void putOptional(JSONObject object, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException
Puts an optional value into a JSON object according to provided write mode.- Parameters:
object
- JSON objectkey
- Key to writevalue
- Value to writewriteMode
- Write modexss
- XSS protection service- Throws:
JSONException
- If value could not be put into the object
-
write
public static void write(JSONWriter writer, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException
Writes a value to JSON writer according to provided write mode.- Parameters:
writer
- JSON writerkey
- Key to writevalue
- Value to writewriteMode
- Write modexss
- XSS protection service- Throws:
JSONException
- If value could not be written
-
writeOptional
public static void writeOptional(JSONWriter writer, java.lang.String key, java.lang.String value, JSONWriterUtil.WriteMode writeMode, XSSProtectionService xss) throws JSONException
Writes an optional value to JSON writer according to provided write mode.- Parameters:
writer
- JSON writerkey
- Key to writevalue
- Value to writewriteMode
- Write modexss
- XSS protection service- Throws:
JSONException
- If value could not be written
-
-