Java Code Examples for com.google.gwt.json.client.JSONValue#isObject()

The following examples show how to use com.google.gwt.json.client.JSONValue#isObject() . 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: WaitForBuildResultCommand.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private static String extractFormName(RpcResult result) {
  String extraString = result.getExtra();
  if (extraString != null) {
    JSONValue extraJSONValue = JSONParser.parseStrict(extraString);
    JSONObject extraJSONObject = extraJSONValue.isObject();
    if (extraJSONObject != null) {
      JSONValue formNameJSONValue = extraJSONObject.get("formName");
      if (formNameJSONValue != null) {
        JSONString formNameJSONString = formNameJSONValue.isString();
        if (formNameJSONString != null) {
          return formNameJSONString.stringValue();
        }
      }
    }
  }
  return "Screen1";
}
 
Example 2
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 3
Source File: GwtGadgetInfoParser.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private GadgetInfo parseGadgetInfo(JSONValue item) {
  JSONObject object = item.isObject();
  if (object != null) {
    String name = object.get("name").isString().stringValue();
    String desc = object.get("desc").isString().stringValue();
    GadgetCategoryType primaryCategory =
        GadgetCategoryType.of(object.get("primaryCategory").isString().stringValue());
    GadgetCategoryType secondaryCategory =
        GadgetCategoryType.of(object.get("secondaryCategory").isString().stringValue());
    String gadgetUrl = object.get("gadgetUrl").isString().stringValue();
    String author = object.get("author").isString().stringValue();
    String submittedBy = object.get("submittedBy").isString().stringValue();
    String imageUrl = object.get("imageUrl").isString().stringValue();

    return new GadgetInfo(name, desc, primaryCategory, secondaryCategory, gadgetUrl, author,
        submittedBy, imageUrl);
  }
  return null;
}
 
Example 4
Source File: GwtGadgetInfoParser.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private GadgetInfo parseGadgetInfo(JSONValue item) {
  JSONObject object = item.isObject();
  if (object != null) {
    String name = object.get("name").isString().stringValue();
    String desc = object.get("desc").isString().stringValue();
    GadgetCategoryType primaryCategory =
        GadgetCategoryType.of(object.get("primaryCategory").isString().stringValue());
    GadgetCategoryType secondaryCategory =
        GadgetCategoryType.of(object.get("secondaryCategory").isString().stringValue());
    String gadgetUrl = object.get("gadgetUrl").isString().stringValue();
    String author = object.get("author").isString().stringValue();
    String submittedBy = object.get("submittedBy").isString().stringValue();
    String imageUrl = object.get("imageUrl").isString().stringValue();

    return new GadgetInfo(name, desc, primaryCategory, secondaryCategory, gadgetUrl, author,
        submittedBy, imageUrl);
  }
  return null;
}
 
Example 5
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public BootstrapServer restoreSelection() {
    if (storage != null) {
        //noinspection MismatchedQueryAndUpdateOfCollection
        StorageMap storageMap = new StorageMap(storage);
        if (storageMap.containsKey(KEY)) {
            String json = storageMap.get(SELECTED);
            if (json != null) {
                JSONValue jsonValue = JSONParser.parseStrict(json);
                if (jsonValue != null) {
                    JSONObject jsonObject = jsonValue.isObject();
                    if (jsonObject != null) {
                        AutoBean<BootstrapServer> bean = AutoBeanCodex
                                .decode(factory, BootstrapServer.class, jsonObject.toString());
                        return bean.as();
                    }
                }
            }
        }
    }
    return null;
}
 
Example 6
Source File: UploadResponse.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private String extractFailure(final JSONObject response) {
    String failure = "n/a";
    JSONValue failureValue = response.get(FAILURE_DESCRIPTION);
    if (failureValue.isString() != null) {
        failure = failureValue.isString().stringValue();
    } else if (failureValue.isObject() != null) {
        JSONObject failureObject = failureValue.isObject();
        for (String key : failureObject.keySet()) {
            if (key.contains("failure") && failureObject.get(key).isString() != null) {
                failure = failureObject.get(key).isString().stringValue();
                break;
            }
        }
    }
    return failure;
}
 
Example 7
Source File: TemplateUploadWizard.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of Template objects containing data needed
 *  to load a template from a zip file. Each non-null template object
 *  is created from its Json string
 *
 * @return ArrayList of TemplateInfo objects
 */
