public interface 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.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all the items from the storage.
|
boolean |
contains(java.lang.String key)
Returns
true if the storage contains an item with the specified key ,
otherwise false . |
java.util.Optional<java.lang.String> |
item(java.lang.String key)
Returns an
Optional that contains the value associated with the given key if
it exists in the storage, otherwise an empty Optional . |
java.util.Optional<java.lang.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 . |
int |
length()
Returns the number of key/value pairs in the storage.
|
void |
putItem(java.lang.String key,
java.lang.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 |
removeItem(java.lang.String key)
Removes the item with the specified
key from the storage. |
int length()
ObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentjava.util.Optional<java.lang.String> key(int index)
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.index
- the index of the key to get the name of. Must be in range 0 <= index <
length()
java.lang.IllegalArgumentException
- when the index
is not in the 0 <= index <
length()
rangeObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentjava.util.Optional<java.lang.String> item(java.lang.String key)
Optional
that contains the value associated with the given key
if
it exists in the storage, otherwise an empty Optional
.key
- the key name of the item to retrieve the value of. Can be empty or blankObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentvoid putItem(java.lang.String key, java.lang.String value)
key
and value
to the storage, or updates it
if the item with the given key
already exists.key
- the key name of the item to put. Can be empty or blankvalue
- the value of the item to put. Can be empty or blankObjectClosedException
- when the frame is closedWebStorageOverflowException
- when if the item size exceeds the available space in the
storageWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentvoid removeItem(java.lang.String key)
key
from the storage. Does nothing if there is no
item with the specified key
in the storage.key
- the key name of the item to remove. Can be empty or blankObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentvoid clear()
ObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
documentboolean contains(java.lang.String key)
true
if the storage contains an item with the specified key
,
otherwise false
.key
- the key name to check. Can be empty or blankObjectClosedException
- when the frame is closedWebStorageSecurityException
- if the access to the storage is forbidden for the current
document