diff options
Diffstat (limited to 'src/esieequest/engine/datastore/BrowserDataStore.java')
-rw-r--r-- | src/esieequest/engine/datastore/BrowserDataStore.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/esieequest/engine/datastore/BrowserDataStore.java b/src/esieequest/engine/datastore/BrowserDataStore.java new file mode 100644 index 0000000..e00cc5c --- /dev/null +++ b/src/esieequest/engine/datastore/BrowserDataStore.java | |||
@@ -0,0 +1,37 @@ | |||
1 | package esieequest.engine.datastore; | ||
2 | |||
3 | import com.google.gwt.storage.client.Storage; | ||
4 | |||
5 | /** | ||
6 | * The browser datastore adapter. Uses the browser's content storage. | ||
7 | * | ||
8 | * @author Pacien TRAN-GIRARD | ||
9 | */ | ||
10 | public class BrowserDataStore implements DataStore { | ||
11 | |||
12 | private final Storage contentStorage; | ||
13 | |||
14 | /** | ||
15 | * Creates a new datastore. | ||
16 | */ | ||
17 | public BrowserDataStore() { | ||
18 | this.contentStorage = Storage.getLocalStorageIfSupported(); | ||
19 | } | ||
20 | |||
21 | @Override | ||
22 | public String load(final String path) { | ||
23 | if (this.contentStorage == null) { | ||
24 | return null; | ||
25 | } | ||
26 | return this.contentStorage.getItem(path); | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | public void save(final String path, final String serialisedGame) { | ||
31 | if (this.contentStorage == null) { | ||
32 | return; | ||
33 | } | ||
34 | this.contentStorage.setItem(path, serialisedGame); | ||
35 | } | ||
36 | |||
37 | } | ||