
org.emfjson.gwt.handlers.LocalStorageHandler Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2015 Guillaume Hillairet.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Guillaume Hillairet - initial API and implementation
*
*/
package org.emfjson.gwt.handlers;
import com.google.gwt.storage.client.Storage;
import org.eclipse.emf.common.util.Callback;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.URIHandlerImpl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
/**
* LocalStorageHandler
*
* URIHandler implementation that uses GWT Storage to store EMF/JSON documents
* in Browsers' local store.
*
* @author ghillairet
* @since 0.6.1
*/
public class LocalStorageHandler extends URIHandlerImpl {
private String BASE_KEY = "emfjs:";
public LocalStorageHandler() {
}
public LocalStorageHandler(String baseKey) {
BASE_KEY = baseKey;
}
public static URI getURI(String key) {
return URI.createURI(key.substring(6));
}
public boolean isResource(String key) {
return key.startsWith(BASE_KEY);
}
private Map createInputStreamResult(byte[] data) {
Map result = new HashMap();
Map response = new HashMap();
result.put(URIConverter.OPTION_RESPONSE, response);
response.put(URIConverter.RESPONSE_RESULT, new ByteArrayInputStream(data));
return result;
}
@Override
public void createInputStream(URI uri, Map, ?> options, Callback
© 2015 - 2025 Weber Informatics LLC | Privacy Policy