List of usage examples for com.google.gwt.json.client JSONValue isString
public JSONString isString()
From source file:fast.servicescreen.client.gui.RuleUtil.java
License:Open Source License
/** * Recursive method for retrieving all jsonvalues for a specified tagName * *//* w w w . j a v a2 s .c o m*/ public static void jsonValuesByTagName(JSONArray elements, JSONValue root, String tagName) { //if object search on first layer. on failure begin depth-search JSONObject object = root.isObject(); if (object != null) { //get (first layer) keys contained in the JSONValue Set<String> keys = object.keySet(); //seek on first layer for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); //found - add it and stop if (key.equals(tagName)) { int index = elements.size(); elements.set(index, object.get(key)); //stop - key can occur only once on first layer break; } //nothing found - depth-search else { jsonValuesByTagName(elements, object.get(key), tagName); } } } //if it's an array, search among it's children by calling recursive method //for every child JSONArray jsonArray = root.isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { jsonValuesByTagName(elements, jsonArray.get(i), tagName); } } //if it's a matching boolean, number or string: add it JSONBoolean jsonBoolean = root.isBoolean(); if (jsonBoolean != null && tagName.equals(jsonBoolean.booleanValue())) { int index = elements.size(); elements.set(index, jsonBoolean); } JSONNumber jsonNumber = root.isNumber(); if (jsonNumber != null && tagName.equals(jsonNumber.doubleValue())) { int index = elements.size(); elements.set(index, jsonNumber); } JSONString jsonString = root.isString(); if (jsonString != null && tagName.equals(jsonString.stringValue())) { int index = elements.size(); elements.set(index, jsonString); } }
From source file:fast.servicescreen.client.gui.RuleUtil.java
License:Open Source License
/** * Returns the String value of given JSONValue, or "" if * value was emtpy//from w w w . ja v a 2 s. co m * */ public static String getJSONValue_AsString(JSONValue jsonValue) { if (jsonValue != null) { //Define JSON valuetype. Get its sting value String nodeValue = ""; JSONBoolean attrBoolean = jsonValue.isBoolean(); JSONNumber attrNumber = jsonValue.isNumber(); JSONString attrString = jsonValue.isString(); if (attrBoolean != null) { nodeValue = "" + attrBoolean.booleanValue(); } else if (attrNumber != null) { nodeValue = "" + attrNumber.doubleValue(); } else if (attrString != null) { String stringValue = attrString.stringValue(); if (stringValue != null && !"".equals(stringValue.trim())) { nodeValue = "" + stringValue; } else { nodeValue = ""; } } return nodeValue; } return ""; }
From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.AnalysisPerspective.java
License:Open Source License
public void fromJSONObject(JSONObject o) { if (o != null) { JSONValue val = o.get("perspectiveTitle"); JSONString js = null;/*from w ww. j a va 2 s . c o m*/ perspectiveTitle = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveTitle = js.stringValue(); } } val = o.get("perspectiveQuestion"); perspectiveQuestion = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveQuestion = js.stringValue(); } } val = o.get("perspectiveSummary"); perspectiveSummary = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveSummary = js.stringValue(); } } val = o.get("arguments"); if (val != null) { JSONArray aa = val.isArray(); if (aa != null) { for (int i = 0; i < aa.size(); i++) { val = aa.get(i); JSONObject a = val.isObject(); if (a != null) { arguments.add(new Argument(a)); } } } } val = o.get("counterArguments"); if (val != null) { JSONArray caa = val.isArray(); if (caa != null) { for (int i = 0; i < caa.size(); i++) { val = caa.get(i); JSONObject ca = val.isObject(); if (ca != null) { counterArguments.add(new Argument(ca)); } } } } } }
From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.Argument.java
License:Open Source License
public void fromJSONObject(JSONObject o) { if (o != null) { JSONValue val = o.get("argument"); JSONString js = null;/*from w w w. jav a2 s. c om*/ argument = null; if (val != null) { js = val.isString(); if (js != null) { argument = js.stringValue(); } } val = o.get("sourceURL"); sourceURL = null; if (val != null) { js = val.isString(); if (js != null) { sourceURL = js.stringValue(); } } val = o.get("reliability"); reliability = null; if (val != null) { js = val.isString(); if (js != null) { String s = js.stringValue(); setIntReliabilityValue(Integer.parseInt(s)); } } val = o.get("reliabilityRationale"); reliabilityRationale = null; if (val != null) { js = val.isString(); if (js != null) { reliabilityRationale = js.stringValue(); } } val = o.get("counterArgument"); counterArgument = false; if (val != null) { JSONBoolean jb = val.isBoolean(); if (jb != null) { counterArgument = jb.booleanValue(); } } } }
From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.ClaimAnalysis.java
License:Open Source License
public void fromJSONObject(JSONObject obj) { reset();//from www . j a va 2 s .com JSONValue val = obj.get("claim"); JSONString js = null; if (val != null) { js = val.isString(); if (js != null) { claim = js.stringValue(); } } val = obj.get("conclusion"); if (val != null) { js = val.isString(); if (js != null) { conclusion = js.stringValue(); } } val = obj.get("perspectives"); if (val != null) { JSONArray pa = val.isArray(); if (pa != null) { for (int i = 0; i < pa.size(); i++) { val = pa.get(i); JSONObject pe = val.isObject(); if (pe != null) { perspectives.add(new AnalysisPerspective(pe)); } } } } }
From source file:fr.insalyon.creatis.vip.applicationimporter.client.JSONUtil.java
License:Open Source License
public static String getPropertyAsString(JSONObject jo, String property, String valueIfAbsent) throws ApplicationImporterException { JSONValue value = jo.get(property); if (value == null) return valueIfAbsent; if (value.isString() == null) return value.toString(); return value.isString().stringValue(); }
From source file:gov.nist.spectrumbrowser.admin.JSONViewer.java
License:Open Source License
private TreeItem populate(TreeItem root, JSONObject jsonObject) { Set<String> keySet = jsonObject.keySet(); for (String key : keySet) { JSONValue jsonValue = jsonObject.get(key); JSONString jsonString = jsonValue.isString(); JSONNumber jsonNumber = jsonValue.isNumber(); TreeItem treeItem = root.addTextItem(key); if (jsonString != null) { String stringValue = jsonString.stringValue(); treeItem.addTextItem(stringValue); } else if (jsonNumber != null) { String stringValue = Double.toString(jsonNumber.doubleValue()); treeItem.addTextItem(stringValue); } else if (jsonValue.isObject() != null) { populate(treeItem, jsonValue.isObject()); }//from w ww . j av a 2s .c om } return root; }
From source file:gov.nist.spectrumbrowser.client.JSONViewer.java
License:Open Source License
private void populate(TreeItem root, JSONObject jsonObject) { Set<String> keySet = jsonObject.keySet(); for (String key : keySet) { JSONValue jsonValue = jsonObject.get(key); JSONString jsonString = jsonValue.isString(); JSONNumber jsonNumber = jsonValue.isNumber(); TreeItem treeItem = root.addTextItem(key); if (jsonString != null) { String stringValue = jsonString.stringValue(); treeItem.addTextItem(stringValue); } else if (jsonNumber != null) { String stringValue = Double.toString(jsonNumber.doubleValue()); treeItem.addTextItem(stringValue); } else if (jsonValue.isObject() != null) { populate(treeItem, jsonValue.isObject()); }/* w ww . j a va2s.c o m*/ } }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static void getNameInfo(JSONObject jsNameObj, Map<LanguageCode, String> res) { JSONValue jsLang = jsNameObj.get("@LanguageCode"); JSONString jsLangStr = jsLang.isString(); JSONValue jsNameVal = jsNameObj.get("$"); JSONString jsNameStr = jsNameVal.isString(); res.put(LanguageCode.valueOf(jsLangStr.toString().replace("\"", "").toUpperCase()), jsNameStr.toString().replace("\"", "")); }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static Airport getAirportInfo(JSONObject jsAirportObj) { JSONValue jsAirportCodeVal = jsAirportObj.get("AirportCode"); JSONValue jsCityCodeVal = jsAirportObj.get("CityCode"); JSONValue jsCountryCodeVal = jsAirportObj.get("CountryCode"); JSONValue jsLocationTypeVal = jsAirportObj.get("LocationType"); if (jsAirportCodeVal == null || jsCityCodeVal == null || jsCountryCodeVal == null || jsLocationTypeVal == null) { return null; }//from w w w.ja va2 s . c o m JSONString jsAirportCodeStr = jsAirportCodeVal.isString(); JSONString jsCityCodeStr = jsCityCodeVal.isString(); JSONString jsCountryCodeStr = jsCountryCodeVal.isString(); JSONString jsLocationTypeStr = jsLocationTypeVal.isString(); JSONObject jsCoordinateObj = jsAirportObj.get("Position").isObject().get("Coordinate").isObject(); JSONNumber jsLatitudeNum = jsCoordinateObj.get("Latitude").isNumber(); JSONNumber jsLongitudeNum = jsCoordinateObj.get("Longitude").isNumber(); JSONObject jsNamesObj = jsAirportObj.get("Names").isObject(); return new Airport((jsAirportCodeStr == null) ? ("") : (jsAirportCodeStr.toString().replace("\"", "")), (jsCityCodeStr == null) ? ("") : (jsCityCodeStr.toString().replace("\"", "")), (jsCountryCodeStr == null) ? ("") : (jsCountryCodeStr.toString().replace("\"", "")), (jsLocationTypeStr == null) ? ("") : (jsLocationTypeStr.toString().replace("\"", "")), jsLatitudeNum.doubleValue(), jsLongitudeNum.doubleValue(), JsonParserUtils.getNamesMap(jsNamesObj)); }