Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:org.geowe.client.local.main.tool.project.Project.java

License:Open Source License

public Project(String json) {
    final JSONValue jsonValue = JSONParser.parseLenient(json);
    final JSONObject jsonObject = jsonValue.isObject();

    String projectDate = jsonObject.get(DATE_NAME).isString().stringValue();
    String projectTitle = jsonObject.get(TITLE_NAME).isString().stringValue();
    String projectVersion = jsonObject.get(VERSION_NAME).isString().stringValue();
    String projectDescription = jsonObject.get(DESCRIPTION_NAME).isString().stringValue();

    setDate(projectDate);// w ww  .  ja  v a  2s. co m
    setTitle(projectTitle);
    setVersion(projectVersion);
    setDescription(projectDescription);

    JSONArray layersArray = jsonObject.get(VECTORS_NAME).isArray();

    if (layersArray != null) {
        for (int i = 0; i < layersArray.size(); i++) {
            JSONObject projectLayerObj = layersArray.get(i).isObject();
            String name = projectLayerObj.get(NAME).isString().stringValue();
            String content = projectLayerObj.get(CONTENT_NAME).isString().stringValue();
            JSONObject styleProjectLayer = projectLayerObj.get(STYLE_NAME).isObject();

            String fillColor = styleProjectLayer.get(ProjectLayerStyle.FILL_COLOR_NAME).isString()
                    .stringValue();
            Double fillOpacity = styleProjectLayer.get(ProjectLayerStyle.FILL_OPACITY_NAME).isNumber()
                    .doubleValue();
            String strokeColor = styleProjectLayer.get(ProjectLayerStyle.STROKE_COLOR_NAME).isString()
                    .stringValue();
            Double strokeWidth = styleProjectLayer.get(ProjectLayerStyle.STROKE_WIDTH_NAME).isNumber()
                    .doubleValue();

            add(name, content, fillColor, fillOpacity, strokeColor, strokeWidth);
        }

    }
}

From source file:org.geowe.client.local.model.style.LeafletStyle.java

License:Open Source License

public static ProjectLayerStyle getStyle(String geoJSONCSS) {
    ProjectLayerStyle style = null;/* w  ww.j av  a 2 s .  c  o  m*/
    final JSONValue jsonValue = JSONParser.parseLenient(geoJSONCSS);
    final JSONObject geoJSONCssObject = jsonValue.isObject();

    if (geoJSONCssObject.containsKey(GeoJSONCSS.STYLE_NAME)) {

        JSONObject styleObject = geoJSONCssObject.get(GeoJSONCSS.STYLE_NAME).isObject();

        String fillColor = getStringValue(styleObject, FILL_COLOR_NAME);
        Double fillOpacity = getDoubleValue(styleObject, FILL_OPACITY_NAME);
        if (fillOpacity == null) {
            fillOpacity = getDoubleValue(styleObject, FILL_OPACITY2_NAME);
        }
        String strokeColor = getStringValue(styleObject, STROKE_COLOR_NAME);
        Double strokeWidth = getDoubleValue(styleObject, STROKE_WIDTH_NAME);

        style = new ProjectLayerStyle(fillColor, fillOpacity, strokeColor, strokeWidth);
    }

    return style;
}

From source file:org.geowe.client.local.model.vector.format.GeoJSONCSS.java

License:Open Source License

public String write(VectorFeature[] vectorFeatures) {
    String json = "";
    VectorStyleDef vectorStyleDef = layer.getVectorStyle();

    if (vectorStyleDef.isColorThemingEnabled()) {

        FeatureAttributeDef attributeDef = vectorStyleDef.getColorThemingAttribute();
        String attributeName = attributeDef.getName();

        for (VectorFeature vf : vectorFeatures) {
            String value = vf.getAttributes().getAttributeAsString(attributeName);
            String color = StyleFactory.stringToColour(value);
            vectorStyleDef.getFill().setNormalColor(color);
            vectorStyleDef.getLine().setNormalColor(color);
            vf.getJSObject().setProperty(STYLE_NAME, LeafletStyle.getStyle(vectorStyleDef));
        }//from ww w. jav a  2  s. c om

        json = super.write(vectorFeatures);

    } else {
        for (VectorFeature vf : vectorFeatures) {
            Style style = vf.getStyle();
            if (style != null) {
                VectorFeatureStyleDef def = new VectorFeatureStyleDef(vf, layer);
                vf.getJSObject().setProperty(STYLE_NAME, LeafletStyle.getStyle(def));
            }
        }

        String geojson = super.write(vectorFeatures);

        final JSONValue jsonValue = JSONParser.parseLenient(geojson);
        final JSONObject geoJSONCssObject = jsonValue.isObject();

        geoJSONCssObject.put(STYLE_NAME, new JSONObject(LeafletStyle.getStyle(vectorStyleDef)));

        json = geoJSONCssObject.toString();
    }

    return json;
}

From source file:org.geowe.client.local.model.vector.format.GeoJSONCSS.java

License:Open Source License

public VectorStyleDef getLayerStyle(String vectorFormatString) {
    VectorFeatureStyleDef def = null;//from  ww  w. j  av  a2  s .  com

    final JSONValue jsonValue = JSONParser.parseLenient(vectorFormatString);
    final JSONObject geoJSONCssObject = jsonValue.isObject();

    if (geoJSONCssObject.containsKey(GeoJSONCSS.STYLE_NAME)) {

        JSONObject styleObject = geoJSONCssObject.get(GeoJSONCSS.STYLE_NAME).isObject();
        JSObject styleJSObject = styleObject.getJavaScriptObject().cast();
        def = getStyleDef(styleJSObject);
    }

    return def;
}

From source file:org.gk.engine.client.utils.StringUtils.java

License:Open Source License

/**
 * ??jsonEventObject/*from   w w  w .j  a v  a 2 s.c  o m*/
 * 
 * @param eventId
 * @param jsonString
 * @return EventObject
 */
public static EventObject toEventObject(String eventId, String jsonString) {
    JSONValue val = JSONParser.parseLenient(jsonString);
    EventObject eo = null;
    if (jsonString.startsWith("{")) {
        eo = new EventObject(eventId, JsonConvert.jsonToMap(val.isObject()));
    } else if (jsonString.startsWith("[")) {
        eo = new EventObject(eventId, JsonConvert.jsonToList(val.isArray()));
    } else {
        eo = new EventObject(eventId, jsonString);
    }
    return eo;
}

From source file:org.gwm.splice.client.service.json.JSONSerializer.java

License:Apache License

private Object convertValue(JSONValue val) {
    if (val.isBoolean() != null) {
        return new Boolean(val.isBoolean().booleanValue());
    } else if (val.isNumber() != null) {
        return new Double(val.isNumber().getValue());
    } else if (val.isString() != null) {
        return val.isString().stringValue();
    } else if (val.isObject() != null) {
        Attributes attrs = new Attributes();
        convertAttributes(val.isObject(), attrs);
        return attrs;
    } else if (val.isArray() != null) {
        JSONArray ja = val.isArray();
        Object[] array = new Object[ja.size()];
        for (int i = 0; i < ja.size(); i++) {
            array[i] = convertValue(ja.get(i));
        }//from   www  .j  a  va  2 s .c  o  m
        return array;
    }
    return null;
}

From source file:org.gwt.dynamic.common.client.util.JsonHelper.java

License:MIT License

public static <T> T fromJsonBean(Class<T> beanClass, String json) {
    JSONValue value = JSONParser.parseStrict(json);
    return getReaderForBean(beanClass).read(value.isObject());
}

From source file:org.gwt.dynamic.common.client.util.JsonHelper.java

License:MIT License

public static <T> T fromJsonBean(Class<T> beanClass, JSONValue json) {
    if (json == null)
        throw new NullPointerException();
    return getReaderForBean(beanClass).read(json.isObject());
}

From source file:org.gwt.json.serialization.client.utils.JsonHashMapSerializer.java

License:Apache License

@Override
public HashMap deSerialize(JSONValue jsonObj, GenericType[] genericTypes) throws JSONException {
    if (jsonObj == null || jsonObj.isObject() == null)
        return null;
    HashMap obj = new HashMap();
    GenericType keyType = genericTypes[0];
    GenericType valueType = genericTypes[1];
    JSONObject mapObject = jsonObj.isObject();
    for (String key : mapObject.keySet()) {
        //well, key is always String, in this case...
        obj.put(key, serializer.getSerializerForType(valueType.getName()).deSerialize(mapObject.get(key),
                valueType.getTypes()));/*ww  w. j  ava  2 s .c o  m*/
    }
    return obj;
}

From source file:org.gwt.json.serialization.client.utils.JsonMapSerializer.java

License:Apache License

@Override
public Map deSerialize(JSONValue jsonObj, GenericType[] genericTypes) throws JSONException {
    if (jsonObj == null || jsonObj.isObject() == null)
        return null;
    Map obj = new HashMap();
    GenericType keyType = genericTypes[0];
    GenericType valueType = genericTypes[1];
    JSONObject mapObject = jsonObj.isObject();
    for (String key : mapObject.keySet()) {
        //well, key is always String, in this case...
        obj.put(key, serializer.getSerializerForType(valueType.getName()).deSerialize(mapObject.get(key),
                valueType.getTypes()));/* w  w  w  .j  a v  a  2s.c  om*/
    }
    return obj;
}