Package org.opencms.jsp.util
Class CmsJspJsonWrapper
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.Object>
-
- org.opencms.jsp.util.CmsJspJsonWrapper
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>
,java.util.Collection<java.lang.Object>
public class CmsJspJsonWrapper extends java.util.AbstractCollection<java.lang.Object>
Wrapper for accessing JSON in JSPs.
-
-
Constructor Summary
Constructors Constructor Description CmsJspJsonWrapper(java.lang.Object value)
Creates a new JSON wrapper.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getCompact()
Returns the JSON text as single line, that is as compact as possible.java.lang.Object
getJson()
Returns the wrapped JSON object.java.lang.Object
getObject()
Returns the wrapped JSON object.java.lang.String
getPretty()
Returns the JSON text in pretty-printed and indented format.java.lang.String
getVerbose()
Synonym forgetPretty()
.boolean
isEmpty()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.java.util.Iterator<java.lang.Object>
iterator()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.void
removePath(java.lang.String path)
Removes the parts from the JSON object which match the given path.static void
removePathInJson(java.lang.Object obj, java.util.List<java.lang.String> pathComponents)
Helper method for removing parts from a JSON object with a given path, which is already split into path components.int
size()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.java.lang.String
toString()
-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
CmsJspJsonWrapper
public CmsJspJsonWrapper(java.lang.Object value)
Creates a new JSON wrapper.- Parameters:
value
- the value to wrap
-
-
Method Detail
-
removePathInJson
public static void removePathInJson(java.lang.Object obj, java.util.List<java.lang.String> pathComponents)
Helper method for removing parts from a JSON object with a given path, which is already split into path components. SeeremovePath(String)
for how the path works.- Parameters:
obj
- the JSON objectpathComponents
- the path components
-
getCompact
public java.lang.String getCompact()
Returns the JSON text as single line, that is as compact as possible.- Returns:
- the JSON text
-
getJson
public java.lang.Object getJson()
Returns the wrapped JSON object. This is an alias forgetObject()
.- Returns:
- the wrapped JSON object
- See Also:
getObject()
-
getObject
public java.lang.Object getObject()
Returns the wrapped JSON object. Useful in case you want to insert an existing JSON object into another JSON object.- Returns:
- the wrapped JSON object
-
getPretty
public java.lang.String getPretty()
Returns the JSON text in pretty-printed and indented format.- Returns:
- the pretty-printed and indented JSON
-
getVerbose
public java.lang.String getVerbose()
Synonym forgetPretty()
.- Returns:
- the pretty-printed and indented JSON
- See Also:
getPretty()
-
isEmpty
public boolean isEmpty()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
isEmpty
in interfacejava.util.Collection<java.lang.Object>
- Overrides:
isEmpty
in classjava.util.AbstractCollection<java.lang.Object>
- See Also:
AbstractCollection.isEmpty()
-
iterator
public java.util.Iterator<java.lang.Object> iterator()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
iterator
in interfacejava.util.Collection<java.lang.Object>
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Object>
- Specified by:
iterator
in classjava.util.AbstractCollection<java.lang.Object>
- Returns:
- an empty Iterator in case
isEmpty()
istrue
, otherwise an Iterator that will return the String value of this wrapper exactly once. - See Also:
AbstractCollection.size()
-
removePath
public void removePath(java.lang.String path)
Removes the parts from the JSON object which match the given path.The path is a slash-separated sequence of path components, where each path component is either the name of a JSON field, or the wildcard '*'. The removal process locates all JSON objects matching the parent path of the given path, and then removes the entry given by the last path component from it.
- If a JSON array is encountered while descending the path, the rest of the path is processed for all elements of the array.
- If an object is encountered which does not have an entry with the same name as the next path component, it and its contents are left unchanged.
- The wildcard '* matches all keys in a JSON object.
- Parameters:
path
- the path which should be deleted
-
size
public int size()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
size
in interfacejava.util.Collection<java.lang.Object>
- Specified by:
size
in classjava.util.AbstractCollection<java.lang.Object>
- Returns:
- always returns 0.
- See Also:
AbstractCollection.size()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<java.lang.Object>
- See Also:
Object.toString()
-
-