Class Storage

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static StorageImpl impl  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static HandlerRegistration addStorageEventHandler​(StorageEvent.Handler handler)
      Registers an event handler for StorageEvents.
      void clear()
      Removes all items in the Storage.
      java.lang.String getItem​(java.lang.String key)
      Returns the item in the Storage associated with the specified key.
      int getLength()
      Returns the number of items in this Storage.
      static Storage getLocalStorageIfSupported()
      Returns a Local Storage.
      static Storage getSessionStorageIfSupported()
      Returns a Session Storage.
      static boolean isLocalStorageSupported()
      Returns true if the localStorage part of the Storage API is supported on the running platform.
      static boolean isSessionStorageSupported()
      Returns true if the sessionStorage part of the Storage API is supported on the running platform.
      static boolean isSupported()
      Returns true if the Storage API (both localStorage and sessionStorage) is supported on the running platform.
      java.lang.String key​(int index)
      Returns the key at the specified index.
      void removeItem​(java.lang.String key)
      Removes the item in the Storage associated with the specified key.
      static void removeStorageEventHandler​(StorageEvent.Handler handler)
      De-registers an event handler for StorageEvents.
      void setItem​(java.lang.String key, java.lang.String data)
      Sets the value in the Storage associated with the specified key to the specified data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getLocalStorageIfSupported

        public static Storage getLocalStorageIfSupported()
        Returns a Local Storage.

        The returned storage is associated with the origin of the Document.

        Returns:
        the localStorage instance, or null if Web Storage is NOT supported.
        See Also:
        W3C Web Storage - localStorage
      • isLocalStorageSupported

        public static boolean isLocalStorageSupported()
        Returns true if the localStorage part of the Storage API is supported on the running platform.
      • isSessionStorageSupported

        public static boolean isSessionStorageSupported()
        Returns true if the sessionStorage part of the Storage API is supported on the running platform.
      • isSupported

        public static boolean isSupported()
        Returns true if the Storage API (both localStorage and sessionStorage) is supported on the running platform.
      • getItem

        public java.lang.String getItem​(java.lang.String key)
        Returns the item in the Storage associated with the specified key.
        Parameters:
        key - the key to a value in the Storage
        Returns:
        the value associated with the given key
        See Also:
        W3C Web Storage - Storage.getItem(k)
      • key

        public java.lang.String key​(int index)
        Returns the key at the specified index.
        Parameters:
        index - the index of the key
        Returns:
        the key at the specified index in this Storage
        See Also:
        W3C Web Storage - Storage.key(n)
      • removeItem

        public void removeItem​(java.lang.String key)
        Removes the item in the Storage associated with the specified key.
        Parameters:
        key - the key to a value in the Storage
        See Also:
        W3C Web Storage - Storage.removeItem(k)
      • setItem

        public void setItem​(java.lang.String key,
                            java.lang.String data)
        Sets the value in the Storage associated with the specified key to the specified data. Note: The empty string may not be used as a key.
        Parameters:
        key - the key to a value in the Storage
        data - the value associated with the key
        See Also:
        W3C Web Storage - Storage.setItem(k,v)