Class 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 for getPretty().
      boolean isEmpty()
      Supports the use of the empty operator in the JSP EL by implementing the Collection interface.
      java.util.Iterator<java.lang.Object> iterator()
      Supports the use of the empty 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 the empty 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
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • 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. See removePath(String) for how the path works.
        Parameters:
        obj - the JSON object
        pathComponents - 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 for getObject().
        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
      • 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 java.util.Collection<java.lang.Object>
        Overrides:
        isEmpty in class java.util.AbstractCollection<java.lang.Object>
        See Also:
        AbstractCollection.isEmpty()
      • iterator

        public java.util.Iterator<java.lang.Object> iterator()
        Supports the use of the empty operator in the JSP EL by implementing the Collection interface.

        Specified by:
        iterator in interface java.util.Collection<java.lang.Object>
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Object>
        Specified by:
        iterator in class java.util.AbstractCollection<java.lang.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:
        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 the empty operator in the JSP EL by implementing the Collection interface.

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

        See Also:
        AbstractCollection.size()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<java.lang.Object>
        See Also:
        Object.toString()