List of usage examples for com.google.gwt.json.client JSONValue toString
@Override public abstract String toString();
From source file:com.ponysdk.core.terminal.PonySDK.java
License:Apache License
/** * From Main terminal to the server//from ww w .j a v a 2s .c o m * Ajax implementation */ public void sendDataToServer(final Object objectID, final JavaScriptObject jsObject, final AjaxCallback callback) { if (callback == null) { final PTInstruction instruction = new PTInstruction(Integer.valueOf(objectID.toString())); instruction.put(ClientToServerModel.NATIVE, jsObject); uiBuilder.sendDataToServer(instruction); } else { final XMLHttpRequest xhr = Browser.getWindow().newXMLHttpRequest(); final PTObject ptObject = uiBuilder.getPTObject(Integer.parseInt(objectID.toString())); xhr.setOnload(evt -> callback.setAjaxResponse(xhr.getResponseText())); xhr.open("GET", MappingPath.AJAX); xhr.setRequestHeader(ClientToServerModel.UI_CONTEXT_ID.name(), String.valueOf(contextId)); xhr.setRequestHeader(ClientToServerModel.OBJECT_ID.name(), String.valueOf(ptObject.getObjectID())); final JSONObject jsonArray = new JSONObject(jsObject); for (final String key : jsonArray.keySet()) { final JSONValue jsonValue = jsonArray.get(key); final JSONString stringValue = jsonValue.isString(); xhr.setRequestHeader(key, stringValue != null ? stringValue.stringValue() : jsonValue.toString()); } xhr.send(); } }
From source file:com.ponysdk.core.terminal.request.ParentRequestBuilder.java
License:Apache License
/** * To Main terminal//from w ww .j a va2s. c om */ @Override public void send(final JSONValue requestData) { sendToParent(requestData.toString()); }
From source file:com.ponysdk.core.terminal.request.ParentWindowRequest.java
License:Apache License
/** * To Main terminal */ @Override public void send(final JSONValue value) { sendToParent(value.toString()); }
From source file:com.ponysdk.core.terminal.request.WebSocketRequestBuilder.java
License:Apache License
@Override public void send(final JSONValue value) { webSocketClient.send(value.toString()); }
From source file:com.smartgwt.mobile.client.data.DataSource.java
License:Open Source License
private static RecordList extractRecordList(JSONArray dataArr, Map<String, DataSourceField> fields) { final DataSourceField pkField = getPrimaryKeyField(fields); final String pkFieldName = pkField == null ? "id" : pkField.getName(); final RecordList records = new RecordList(); for (int i = 0; i < dataArr.size(); ++i) { final JSONValue datumVal = dataArr.get(i); if (datumVal == null) continue; JSONObject datumObj = datumVal.isObject(); if (datumObj != null) { records.add(extractRecord(datumObj, fields)); } else {/* www. j av a 2 s. c om*/ if (datumVal.isNull() != null) continue; String idValue; JSONString datumStr = datumVal.isString(); if (datumStr != null) idValue = datumStr.stringValue(); else idValue = datumVal.toString(); idValue = idValue.trim(); final Record record = new Record(); record.setAttribute(pkFieldName, idValue); records.add(record); } } return records; }
From source file:com.smartgwt.mobile.client.data.DSResponse.java
License:Open Source License
DSResponse(DSRequest dsRequest, int status, JSONObject responseObj) { init(dsRequest);//from w w w .ja v a 2 s . c om Map<String, String> errors = null; if (responseObj != null) { JSONValue val = responseObj.get("status"); JSONNumber num = (val == null ? null : val.isNumber()); if (num != null) { status = (int) num.doubleValue(); } val = responseObj.get("startRow"); num = (val == null ? null : val.isNumber()); if (num != null) { setStartRow(Integer.valueOf((int) num.doubleValue())); } val = responseObj.get("endRow"); num = (val == null ? null : val.isNumber()); if (num != null) { setEndRow(Integer.valueOf((int) num.doubleValue())); } val = responseObj.get("totalRows"); num = (val == null ? null : val.isNumber()); if (num != null) { setTotalRows(Integer.valueOf((int) num.doubleValue())); } val = responseObj.get("errors"); JSONObject errorsObj = (val == null ? null : val.isObject()); if (errorsObj != null) { errors = new HashMap<String, String>(); for (final String key : errorsObj.keySet()) { val = errorsObj.get(key); if (val == null || val.isNull() != null) continue; final String errorMessage; JSONString str = val.isString(); if (str != null) errorMessage = str.stringValue(); else errorMessage = val.toString(); errors.put(key, errorMessage); } } } setStatus(status); if (errors != null) setErrors(errors); // No need to handle the response data here. }
From source file:cometedgwt.auction.client.StreamingServiceGWTClientImpl.java
License:Open Source License
public void sendMessage(String topicName, JSONValue object) { sendMessage(topicName, "$JSONSTART$" + object.toString() + "$JSONEND$"); }
From source file:de.eckhartarnold.client.ImageCollectionReader.java
License:Apache License
private void retrieveSequentially(String baseURL, ICallback readyReport, IMessage errorReport) { final ICallback ready = readyReport; final IMessage error = errorReport; final ImageCollectionReader src = this; final String url = baseURL; if (directories == null) { readJSON(baseURL + "/directories.json", new JSONDelegate() { public void process(JSONValue json) { directories = interpretStringArray(json); for (int i = 0; i < directories.length; i++) directories[i] = url + "/" + directories[i]; if (isReady() && !finished) { finished = true;/* ww w . ja v a 2 s. com*/ ready.callback(src); } else retrieveSequentially(url, ready, error); } }, errorReport); } else if (imageNames == null) { readJSON(baseURL + "/filenames.json", new JSONDelegate() { public void process(JSONValue json) { imageNames = interpretStringArray(json); if (isReady() && !finished) { finished = true; ready.callback(src); } else retrieveSequentially(url, ready, error); } }, errorReport); } else if (captionDictionary == null) { readJSON(baseURL + "/captions.json", new JSONDelegate() { public void process(JSONValue json) { captionDictionary = interpretStringDictionary(json); if (isReady() && !finished) { finished = true; ready.callback(src); } else retrieveSequentially(url, ready, error); } }, errorReport); } else if (imageSizes == null) { readJSON(baseURL + "/resolutions.json", new JSONDelegate() { public void process(JSONValue json) { imageSizes = interpretSizes(json); if (isReady() && !finished) { finished = true; ready.callback(src); } else retrieveSequentially(url, ready, error); } }, errorReport); } else if (info == null) { readJSON(baseURL + "/" + infoFileName, new JSONDelegate() { public void process(JSONValue json) { GWT.log(json.toString()); info = interpretStringDictionary(json); if (isReady() && !finished) { finished = true; ready.callback(src); } else retrieveSequentially(url, ready, error); } }, errorReport); } }
From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java
License:Open Source License
protected String json2string(JSONValue value, boolean supportNull) throws SerializationException { if (value == null || value.toString().trim().equals("{}")) { if (supportNull) return null; throw new SerializationException("String expected, found null"); }//from w w w. j a v a 2s. c o m final JSONString jsonstring = value.isString(); if (jsonstring == null) throw new SerializationException("String expected, found: " + value); return jsonstring.stringValue(); }
From source file:es.deusto.weblab.client.lab.comm.LabSerializerJSON.java
License:Open Source License
@Override public String serializeReserveExperimentRequest(SessionID sessionId, ExperimentID experimentId, JSONValue clientInitialData) throws SerializationException { //{"params": {"session_id": {"id": "svAsc-rCIKLP1qeU"}, // "experiment_id": {"exp_name": "ud-dummy", "cat_name": "Dummy experiments"}, // "client_initial_data" : "{}", // "consumer_data" : "{}"}, // "method": "reserve_experiment"} final JSONObject params = new JSONObject(); params.put("session_id", this.serializeSessionId(sessionId)); final JSONObject jsonExperimentId = new JSONObject(); jsonExperimentId.put("exp_name", new JSONString(experimentId.getExperimentName())); jsonExperimentId.put("cat_name", new JSONString(experimentId.getCategory().getCategory())); params.put("experiment_id", jsonExperimentId); if (clientInitialData == null) params.put("client_initial_data", new JSONString("{}")); else//from w ww . ja v a2 s . c o m params.put("client_initial_data", new JSONString(clientInitialData.toString())); // Client will never implement the consumer_data, since this argument is intended to be used with an external // entity such as a LMS or an external WebLab-Deusto, and will include things such as "user_identifier", etc. params.put("consumer_data", new JSONString("{}")); return this.serializeRequest("reserve_experiment", params); }