-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathStorage.java
More file actions
44 lines (35 loc) · 1.12 KB
/
Storage.java
File metadata and controls
44 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package snap.webapi;
/**
* This class is a wrapper for Web API Storage (https://developer.mozilla.org/en-US/docs/Web/API/Storage).
*/
public class Storage extends JSProxy {
// The local storage
private static Storage _localStorage;
/**
* Constructor.
*/
public Storage(Object programJS)
{
super(programJS);
}
public String getItem(String aKey) { return (String) call("getItem", aKey); }
public void setItem(String aKey, String aValue)
{
if (aValue == null)
removeItem(aKey);
else call("setItem", aKey, aValue);
}
public void removeItem(String aKey) { call("removeItem", aKey); }
public String getKey(int anIndex) { return (String) call("key", anIndex); }
public void clear() { call("clear"); }
/**
* Returns the shared local storage.
*/
public static Storage getLocalStorage()
{
if (_localStorage != null) return _localStorage;
Window window = Window.get();
Object localStorageJS = window.getMember("localStorage");
return _localStorage = new Storage(localStorageJS);
}
}