Example usage for com.google.gwt.storage.client Storage removeItem

List of usage examples for com.google.gwt.storage.client Storage removeItem

Introduction

In this page you can find the example usage for com.google.gwt.storage.client Storage removeItem.

Prototype

public void removeItem(String key) 

Source Link

Document

Removes the item in the Storage associated with the specified key.

Usage

From source file:ch.gbrain.gwtstorage.manager.StorageManager.java

License:Apache License

/**
 * Remove all StorageItem related keys from the LocalStorage, thus clear the
 * cached json objects and references etc.
 *//*from   w w w  .  j  a va 2  s. com*/
public void clearStorageItems() {
    try {
        Storage storage = this.getLocalStorage();
        if (storage == null)
            return;
        Integer len = storage.getLength();
        int index = 0;
        for (int i = 0; i < len; i++) {
            String key = storage.key(index);
            if (StorageItem.isStorageItemKey(key)) {
                logger.log(Level.INFO, "Remove cached StorageItem:" + key);
                storage.removeItem(key);
            } else {
                index++;
            }
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Execption clearing StorageItems", ex);
    }
}

From source file:ch.gbrain.gwtstorage.manager.StorageManager.java

License:Apache License

/**
 * Remove all ResourceItem related keys from the LocalStorage and as well
 * related resource files, ClearCache/*from www  .  j a va  2s. com*/
 */
public void clearResourceItems() {
    try {
        Storage storage = this.getLocalStorage();
        if (storage == null)
            return;
        Integer len = storage.getLength();
        Integer index = 0;
        for (int i = 0; i < len; i++) {
            String key = storage.key(index);
            if (StorageResource.isResourceIdKey(key)) {
                logger.log(Level.INFO, "Remove cached ResourceId : " + key);
                final String fullFileUrl = storage.getItem(key);
                storage.removeItem(key);
                // now remove the corresponding file asynch
                phonegap.getFile().resolveLocalFileSystemURI(fullFileUrl,
                        new FileCallback<EntryBase, FileError>() {
                            @Override
                            public void onSuccess(EntryBase entry) {
                                try {
                                    logger.log(Level.INFO,
                                            "Remove resource file:" + entry.getAsFileEntry().getFullPath());
                                    entry.getAsFileEntry().remove(new FileCallback<Boolean, FileError>() {
                                        @Override
                                        public void onSuccess(Boolean entry) {
                                            logger.log(Level.INFO, "Successfully deleted file:" + fullFileUrl);
                                        }

                                        @Override
                                        public void onFailure(FileError error) {
                                            logger.log(Level.WARNING, "Unable to delete File:" + fullFileUrl
                                                    + " error:" + error.getErrorCode());
                                        }
                                    });
                                } catch (Exception successEx) {
                                    logger.log(Level.WARNING, "Remove resource file failed:"
                                            + entry.getAsFileEntry().getFullPath(), successEx);
                                }
                            }

                            @Override
                            public void onFailure(FileError error) {
                                logger.log(Level.WARNING, "Unable to locate File for deletion:" + fullFileUrl
                                        + " error:" + error.getErrorCode());
                            }
                        });
            } else if (StorageResource.isResourceVersionKey(key)) {
                logger.log(Level.INFO, "Remove cached ResourceVersion : " + key);
                storage.removeItem(key);
            } else {
                index++;
            }
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Execption clearing Resources", ex);
    }
}

From source file:com.ait.tooling.nativetools.client.storage.AbstractStorage.java

License:Open Source License

protected AbstractStorage(final CacheType type, Storage storage) {
    m_type = type;//  ww  w.  j  av a 2  s  .com

    if (null != storage) {
        try {
            final String test = "__" + type + "__";

            storage.setItem(test, test);

            storage.removeItem(test);
        } catch (Exception e) {
            storage = null;

            Client.get().error(type + " is not enabled, Browser may be in private mode: ", e);
        }
    }
    m_storage = storage;
}

From source file:com.data2semantics.yasgui.client.helpers.LocalStorageHelper.java

License:Open Source License

private static void removeLocalStorageKey(String key) {
    Storage html5Storage = Storage.getLocalStorageIfSupported();
    String domain = Helper.getCurrentHost();
    html5Storage.removeItem(domain + "_" + key);
}

From source file:com.dawg6.web.dhcalc.client.SavePanel.java

License:Open Source License

protected void renameLocalStorage() {
    String name = getName();/*from w  w  w.ja v  a  2  s  .  co m*/

    if (name != null) {
        final Storage s = getStorage();

        if (s != null) {
            final int i = storageList.getSelectedIndex();

            if (i < 0) {
                ApplicationPanel.showErrorDialog("Select a Storage entry");
            } else {
                String key = storageList.getValue(i);
                String value = s.getItem(key);
                storageList.removeItem(i);
                s.removeItem(key);
                key = STORAGE_KEY + name;
                s.setItem(key, value);
                storageList.insertItem(name, key, i);
            }
        }
    }
}

From source file:com.dawg6.web.dhcalc.client.SavePanel.java

License:Open Source License

protected void deleteLocalStorage() {
    final Storage s = getStorage();

    if (s != null) {
        final int i = storageList.getSelectedIndex();

        if (i < 0) {
            ApplicationPanel.showErrorDialog("Select a Storage entry");
        } else {/*from w ww.ja v  a2s  . c  om*/
            String key = storageList.getValue(i);
            storageList.removeItem(i);
            s.removeItem(key);
        }
    }
}

From source file:com.vaadin.client.debug.internal.VDebugWindow.java

License:Apache License

/**
 * Removes the item with the given key (automatically prefixed with
 * {@value #STORAGE_PREFIX}) from the given {@link Storage}.
 * /*from w  w  w . j  a  va 2s  .  c  om*/
 * @param storage
 * @param key
 */
private void removeState(Storage storage, String key) {
    storage.removeItem(STORAGE_PREFIX + key);
}

From source file:edu.caltech.ipac.firefly.core.Preferences.java

public static void set(String prefname, String prefvalue, boolean sessionScope) {

    if (sessionScope) {
        // put preference into session storage, if available
        // otherwise into local static map
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        if (sessionStorage != null) {
            //oldvalue = sessionStorage.getItem(PREFIX+prefname);
            if (prefvalue == null) {
                sessionStorage.removeItem(PREFIX + prefname);
            } else {
                sessionStorage.setItem(PREFIX + prefname, prefvalue);
            }/*w w  w.  j a v  a2 s  .  co m*/
        } else {
            //oldvalue =  localPrefMap.get(prefname);
            localPrefMap.put(prefname, prefvalue);
        }
    }

    else {
        // check browser local storage
        Storage localStorage = Storage.getLocalStorageIfSupported();
        String oldvalue;
        if (localStorage != null) {
            oldvalue = localStorage.getItem(PREFIX + prefname);
            if (prefvalue == null) {
                localStorage.removeItem(PREFIX + prefname);
            } else {
                localStorage.setItem(PREFIX + prefname, prefvalue);
            }
        } else {
            oldvalue = localPrefMap.get(prefname);
            localPrefMap.put(prefname, prefvalue);
        }
        if (notBulkUpdate && loginManager != null && loginManager.isLoggedIn()) {
            if ((prefvalue != null && !prefvalue.equals(oldvalue))
                    || (oldvalue != null && !oldvalue.equals(prefvalue))) {
                // logged in user - also put preferences to db
                loginManager.setPreference(prefname, prefvalue);
            }
        }
    }

    // no need to fire event
    // fire event if preference value has changed 
    //if ((prefvalue != null && !prefvalue.equals(oldvalue)) ||
    //        (oldvalue != null && !oldvalue.equals(prefvalue))) {
    //    HashMap<String,String> prefmap = new HashMap<String,String>(1);
    //    prefmap.put(prefname,prefvalue);
    //    WebEventManager.getAppEvManager().fireEvent(new WebEvent(Preferences.class, Name.PREFERENCE_UPDATE, prefmap));
    //}
}

From source file:fr.mncc.gwttoolbox.base.client.OfflineStorage.java

License:Open Source License

/**
 * Remove item whose key is key from local storage
 * // w  ww  .  j av a2  s  . c o  m
 * @param key unique identifier
 */
public static void RemoveFromLocalStorage(final String key) {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null)
        storage.removeItem(key);
}

From source file:fr.mncc.gwttoolbox.base.client.OfflineStorage.java

License:Open Source License

/**
 * Remove item whose key is key from session storage
 * /*from   w  ww . j av a 2s . c o m*/
 * @param key unique identifier
 */
public static void RemoveFromSessionStorage(final String key) {
    Storage storage = Storage.getSessionStorageIfSupported();
    if (storage != null)
        storage.removeItem(key);
}