List of usage examples for com.google.gwt.json.client JSONValue isNumber
public JSONNumber isNumber()
From source file:fast.servicescreen.client.rpc.ShareResourceHandler.java
License:Open Source License
public String share(BuildingBlock res) { final String resultString = ""; //url and header String url = gvsUrl + "buildingblock/resource"; final String cookie = "fastgvsid=" + Cookies.getCookie("fastgvsid"); final HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Cookie", cookie); //build operator String body = "buildingblock=" + buildResource(res); // Window.alert("Resource: " + body); //upload to GVS shResService = GWT.create(RequestService.class); shResService.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() { @Override//from w w w. j a v a 2 s .c o m public void onFailure(Throwable caught) { } @Override public void onSuccess(String result) { if (result != null && result != "-1") { JSONValue resourceVal = JSONParser.parse(result); JSONObject resourceObj = resourceVal.isObject(); JSONValue idVal = resourceObj.get("id"); JSONNumber idNum = idVal.isNumber(); String id = idNum.toString(); if (id != null) { String shareUrl = gvsUrl + "buildingblock/" + id + "/sharing"; shResService.sendHttpRequest_POST(shareUrl, headers, "", new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { //Resource couldn't be shared System.out.println("Resource couldn't be shared" + caught.getMessage()); } @Override public void onSuccess(String result) { //Resource was shared System.out.println("Resource was shared: " + result); } }); } } } }); return resultString; }
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 ww w . j a v a 2 s .c o m*/ } 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 w w . j a v a 2s .c om } }
From source file:it.appify.geolocation.WsGeolocation.java
License:Open Source License
protected void onPositionSuccess(JavaScriptObject jsObj) { JSONObject obj = new JSONObject(jsObj); long timestamp = Long.parseLong("" + obj.get("timestamp").isNumber().doubleValue()); double latitude = obj.get("coords").isObject().get("latitude").isNumber().doubleValue(); double longitude = obj.get("coords").isObject().get("longitude").isNumber().doubleValue(); JSONValue jsValue = obj.get("coords").isObject().get("accuracy"); double accuracy = jsValue != null ? jsValue.isNumber().doubleValue() : 0; Geoposition positionObj = new Geoposition(); positionObj.setTimestamp(timestamp); Coordinates coords = new Coordinates(); coords.setLatitude(latitude);/*www . ja v a 2 s. c om*/ coords.setLongitude(longitude); coords.setAccuracy((int) accuracy); positionObj.setCoords(coords); if (this.callback != null) { lastPosition = positionObj; this.callback.onPosition(positionObj); } }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static String getAircraftCode(JSONValue jsAircraftCodeVal) { if (jsAircraftCodeVal == null) { return null; }/*from w w w. j a v a2s. c o m*/ JSONString jsAircraftCodeStr = jsAircraftCodeVal.isString(); JSONNumber jsAircraftCodeNum = null; if (jsAircraftCodeStr == null) { jsAircraftCodeNum = jsAircraftCodeVal.isNumber(); } return (jsAircraftCodeStr != null) ? (jsAircraftCodeStr.toString().replace("\"", "")) : ((jsAircraftCodeNum != null) ? (String.valueOf(jsAircraftCodeNum.doubleValue())) : ("")); }
From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java
License:Apache License
private static JSONNumber getNumberIfExist(JSONObject jsObj, String object, String property) { JSONValue jsObjectVal = jsObj.get(object); JSONNumber jsNum = null;//from www . j a v a 2 s .c o m if (jsObjectVal != null) { JSONValue jsObjectPropVal = jsObjectVal.isObject().get(property); if (jsObjectPropVal != null) { jsNum = jsObjectPropVal.isNumber(); } } return jsNum; }
From source file:net.opentsdb.tsd.client.QueryUi.java
License:Open Source License
private void refreshGraph() { final Date start = start_datebox.getValue(); if (start == null) { graphstatus.setText("Please specify a start time."); return;//from ww w . j ava 2 s . c o m } final Date end = end_datebox.getValue(); if (end != null && !autoreoload.isChecked()) { if (end.getTime() <= start.getTime()) { end_datebox.addStyleName("dateBoxFormatError"); graphstatus.setText("End time must be after start time!"); return; } } final StringBuilder url = new StringBuilder(); url.append("/q?start=").append(FULLDATE.format(start)); if (end != null && !autoreoload.isChecked()) { url.append("&end=").append(FULLDATE.format(end)); } else { // If there's no end-time, the graph may change while the URL remains // the same. No browser seems to re-fetch an image once it's been // fetched, even if we destroy the DOM object and re-created it with the // same src attribute. This has nothing to do with caching headers sent // by the server. The browsers simply won't retrieve the same URL again // through JavaScript manipulations, period. So as a workaround, we add // a special parameter that the server will delete from the query. url.append("&ignore=" + nrequests++); } if (!addAllMetrics(url)) { return; } addLabels(url); addFormats(url); addYRanges(url); addLogscales(url); if (nokey.isChecked()) { url.append("&nokey"); } else if (!keypos.isEmpty() || horizontalkey.isChecked()) { url.append("&key="); if (!keypos.isEmpty()) { url.append(keypos); } if (horizontalkey.isChecked()) { url.append(" horiz"); } if (keybox.isChecked()) { url.append(" box"); } } url.append("&wxh=").append(wxh.getText()); final String uri = url.toString(); if (uri.equals(lastgraphuri)) { return; // Don't re-request the same graph. } else if (pending_requests++ > 0) { return; } lastgraphuri = uri; graphstatus.setText("Loading graph..."); asyncGetJson(uri + "&json", new GotJsonCallback() { public void got(final JSONValue json) { if (autoreoload_timer != null) { autoreoload_timer.cancel(); autoreoload_timer = null; } final JSONObject result = json.isObject(); final JSONValue err = result.get("err"); String msg = ""; if (err != null) { displayError("An error occurred while generating the graph: " + err.isString().stringValue()); graphstatus.setText("Please correct the error above."); } else { clearError(); final JSONValue nplotted = result.get("plotted"); final JSONValue cachehit = result.get("cachehit"); if (cachehit != null) { msg += "Cache hit (" + cachehit.isString().stringValue() + "). "; } if (nplotted != null && nplotted.isNumber().doubleValue() > 0) { graph.setUrl(uri + "&png"); graph.setVisible(true); msg += result.get("points").isNumber() + " points retrieved, " + nplotted + " points plotted"; } else { graph.setVisible(false); msg += "Your query didn't return anything"; } final JSONValue timing = result.get("timing"); if (timing != null) { msg += " in " + timing + "ms."; } else { msg += '.'; } } final JSONValue info = result.get("info"); if (info != null) { if (!msg.isEmpty()) { msg += ' '; } msg += info.isString().stringValue(); } graphstatus.setText(msg); if (result.get("etags") != null) { final JSONArray etags = result.get("etags").isArray(); final int netags = etags.size(); for (int i = 0; i < netags; i++) { if (i >= metrics.getWidgetCount()) { break; } final Widget widget = metrics.getWidget(i); if (!(widget instanceof MetricForm)) { break; } final MetricForm metric = (MetricForm) widget; final JSONArray tags = etags.get(i).isArray(); final int ntags = tags.size(); for (int j = 0; j < ntags; j++) { metric.autoSuggestTag(tags.get(j).isString().stringValue()); } } } if (autoreoload.isChecked()) { final int reload_in = Integer.parseInt(autoreoload_interval.getValue()); if (reload_in >= 5) { autoreoload_timer = new Timer() { public void run() { // Verify that we still want auto reload and that the graph // hasn't been updated in the mean time. if (autoreoload.isChecked() && lastgraphuri == uri) { // Force refreshGraph to believe that we want a new graph. lastgraphuri = ""; refreshGraph(); } } }; autoreoload_timer.schedule(reload_in * 1000); } } if (--pending_requests > 0) { pending_requests = 0; refreshGraph(); } } }); }
From source file:org.apache.solr.explorer.client.util.json.JSONUtils.java
License:Apache License
/** * Converts JSON value to integer.//from w ww.j a v a 2 s . c o m * * @param jsonValue the JSON value. * @return the integer value. */ public static Integer jsonValueToInt(JSONValue jsonValue) { JSONNumber number = jsonValue.isNumber(); if (number == null) { throw new JSONException("Not an integer: " + jsonValue); } else { return new Double(number.doubleValue()).intValue(); } }
From source file:org.apache.solr.explorer.client.util.json.JSONUtils.java
License:Apache License
/** * Converts JSON value to long.//from w w w . jav a 2 s.co m * * @param jsonValue the JSON value. * @return the integer value. */ public static Long jsonValueToLong(JSONValue jsonValue) { JSONNumber number = jsonValue.isNumber(); if (number == null) { throw new JSONException("Not a long: " + jsonValue); } else { return new Double(number.doubleValue()).longValue(); } }
From source file:org.bonitasoft.console.client.user.process.action.ProcessInstantiationCallbackBehavior.java
License:Open Source License
protected String getAttributeValue(final String responseContent, final String attributeName) { String attributeValueAsString = null; if (responseContent != null && !responseContent.isEmpty()) { final JSONValue root = JSONParser.parseLenient(responseContent); final JSONObject dataObject = root.isObject(); if (dataObject != null) { final JSONValue attributeValue = dataObject.get(attributeName); if (attributeValue != null) { attributeValueAsString = Double.toString(attributeValue.isNumber().doubleValue()); }// www . j a v a 2 s . c o m } } return attributeValueAsString; }