List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:com.codenvy.ide.ext.java.jdt.internal.compiler.parser.Parser.java
License:Open Source License
private static String[] parseJsonArray(JSONValue value) { if (value.isObject() != null) { value = value.isObject().get("rsc").isArray(); }/*w ww . j av a 2 s . co m*/ if (value.isArray() == null) throw new IllegalArgumentException("'json' parameter must represent a JSON array"); JSONArray array = value.isArray(); String result[] = new String[array.size()]; for (int i = 0; i < array.size(); i++) { result[i] = array.get(i).isNull() == null ? array.get(i).isString().stringValue() : null; } return result; }
From source file:com.data2semantics.yasgui.client.helpers.CallableJsMethods.java
License:Open Source License
public void storeCompletionMethodsInSettings(String methodsJsonString, String type) { JSONValue jsonVal = JSONParser.parseStrict(methodsJsonString); if (jsonVal != null && jsonVal.isObject() != null) { if (type.equals("property")) { view.getSettings().setPropertyCompletionMethods(jsonVal.isObject()); } else if (type.equals("class")) { view.getSettings().setClassCompletionMethods(jsonVal.isObject()); }/*from ww w . j a v a 2 s . c o m*/ LocalStorageHelper.storeSettings(view.getSettings()); } }
From source file:com.data2semantics.yasgui.client.settings.Settings.java
License:Open Source License
public void addToSettings(String jsonString) throws IOException { JSONValue jsonVal = JSONParser.parseStrict(jsonString); if (jsonVal != null) { JSONObject jsonObject = jsonVal.isObject(); if (jsonObject != null) { addToSettings(jsonObject);/*from w ww . j av a2 s . co m*/ } else { throw new IOException("Unable to convert json value to json object"); } } else { throw new IOException("Unable to parse json settings string"); } }
From source file:com.data2semantics.yasgui.client.tab.optionbar.endpoints.EndpointDataSource.java
License:Open Source License
public void addEndpointsFromJson(String jsonString) throws Exception { JSONValue jsonVal = JSONParser.parseStrict(jsonString); if (jsonVal != null) { JSONArray endpoints = jsonVal.isArray(); if (endpoints != null) { for (int i = 0; i < endpoints.size(); i++) { JSONValue endpointVal = endpoints.get(i); if (endpointVal != null) { JSONObject endpoint = endpointVal.isObject(); if (endpoint != null) { addEndpointFromJson(endpoint); }// w ww .j a v a 2 s . c o m } } } } setCacheData(records.toArray(new ListGridRecord[records.size()])); }
From source file:com.data2semantics.yasgui.client.tab.results.input.JsonResults.java
License:Open Source License
/** * Main parser method//from www . j a v a 2 s . co m * @param jsonString Json string to parse * @throws SparqlParseException When json string is not valid * @throws SparqlEmptyException When json string is valid, but contains no results */ public void processResults(String jsonString) throws SparqlParseException, SparqlEmptyException { if (jsonString == null || jsonString.length() == 0) { throw new SparqlParseException("Unable to parse empty JSON string"); } JSONValue jsonValue = JSONParser.parseStrict(jsonString); //no need for this anymore, and it can be quite big. Fingers crossed and hope garbage collector deals witht this properly jsonString = null; if (jsonValue == null) { throw new SparqlParseException("Unable to parse query json string"); } JSONObject queryResult = jsonValue.isObject(); if (queryResult == null) throw new SparqlParseException("Unable to parse query json string"); if (queryMode == ResultContainer.RESULT_TYPE_TABLE) { storeVariables(queryResult); storeBindings(queryResult); } else if (queryMode == ResultContainer.RESULT_TYPE_BOOLEAN) { storeBooleanResult(queryResult); } }
From source file:com.data2semantics.yasgui.client.tab.results.input.JsonResults.java
License:Open Source License
/** * Gets JSON value as object, and throws exception when value is null * //from ww w . ja v a 2s .c om * @param jsonValue * @return * @throws SparqlParseException */ public JSONObject getAsObject(JSONValue jsonValue) throws SparqlParseException { if (jsonValue == null) { throw new SparqlParseException("Unable to get as object"); } JSONObject result = jsonValue.isObject(); if (result == null) { throw new SparqlParseException("Unable to get as object"); } return result; }
From source file:com.data2semantics.yasgui.client.tab.results.ResultContainer.java
License:Open Source License
public int detectContentType(String responseString) { int contentType = 0; try {/*w w w .ja v a 2 s .c om*/ JSONValue jsonValue = JSONParser.parseStrict(responseString); if (jsonValue != null) { JSONObject jsonObject = jsonValue.isObject(); JSONValue head = jsonObject.get("head"); if (head != null) { return CONTENT_TYPE_JSON; } } } catch (Exception e) { } try { Document xmlDoc = XMLParser.parse(responseString); if (xmlDoc != null && xmlDoc.getElementsByTagName("sparql").getLength() > 0) { return CONTENT_TYPE_XML; } } catch (Exception e) { } return contentType; }
From source file:com.dawg6.web.dhcalc.client.JsonUtil.java
License:Open Source License
public static FormData parseFormData(String text) { FormData data = new FormData(); if ((text != null) && (text.trim().length() > 0)) { try {/* ww w . ja va 2 s. co m*/ JSONValue value = JSONParser.parseLenient(text); if (value != null) { JSONObject obj = value.isObject(); if (obj != null) { data.version = JsonUtil.parseVersion(obj.get("version")); data.main = JsonUtil.parseMap(obj.get("main")); data.calculator = JsonUtil.parseMap(obj.get("calculator")); data.items = JsonUtil.parseMap(obj.get("items")); data.passives = JsonUtil.parseMap(obj.get("passives")); data.gems = JsonUtil.parseMap(obj.get("gems")); data.specialItems = JsonUtil.parseMap(obj.get("equipment")); data.skills = JsonUtil.parseMap(obj.get("skills")); data.elementalDamage = JsonUtil.parseMap(obj.get("elementalDamage")); data.skillDamage = JsonUtil.parseMap(obj.get("skillDamage")); data.hero = null; data.career = null; } } } catch (Exception e) { ApplicationPanel.showErrorDialog("Error Parsing Form Data"); GWT.log("Error Parsing JSON Data", e); } } return data; }
From source file:com.dawg6.web.dhcalc.client.JsonUtil.java
License:Open Source License
public static Map<String, String> parseMap(JSONValue jsonValue) { JSONObject obj = jsonValue.isObject(); Map<String, String> map = new TreeMap<String, String>(); if (obj != null) { for (String key : obj.keySet()) { JSONValue value = obj.get(key); if (value != null) { JSONString str = value.isString(); if (str != null) { map.put(key, str.stringValue()); }//from w ww .j av a 2 s.com } } } return map; }
From source file:com.dawg6.web.dhcalc.client.JsonUtil.java
License:Open Source License
public static Version parseVersion(JSONValue jsonValue) { JSONObject obj = jsonValue.isObject(); Version version = new Version(); if (obj != null) { JSONValue value = obj.get("version"); if (value != null) { JSONString str = value.isString(); if (str != null) { version.version = str.stringValue(); }//from w ww . java 2s .c om } } return version; }