Package com.google.gwt.storage.client
Class Storage
- java.lang.Object
-
- com.google.gwt.storage.client.Storage
-
public final class Storage extends java.lang.ObjectImplements the HTML5 Storage interface.You can obtain a Storage by either invoking
getLocalStorageIfSupported()orgetSessionStorageIfSupported().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.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static StorageImplimpl
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HandlerRegistrationaddStorageEventHandler(StorageEvent.Handler handler)Registers an event handler for StorageEvents.voidclear()Removes all items in the Storage.java.lang.StringgetItem(java.lang.String key)Returns the item in the Storage associated with the specified key.intgetLength()Returns the number of items in this Storage.static StoragegetLocalStorageIfSupported()Returns a Local Storage.static StoragegetSessionStorageIfSupported()Returns a Session Storage.static booleanisLocalStorageSupported()Returnstrueif thelocalStoragepart of the Storage API is supported on the running platform.static booleanisSessionStorageSupported()Returnstrueif thesessionStoragepart of the Storage API is supported on the running platform.static booleanisSupported()Returnstrueif the Storage API (both localStorage and sessionStorage) is supported on the running platform.java.lang.Stringkey(int index)Returns the key at the specified index.voidremoveItem(java.lang.String key)Removes the item in the Storage associated with the specified key.static voidremoveStorageEventHandler(StorageEvent.Handler handler)De-registers an event handler for StorageEvents.voidsetItem(java.lang.String key, java.lang.String data)Sets the value in the Storage associated with the specified key to the specified data.
-
-
-
Field Detail
-
impl
static final StorageImpl impl
-
-
Method Detail
-
addStorageEventHandler
public static HandlerRegistration addStorageEventHandler(StorageEvent.Handler handler)
Registers an event handler for StorageEvents.- Parameters:
handler-- Returns:
HandlerRegistrationused to remove this handler- See Also:
- W3C Web Storage - the storage event
-
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
nullif Web Storage is NOT supported. - See Also:
- W3C Web Storage - localStorage
-
getSessionStorageIfSupported
public static Storage getSessionStorageIfSupported()
Returns a Session Storage.The returned storage is associated with the current top-level browsing context.
- Returns:
- the sessionStorage instance, or
nullif Web Storage is NOT supported. - See Also:
- W3C Web Storage - sessionStorage
-
isLocalStorageSupported
public static boolean isLocalStorageSupported()
Returnstrueif thelocalStoragepart of the Storage API is supported on the running platform.
-
isSessionStorageSupported
public static boolean isSessionStorageSupported()
Returnstrueif thesessionStoragepart of the Storage API is supported on the running platform.
-
isSupported
public static boolean isSupported()
Returnstrueif the Storage API (both localStorage and sessionStorage) is supported on the running platform.
-
removeStorageEventHandler
public static void removeStorageEventHandler(StorageEvent.Handler handler)
De-registers an event handler for StorageEvents.- Parameters:
handler-- See Also:
- W3C Web Storage - the storage event
-
clear
public void clear()
Removes all items in the Storage.- See Also:
- W3C Web Storage - Storage.clear()
-
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)
-
getLength
public int getLength()
Returns the number of items in this Storage.- Returns:
- number of items in this Storage
- See Also:
- W3C Web Storage - Storage.length()
-
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 Storagedata- the value associated with the key- See Also:
- W3C Web Storage - Storage.setItem(k,v)
-
-