public final class Storage
extends java.lang.Object
You can obtain a Storage by either invoking
getLocalStorageIfSupported()
or
getSessionStorageIfSupported()
.
Experimental API: This API is still under development and is subject to change.
If Web Storage is NOT supported in the browser, these methods return
null
.
Note: Storage events into other windows are not supported.
This may not be supported on all browsers.
Modifier and Type | Field and Description |
---|---|
(package private) static StorageImpl |
impl |
Modifier and Type | Method and 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.
|
static final StorageImpl impl
public static HandlerRegistration addStorageEventHandler(StorageEvent.Handler handler)
handler
- HandlerRegistration
used to remove this handlerpublic static Storage getLocalStorageIfSupported()
The returned storage is associated with the origin of the Document.
null
if Web Storage is
NOT supported.public static Storage getSessionStorageIfSupported()
The returned storage is associated with the current top-level browsing context.
null
if Web Storage is
NOT supported.public static boolean isLocalStorageSupported()
true
if the localStorage
part of the
Storage API is supported on the running platform.public static boolean isSessionStorageSupported()
true
if the sessionStorage
part of the
Storage API is supported on the running platform.public static boolean isSupported()
true
if the Storage API (both localStorage and
sessionStorage) is supported on the running platform.public static void removeStorageEventHandler(StorageEvent.Handler handler)
handler
- public void clear()
public java.lang.String getItem(java.lang.String key)
key
- the key to a value in the Storagepublic int getLength()
public java.lang.String key(int index)
index
- the index of the keypublic void removeItem(java.lang.String key)
key
- the key to a value in the Storagepublic void setItem(java.lang.String key, java.lang.String data)
key
- the key to a value in the Storagedata
- the value associated with the key