Package com.google.gwt.storage.client

Examples of com.google.gwt.storage.client.Storage


      storage.setItem(STORAGE_KEY, todoItems.toString());
    }
  }

  private void loadState() {
    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {
      try {
        // get state
        String state = storage.getItem(STORAGE_KEY);

        // parse the JSON array
        JSONArray todoItems = JSONParser.parseStrict(state).isArray();
        for (int i = 0; i < todoItems.size(); i++) {
          // extract the to-do item values
View Full Code Here


public class LocalFXStorage implements FXStorage {

    private Map<String,String> delegate;

    public LocalFXStorage() {
        Storage storage = Storage.getLocalStorageIfSupported();

        if(null==storage)
        {
            Log.warn("Local storage not supported");
            this.delegate = new HashMap<String,String>();
View Full Code Here

    return jsonString;
  }
  public static void clearSettings() {
    String key = Helper.getCurrentHost() + "_" + CookieKeys.SETTINGS;
    if (Storage.isLocalStorageSupported()) {
      Storage html5Storage = Storage.getLocalStorageIfSupported();
      html5Storage.removeItem(key);
    } else {
      //We are using a browser which does not support html5
      Cookies.removeCookie(key);
    }
  }
View Full Code Here

    String key = Helper.getCurrentHost() + "_" + CookieKeys.LOGIN_STACK;
    clear(key);
  }
  private static void clear(String key) {
    if (Storage.isLocalStorageSupported()) {
      Storage html5Storage = Storage.getLocalStorageIfSupported();
      html5Storage.removeItem(key);
    } else {
      //We are using a browser which does not support html5
      Cookies.removeCookie(key);
    }
  }
View Full Code Here

    return result;
  }
 
  private static StorageMap getStorageMap() {
    StorageMap storageMap = null;
    Storage html5Storage = Storage.getLocalStorageIfSupported();
    if (html5Storage != null) {
      storageMap = new StorageMap(html5Storage);
    }
    return storageMap;
  }
View Full Code Here

    }
    return null;
  }
 
  private static void removeLocalStorageKey(String key) {
    Storage html5Storage = Storage.getLocalStorageIfSupported();
    String domain = Helper.getCurrentHost();
    html5Storage.removeItem(domain + "_" + key);
  }
View Full Code Here

    html5Storage.removeItem(domain + "_" + key);
  }
 
  private static void storeInLocalStorage(String key, String value) {
    if (Storage.isLocalStorageSupported()) {
      Storage html5Storage = Storage.getLocalStorageIfSupported();
      try {
        html5Storage.setItem(Helper.getCurrentHost() + "_" + key, value);
      } catch (Throwable t) {
        Helper.logExceptionToServer(t);
      }
    }
  }
View Full Code Here

        });

        try {

            Long viewID = null;
            final Storage storage = Storage.getSessionStorageIfSupported();
            if (storage != null) {
                final String v = storage.getItem(APPLICATION.VIEW_ID);
                if (v != null && !v.isEmpty()) viewID = Long.parseLong(v);
            }
            final PTInstruction requestData = new PTInstruction();

            final JSONArray cookies = new JSONArray();

            // load all cookies at startup
            final Collection<String> cookieNames = Cookies.getCookieNames();
            if (cookieNames != null) {
                int i = 0;
                for (final String cookie : cookieNames) {
                    final JSONObject jsoObject = new JSONObject();
                    jsoObject.put(PROPERTY.KEY, new JSONString(cookie));
                    jsoObject.put(PROPERTY.VALUE, new JSONString(Cookies.getCookie(cookie)));
                    cookies.set(i++, jsoObject);
                }
            }

            requestData.put(APPLICATION.KEY, APPLICATION.KEY_.START);
            requestData.put(APPLICATION.SEQ_NUM, 0);
            requestData.put(HISTORY.TOKEN, History.getToken());
            requestData.put(PROPERTY.COOKIES, cookies);

            if (viewID != null) requestData.put(APPLICATION.VIEW_ID, viewID);

            final RequestCallback requestCallback = new RequestCallback() {

                @Override
                public void onDataReceived(final JSONObject data) {
                    try {
                        if (data.containsKey(APPLICATION.VIEW_ID)) {
                            applicationViewID = (long) data.get(APPLICATION.VIEW_ID).isNumber().doubleValue();

                            if (storage != null) storage.setItem(APPLICATION.VIEW_ID, Long.toString(applicationViewID));

                            uiBuilder.init(applicationViewID, requestBuilder);
                        }

                        uiBuilder.update(data);
View Full Code Here

   }

   @Test
   public void keySessionStorage() {
      // Arrange
      Storage session = Storage.getSessionStorageIfSupported();
      session.setItem("test0", "my test 0");
      session.setItem("test1", "my test 1");
      session.setItem("test2", "my test 2");

      // Act
      String key0 = session.key(0);
      String key1 = session.key(1);
      String key2 = session.key(2);

      // Assert
      assertThat(key0).isEqualTo("test0");
      assertThat(key1).isEqualTo("test1");
      assertThat(key2).isEqualTo("test2");
View Full Code Here

public class StorageTest extends GwtTestTest {

   @Test
   public void clearLocalStorage() {
      // Arrange
      Storage local = Storage.getLocalStorageIfSupported();
      local.setItem("test", "my test");
      local.setItem("test2", "my test 2");

      // Pre-Assert
      assertThat(local.getLength()).isEqualTo(2);

      // Act
      local.clear();

      // Assert
      assertThat(local.getLength()).isEqualTo(0);
   }
View Full Code Here

TOP

Related Classes of com.google.gwt.storage.client.Storage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.