protected static ArrayList<TemplateInfo> getTemplates() {
  JSONValue jsonVal = JSONParser.parseLenient(templateDataString);
  JSONArray jsonArr = jsonVal.isArray();
  ArrayList<TemplateInfo> templates = new ArrayList<TemplateInfo>();
  for (int i = 0; i < jsonArr.size(); i++) {
    JSONValue value = jsonArr.get(i);
    JSONObject obj = value.isObject();
    if (obj != null)
      templates.add(new TemplateInfo(obj)); // Create TemplateInfo from Json
  }
  return templates;
}
 
Example 8
Source File: GWTFileUploadResponse.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * GWTFileUploadResponse
 *
 * @param text json encoded parameters.
 */
public GWTFileUploadResponse(String text) {
	text = text.substring(text.indexOf("{"));
	text = text.substring(0, text.lastIndexOf("}") + 1);
	JSONValue responseValue = JSONParser.parseStrict(text);
	JSONObject response = responseValue.isObject();

	// Deserialize information
	hasAutomation = response.get("hasAutomation").isBoolean().booleanValue();
	path = URL.decodeQueryString(response.get("path").isString().stringValue());
	error = response.get("error").isString().stringValue();
	showWizardCategories = response.get("showWizardCategories").isBoolean().booleanValue();
	showWizardKeywords = response.get("showWizardKeywords").isBoolean().booleanValue();
	digitalSignature = response.get("digitalSignature").isBoolean().booleanValue();

	// Getting property groups
	JSONArray groupsArray = response.get("groupsList").isArray();

	if (groupsArray != null) {
		for (int i = 0; i <= groupsArray.size() - 1; i++) {
			groupsList.add(groupsArray.get(i).isString().stringValue());
		}
	}

	// Getting workflows
	JSONArray workflowArray = response.get("workflowList").isArray();

	if (workflowArray != null) {
		for (int i = 0; i <= workflowArray.size() - 1; i++) {
			workflowList.add(workflowArray.get(i).isString().stringValue());
		}
	}
}
 
Example 9
Source File: ErrorHandler.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Creates response object from JSON response string in
     * {@link com.smartgwt.client.data.RestDataSource SmartGWT format}.
     * @param response JSON response string
     * @return response object
     */
    public static DSResponse getDsResponse(String response) {
        DSResponse dsResponse;
//        ClientUtils.info(LOG, "response: %s", response);
        if (response == null || response.isEmpty()) {
            // not JSON response
            LOG.log(Level.WARNING, null, new IllegalStateException("Empty response!"));
            dsResponse = new DSResponse();
            dsResponse.setStatus(RPCResponse.STATUS_SUCCESS);
        } else {
            JSONValue rVal = JSONParser.parseStrict(response);
            if (rVal.isObject() != null) {
                rVal = rVal.isObject().get("response");
            }
            if (rVal != null && rVal.isObject() != null) {
                JSONObject rObj = rVal.isObject();
                dsResponse = DSResponse.getOrCreateRef(rObj.getJavaScriptObject());
            } else {
                // not JSON response in expected format
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("data", new JSONString(response));
                dsResponse = new DSResponse(jsonObject.getJavaScriptObject());
                dsResponse.setStatus(RPCResponse.STATUS_FAILURE);
            }
        }
        return dsResponse;
    }
 
Example 10
Source File: Project.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
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);
	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);	           
        }
	
	}
}
 
Example 11
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 12
Source File: LoadCompatMatrix.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(Control<BootstrapContext> control) {

    TextResource compat = TextResources.INSTANCE.compat();
    JSONValue root = JSONParser.parseLenient(compat.getText());
    JSONObject versionList = root.isObject();
    Set<String> keys = versionList.keySet();
    for (String key : keys) {
        modelVersions.put(key, versionList.get(key).isString().stringValue());
    }

    System.out.println("Build against Core Model Version: " + modelVersions.get("core-version"));
    control.proceed();
}
 
Example 13
Source File: JsonTokenizer.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
public static JSONObject parseObject(String token) {
    JSONValue val = parse(token);
    return val == null ? null : val.isObject();
}
 
Example 14
Source File: GadgetMetadata.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to extract a JSONObject from a JSONValue if it exists.
 *
 * @param json JSON object to extract the value from.
 * @param key key of the value to extract.
 * @return the JSONObject if it exists.
 */
private static JSONObject getJsonObjectValue(JSONObject json, String key) {
  JSONValue value = json.get(key);
  return (value != null) ? value.isObject() : null;
}
 
Example 15
Source File: GadgetMetadata.java    From incubator-retired-wave with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to extract a JSONObject from a JSONValue if it exists.
 *
 * @param json JSON object to extract the value from.
 * @param key key of the value to extract.
 * @return the JSONObject if it exists.
 */
private static JSONObject getJsonObjectValue(JSONObject json, String key) {
  JSONValue value = json.get(key);
  return (value != null) ? value.isObject() : null;
}