Class CmsJspJsonWrapper

java.lang.Object
java.util.AbstractCollection<Object>
org.opencms.jsp.util.CmsJspJsonWrapper
All Implemented Interfaces:
Iterable<Object>, Collection<Object>

Wrapper for accessing JSON in JSPs.
  • Constructor Details

    • CmsJspJsonWrapper

      public CmsJspJsonWrapper(Object value)
      Creates a new JSON wrapper.
      Parameters:
      value - the value to wrap
  • Method Details

    • removePathInJson

      public static void removePathInJson(Object obj, List<String> pathComponents)
      Helper method for removing parts from a JSON object with a given path, which is already split into path components. See removePath(String) for how the path works.
      Parameters:
      obj - the JSON object
      pathComponents - the path components
    • getCompact

      public String getCompact()
      Returns the JSON text as single line, that is as compact as possible.
      Returns:
      the JSON text
    • getJson

      public Object getJson()
      Returns the wrapped JSON object. This is an alias for getObject().
      Returns:
      the wrapped JSON object
      See Also:
    • getObject

      public 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 String getPretty()
      Returns the JSON text in pretty-printed and indented format.
      Returns:
      the pretty-printed and indented JSON
    • getVerbose

      public String getVerbose()
      Synonym for getPretty().
      Returns:
      the pretty-printed and indented JSON
      See Also:
    • isEmpty

      public boolean isEmpty()
      Supports the use of the empty operator in the JSP EL by implementing the Collection interface.

      Specified by:
      isEmpty in interface Collection<Object>
      Overrides:
      isEmpty in class AbstractCollection<Object>
      See Also:
    • iterator

      Supports the use of the empty operator in the JSP EL by implementing the Collection interface.

      Specified by:
      iterator in interface Collection<Object>
      Specified by:
      iterator in interface Iterable<Object>
      Specified by:
      iterator in class AbstractCollection<Object>
      Returns:
      an empty Iterator in case isEmpty() is true, otherwise an Iterator that will return the String value of this wrapper exactly once.

      See Also:
    • removePath

      public void removePath(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 the empty operator in the JSP EL by implementing the Collection interface.

      Specified by:
      size in interface Collection<Object>
      Specified by:
      size in class AbstractCollection<Object>
      Returns:
      always returns 0.

      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Object>
      See Also: