Java Code Examples for com.google.gwt.json.client.JSONObject#containsKey()

The following examples show how to use com.google.gwt.json.client.JSONObject#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeafletStyle.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
public static ProjectLayerStyle getStyle(String geoJSONCSS) {
	ProjectLayerStyle style = null;
	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;
}
 
Example 2
Source File: Application.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
private static TimeseriesRenderingOptions createRenderingOptions(String options) {
    if (options == null) {
        return new TimeseriesRenderingOptions();
    }
    TimeseriesRenderingOptions tsOptions = new TimeseriesRenderingOptions();
    JSONObject tsRenderingOptions = new JSONObject(parseUntrustedJson(options));
    if (tsRenderingOptions.containsKey("color")) {
        JSONString color = tsRenderingOptions.get("color").isString();
        tsOptions.setColor(color.stringValue());
    }
    if (tsRenderingOptions.containsKey("lineWidth")) {
        JSONNumber lineWidth = tsRenderingOptions.get("lineWidth").isNumber();
        tsOptions.setLineWidth((int)lineWidth.doubleValue());
    }
    return tsOptions;
}
 
Example 3
Source File: LeafletStyle.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private static String getStringValue(JSONObject styleObject, String key) {
	String newValue = "";

	if (styleObject.containsKey(key)) {
		try {
			newValue = styleObject.get(key).isString().stringValue();
		} catch (Exception e) {
			// si el valor del atributo no está bien definido es ignorado
		}
	}

	return newValue;

}
 
Example 4
Source File: LeafletStyle.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private static Double getDoubleValue(JSONObject styleObject, String key) {
	Double newValue = null;

	if (styleObject.containsKey(key)) {
		try {
			newValue = styleObject.get(key).isNumber().doubleValue();
		} catch (Exception e) {
			// si el valor del atributo no está bien definido es ignorado
		}
	}

	return newValue;
}
 
Example 5
Source File: GeoJSONCSS.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
public VectorStyleDef getLayerStyle(String vectorFormatString) {
	VectorFeatureStyleDef def = null;
	
	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;
}
 
Example 6
Source File: UploadResponse.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode get() {
    ModelNode node;
    if (contentType.startsWith(APPLICATION_DMR_ENCODED)) {
        node = ModelNode.fromBase64(payload);
    } else if (contentType.startsWith(APPLICATION_JSON)) {
        node = new ModelNode();
        JSONObject response = JSONParser.parseLenient(payload).isObject();
        JSONString outcome = response.get(OUTCOME).isString();
        node.get(OUTCOME).set(outcome.stringValue());
        if (outcome.stringValue().equals(SUCCESS)) {
            if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) {
                node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2));
            } else {
                node.get(RESULT).set(new ModelNode());
            }
        } else {
            String failure = extractFailure(response);
            node.get(FAILURE_DESCRIPTION).set(failure);
        }
    } else {
        node = new ModelNode();
        node.get(OUTCOME).set(FAILED);
        node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType);
    }
    return node;
}
 
Example 7
Source File: SubsetJSONPropertyEditor.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
private void loadComponents(JSONObject jsonObj) {
  // TODO: Review JSON format. There has to be a better way to store and retrieve this info.
  JSONObject shownComponents = jsonObj.get("shownComponentTypes").isObject();
  JSONObject shownComponentBlocks = jsonObj.get("shownBlockTypes").isObject().get("ComponentBlocks").isObject();
  for (int i = 0; i < componentTree.getItemCount(); ++i) {
    TreeItem componentCatItem = componentTree.getItem(i);
    CheckBox componentCatCb = (CheckBox)componentCatItem.getWidget();
    String catName = componentCatCb.getName().toUpperCase();
    if (shownComponents.containsKey(catName)) {
      JSONArray jsonComponentCat = shownComponents.get(catName).isArray();
      if (jsonComponentCat.size() > 0) {
        componentCatCb.setValue(true, false);
        HashMap<String, String> jsonComponentHash = new HashMap<String, String>();
        for (int j = 0; j < jsonComponentCat.size(); ++j) {
          JSONValue jsonComponentHashCat = jsonComponentCat.get(j);
          if (jsonComponentHashCat != null) {
            jsonComponentHash.put(jsonComponentHashCat.isObject().get("type").isString().stringValue(), "type");
          }
        }
        for (int j = 0; j < componentCatItem.getChildCount(); ++j) {
          TreeItem componentItem = componentCatItem.getChild(j);
          CheckBox componentCb = (CheckBox) componentItem.getWidget();
          if (jsonComponentHash.get(componentCb.getName()) != null) {
            componentCb.setValue(true, false);
            JSONArray jsonComponentBlockProps = shownComponentBlocks.get(componentCb.getName()).isArray();
            HashMap<String, String> componentPropHash = new HashMap<String, String>();
            for (int k = 0; k < jsonComponentBlockProps.size(); ++k) {
              JSONObject jsonComponentBlockType = jsonComponentBlockProps.get(k).isObject();
              String componentBlockType = jsonComponentBlockType.get("type").isString().stringValue();
              if ("component_set_get".equals(componentBlockType)) {
                componentPropHash.put(jsonComponentBlockType.get("mutatorNameToValue").isObject().get("property_name").isString().stringValue(), "PROP");
              } else if ("component_event".equals(componentBlockType)) {
                JSONValue mutatorValue = jsonComponentBlockType.get("mutatorNameToValue");
                JSONValue event_name = mutatorValue.isObject().get("event_name");
                componentPropHash.put(event_name.isString().stringValue(), "EVENT");
              } else if ("component_method".equals(componentBlockType)) {
                componentPropHash.put(jsonComponentBlockType.get("mutatorNameToValue").isObject().get("method_name").isString().stringValue(), "METHOD");
              }
            }
            for (int k = 0; k < componentItem.getChildCount(); ++k) {
              TreeItem componentPropItem = componentItem.getChild(k);
              CheckBox componentPropCb = (CheckBox) componentPropItem.getWidget();
              if (componentPropHash.get(componentPropCb.getText()) != null) {
                componentPropCb.setValue(true, false);
              } else {
                componentPropCb.setValue(false, false);
              }
            }

          } else {
            componentCb.setValue(false, false);
            toggleChildren(componentItem, false);
          }
        }
      } else {
        componentCatCb.setValue(false, false);
        toggleChildren(componentCatItem, false);
      }
    } else {
      componentCatCb.setValue(false, false);
      toggleChildren(componentCatItem, false);
    }
  }
}