Java Code Examples for com.google.gwt.json.client.JSONParser#parseStrict()

The following examples show how to use com.google.gwt.json.client.JSONParser#parseStrict() . 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: GwtGadgetInfoParser.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
  List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
  JSONValue value = JSONParser.parseStrict(json);
  JSONArray array = value.isArray();
  if (array != null) {
    for (int i = 0; i < array.size(); i++) {
      JSONValue item = array.get(i);
      GadgetInfo info = parseGadgetInfo(item);
      if (info != null) {
        gadgetList.add(info);
      }
    }
  }
  return gadgetList;
}
 
Example 3
Source File: GwtGadgetInfoParser.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
  List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
  JSONValue value = JSONParser.parseStrict(json);
  JSONArray array = value.isArray();
  if (array != null) {
    for (int i = 0; i < array.size(); i++) {
      JSONValue item = array.get(i);
      GadgetInfo info = parseGadgetInfo(item);
      if (info != null) {
        gadgetList.add(info);
      }
    }
  }
  return gadgetList;
}
 
Example 4
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List<BootstrapServer> load() {
    List<BootstrapServer> servers = new ArrayList<BootstrapServer>();
    if (storage != null) {
        //noinspection MismatchedQueryAndUpdateOfCollection
        StorageMap storageMap = new StorageMap(storage);
        if (storageMap.containsKey(KEY)) {
            String json = storageMap.get(KEY);
            if (json != null) {
                JSONValue jsonValue = JSONParser.parseStrict(json);
                if (jsonValue != null) {
                    JSONArray jsonArray = jsonValue.isArray();
                    if (jsonArray != null) {
                        for (int i = 0; i < jsonArray.size(); i++) {
                            AutoBean<BootstrapServer> bean = AutoBeanCodex
                                    .decode(factory, BootstrapServer.class, jsonArray.get(i).toString());
                            servers.add(bean.as());
                        }
                    }
                }
            }
        }
    }
    return servers;
}
 
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: 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 7
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 8
Source File: JsonTokenizer.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public static JSONValue parse(String token) {
    try {
        if (JsonUtils.safeToEval(token)) {
            JSONValue jsonv = JSONParser.parseStrict(token);
            return jsonv;
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, token, ex);
    }
    return null;
}
 
Example 9
Source File: BitcoinJSONViewer.java    From bitcoin-transaction-explorer with MIT License 3 votes vote down vote up
public void setValue(final String json) {
  final JSONValue tree = JSONParser.parseStrict(json);

  clear();

  display(2, this, tree);
}