Interface WebStorage


public interface WebStorage
An HTML WebStorage.

Provides access to the session storage or local storage for a particular document on the loaded web page. Allows you to add, modify, or delete the stored items.

Since:
7.1
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all the items from the storage.
    boolean
    Returns true if the storage contains an item with the specified key, otherwise false.
    item(String key)
    Returns an Optional that contains the value associated with the given key if it exists in the storage, otherwise an empty Optional.
    key(int index)
    Returns an Optional that contains the name of the key by the specified index if it exists in the storage, otherwise an empty Optional.
    int
    Returns the number of key/value pairs in the storage.
    void
    putItem(String key, String value)
    Adds the item with the specified key and value to the storage, or updates it if the item with the given key already exists.
    void
    Removes the item with the specified key from the storage.
  • Method Details

    • length

      int length()
      Returns the number of key/value pairs in the storage.
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • key

      Optional<String> key(int index)
      Returns an Optional that contains the name of the key by the specified index if it exists in the storage, otherwise an empty Optional. The order of keys is not specified and may change as you add or remove items to the storage.
      Parameters:
      index - the index of the key to get the name of. Must be in range 0 <= index < length()
      Throws:
      IllegalArgumentException - when the index is not in the 0 <= index < length() range
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • item

      Optional<String> item(String key)
      Returns an Optional that contains the value associated with the given key if it exists in the storage, otherwise an empty Optional.
      Parameters:
      key - the key name of the item to retrieve the value of. Can be empty or blank
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • putItem

      void putItem(String key, String value)
      Adds the item with the specified key and value to the storage, or updates it if the item with the given key already exists.
      Parameters:
      key - the key name of the item to put. Can be empty or blank
      value - the value of the item to put. Can be empty or blank
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageOverflowException - when if the item size exceeds the available space in the storage
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • removeItem

      void removeItem(String key)
      Removes the item with the specified key from the storage. Does nothing if there is no item with the specified key in the storage.
      Parameters:
      key - the key name of the item to remove. Can be empty or blank
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • clear

      void clear()
      Removes all the items from the storage.
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document
    • contains

      boolean contains(String key)
      Returns true if the storage contains an item with the specified key, otherwise false.
      Parameters:
      key - the key name to check. Can be empty or blank
      Throws:
      ObjectClosedException - when the frame is closed
      WebStorageSecurityException - if the access to the storage is forbidden for the current document