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

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

Introduction

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

Prototype

public int getLength() 

Source Link

Document

Returns the number of items in this Storage.

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  www.  j  a  va2 s  . c om*/
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  ww  w .j  ava2 s.c  o  m*/
 */
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:ch.gbrain.gwtstorage.manager.StorageManager.java

License:Apache License

/**
 * Retrieve all ResourceItems related keys from the LocalStorage
 * //from w  w w.j  a va  2s  .c o  m
 * @return The number of resources which will be evaluated and for which
 *         callbacks have to be expected
 */
public int getAllCachedResourceItems(final Callback<StorageInfo, FileError> callback) {
    int resCtr = 0;
    try {
        if (!this.isResourceCachingEnabled())
            return 0;
        if (callback == null)
            return 0;
        logger.log(Level.INFO, "getAllCachedResourceItems");
        Storage storage = this.getLocalStorage();
        int len = storage.getLength();
        for (int i = 0; i < len; i++) {
            String key = storage.key(i);
            if (StorageResource.isResourceIdKey(key)) {
                logger.log(Level.INFO, "Read cached Resource : " + key);
                StorageInfoCollector collector = new StorageInfoCollector(this, key, callback);
                Scheduler.get().scheduleDeferred(collector);
                resCtr++;
            }
        }
        return resCtr;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Execption reading all cached Resources", ex);
    }
    return resCtr;
}

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

License:Open Source License

@Override
public void onLoad() {
    tabPanel.selectTab(0);//from  w  w w.j a  va 2 s  .  co  m

    if (!Beans.isDesignTime()) {
        Storage s = Storage.getLocalStorageIfSupported();

        if (s != null) {

            for (int i = 0; i < s.getLength(); i++) {
                String key = s.key(i);

                if ((key != null) && key.startsWith(STORAGE_KEY)) {
                    String name = key.substring(STORAGE_KEY.length());
                    storageList.addItem(name, key);
                }
            }
        }
    }
}

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

License:Apache License

/**
 * Resets (clears) the stored state from localStorage.
 *//*www .  j a  v  a2 s  .  com*/
private void resetStoredState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage == null) {
        return;
    }
    // note: length is live
    for (int i = 0; i < storage.getLength();) {
        String key = storage.key(i);
        if (key.startsWith(STORAGE_PREFIX)) {
            removeState(storage, key.substring(STORAGE_PREFIX.length()));
        } else {
            i++;
        }
    }
}

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

public static Set<String> getPrefNames() {
    Set<String> names = new HashSet<String>(20);
    {//from w w w  .  jav  a 2s. c om
        // check session storage for preferences
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        if (sessionStorage != null) {
            String key;
            for (int i = 0; i < sessionStorage.getLength(); i++) {
                key = sessionStorage.key(i);
                if (key.startsWith(PREFIX)) {
                    names.add(key.substring(PREFIX.length()));
                }
            }
        }
    }

    {
        // check browser local storage
        Storage localStorage = Storage.getLocalStorageIfSupported();
        if (localStorage != null) {
            String key;
            for (int i = 0; i < localStorage.getLength(); i++) {
                key = localStorage.key(i);
                if (key.startsWith(PREFIX)) {
                    names.add(key.substring(PREFIX.length()));
                }
            }
        }
    }

    // preferences in the local map
    names.addAll(localPrefMap.keySet());

    return names;
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.LocalStoragePresenter.java

License:Open Source License

protected void localStorageData() {
    final Storage localStorage = Storage.getLocalStorageIfSupported();
    for (int itemIndex = 0; itemIndex < localStorage.getLength(); itemIndex++) {
        final String key = localStorage.key(itemIndex);
        ((ComplexView) simpleView).addHtmlText(key, "highlightedText");
        ((ComplexView) simpleView).addText(localStorage.getItem(key));
    }/*from  w  w w  .  ja v  a  2 s  . c om*/
}