List of usage examples for com.google.gwt.storage.client Storage isSupported
public static boolean isSupported()
true if the Storage API (both localStorage and sessionStorage) is supported on the running platform. From source file:ch.takoyaki.email.html.client.service.FileServiceImpl.java
License:Open Source License
@Override public boolean isSupported() { return Storage.isSupported(); }
From source file:com.data2semantics.yasgui.client.View.java
License:Open Source License
/** * For a given endpoint, check whether it is defined in our endpoints datasource. * If it isnt, add it //ww w . j av a 2 s . com * * @param endpoint */ public void checkAndAddEndpointToDs(String endpoint) { if (!getSettings().inSingleEndpointMode()) { Record[] records = endpointDataSource.getCacheData(); boolean exists = false; for (Record record : records) { String recordEndpoint = record.getAttribute(Endpoints.KEY_ENDPOINT); if (recordEndpoint != null && recordEndpoint.equals(endpoint)) { exists = true; break; } } if (!exists) { //Ok, so endpoint is not in our datasource. let's add it ListGridRecord listGridRecord = new ListGridRecord(); listGridRecord.setAttribute(Endpoints.KEY_ENDPOINT, endpoint); Record[] newRecords = new Record[records.length + 1]; newRecords[0] = listGridRecord; System.arraycopy(records, 0, newRecords, 1, records.length); endpointDataSource = new EndpointDataSource(this, newRecords); if (Storage.isSupported()) { //we have html5. add it to local storage as well so we keep it persistent between sessions String endpointsJsonString = LocalStorageHelper.getEndpointsFromLocalStorage(); if (endpointsJsonString == null) { //There are no endpoints in our storage. //This is kinda strange, but lets create a json array with this new endpoint anyway JSONArray jsonArray = new JSONArray(); JSONObject newEndpointObject = new JSONObject(); newEndpointObject.put(Endpoints.KEY_ENDPOINT, new JSONString(endpoint)); jsonArray.set(0, newEndpointObject); LocalStorageHelper.setEndpoints(jsonArray.toString()); } else { //Prepend the new endpoint to the array in our json object JSONValue jsonVal = JSONParser.parseStrict(endpointsJsonString); if (jsonVal != null) { JSONArray endpoints = jsonVal.isArray(); JSONArray newEndpointsArray = new JSONArray(); JSONObject newEndpointObject = new JSONObject(); newEndpointObject.put(Endpoints.KEY_ENDPOINT, new JSONString(endpoint)); newEndpointsArray.set(0, newEndpointObject); if (endpoints != null) { for (int i = 0; i < endpoints.size(); i++) { newEndpointsArray.set(newEndpointsArray.size(), endpoints.get(i)); } } LocalStorageHelper.setEndpoints(newEndpointsArray.toString()); } } } } } }
From source file:org.clevermore.monitor.client.utils.LocalStorage.java
License:Apache License
public static String readStoredItem(final String key) { if (Storage.isSupported()) { String item = Storage.getLocalStorageIfSupported().getItem(key); item = item == null ? "" : item; Log.debug("Returning value:" + item + ", from local storage with key:" + key); return item; } else {/* www . j a va 2s. c o m*/ // get from cookies String cookie = Cookies.getCookie(key); Log.debug("Returning value:" + cookie + ", from cookie with key:" + key); return cookie; } }
From source file:org.clevermore.monitor.client.utils.LocalStorage.java
License:Apache License
public static void storeItem(final String key, final String value) { if (Storage.isSupported()) { Log.debug("Storing value:" + value + ", with key:" + key + ", to local storage"); Storage.getLocalStorageIfSupported().setItem(key, value); } else {/*from ww w. java 2 s . c om*/ // store to cookies Log.debug("Storing value:" + value + ", with key:" + key + ", to cookie"); Cookies.setCookie(key, value, new Date(Long.MAX_VALUE)); } }
From source file:org.clevermore.monitor.client.utils.LocalStorage.java
License:Apache License
public static void removeItem(final String key) { if (Storage.isSupported()) { Log.debug("Removing key:" + key + ", from local storage"); Storage.getLocalStorageIfSupported().removeItem(key); } else {/* www . j a v a2 s. c o m*/ // store to cookies Log.debug("Removing key:" + key + ", from cookies"); Cookies.removeCookie(key); } }