Sha256: 1108b456fb13e49885f64a5338f720501c9a8dea589461d294d12563172a9d6b

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

/**
 * Sencha GXT 3.1.1 - Sencha for GWT
 * Copyright(c) 2007-2014, Sencha, Inc.
 * licensing@sencha.com
 *
 * http://www.sencha.com/products/gxt/license/
 */
package com.dldinternet.aws.cfn.stacker.desktopapp.client.persistence;

import com.google.gwt.storage.client.Storage;
import com.google.gwt.storage.client.StorageMap;

import java.util.Iterator;

// TODO: Consider decorator pattern for encryption layer support

public class StorageBackingStore implements BackingStore {

  private static final String DELIMITER = ".";

  private Storage storage;
  private String storageKeyPrefix;

  public StorageBackingStore(Storage storage, String storageKeyPrefix) {
    this.storage = storage;
    this.storageKeyPrefix = storageKeyPrefix;
  }

  @Override
  public void clear() {
    String qualifiedStorageKeyPrefix = storageKeyPrefix + DELIMITER;
    StorageMap storageMap = new StorageMap(storage);
    Iterator<String> iterator = storageMap.keySet().iterator();
    while (iterator.hasNext()) {
      String key = iterator.next();
      if (key.startsWith(qualifiedStorageKeyPrefix)) {
        iterator.remove();
      }
    }
  }

  @Override
  public String getItem(String key) {
    return storage.getItem(getStorageKey(key));
  }

  @Override
  public void removeItem(String key) {
    storage.removeItem(getStorageKey(key));
  }

  @Override
  public void setItem(String key, String data) {
    storage.setItem(getStorageKey(key), data);
  }

  private String getStorageKey(String key) {
    return storageKeyPrefix + DELIMITER + key;
  }

}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws-cfn-stacker-0.0.6 ui/src/com/dldinternet/aws/cfn/stacker/desktopapp/client/persistence/StorageBackingStore.java