List of usage examples for com.google.gwt.json.client JSONValue isString
public JSONString isString()
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 ww . ja v a 2 s. co 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.configuration.ConfigurationRetriever.java
License:Open Source License
/** * Retrieves a String property. Will throw an exception if not found. * @param key String which uniquely identifies the property */// w ww . j a v a 2 s .co m @Override public String getProperty(String key) throws ConfigurationKeyNotFoundException, InvalidConfigurationValueException { final JSONValue value = this.getJSONProperty(key); if (value == null) throw new ConfigurationKeyNotFoundException("Configuration key: " + key + " not found"); final JSONString stringValue = value.isString(); if (stringValue == null) throw new InvalidConfigurationValueException("Invalid string format for key " + key); return stringValue.stringValue(); }
From source file:es.deusto.weblab.client.configuration.ConfigurationRetriever.java
License:Open Source License
/** * Retrieves a string property. If the property is not found, * a default value is returned./*from w w w . ja v a 2s .co m*/ * @param key String which uniquely identifies the property * @param def Default string to return in case no string is found for the * specified key. */ @Override public String getProperty(String key, String def) { final JSONValue s = this.getJSONProperty(key); if (s == null) return def; final JSONString stringValue = s.isString(); if (stringValue == null) return def; return stringValue.stringValue(); }
From source file:es.deusto.weblab.client.experiments.aquarium.ui.SingleWebcamPanel.java
License:Open Source License
private void configureWebcam(WlWebcam webcam, JSONObject initialConfigObject, int number) { final JSONValue webcamValue = initialConfigObject.get("webcam" + number); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); webcam.setUrl(urlWebcam);/*from w w w . ja v a 2s . c o m*/ } final JSONValue mjpegValue = initialConfigObject.get("mjpeg" + number); if (mjpegValue != null) { final String mjpeg = mjpegValue.isString().stringValue(); int width = 320; int height = 240; if (initialConfigObject.get("mjpegWidth" + number) != null) { final JSONValue mjpegWidth = initialConfigObject.get("mjpegWidth" + number); if (mjpegWidth.isNumber() != null) { width = (int) mjpegWidth.isNumber().doubleValue(); } else if (mjpegWidth.isString() != null) { width = Integer.parseInt(mjpegWidth.isString().stringValue()); } } if (initialConfigObject.get("mjpegHeight" + number) != null) { final JSONValue mjpegHeight = initialConfigObject.get("mjpegHeight" + number); if (mjpegHeight.isNumber() != null) { height = (int) mjpegHeight.isNumber().doubleValue(); } else if (mjpegHeight.isString() != null) { height = Integer.parseInt(mjpegHeight.isString().stringValue()); } } webcam.setStreamingUrl(mjpeg, width, height); } }
From source file:es.deusto.weblab.client.experiments.incubator.ui.EggMiniWidget.java
License:Open Source License
private void configureWebcam(WlWebcam webcam, JSONObject initialConfigObject, String number) { final JSONValue webcamValue = initialConfigObject.get("webcam" + number); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); webcam.setUrl(urlWebcam);//from www. j a v a2s.co m } final JSONValue mjpegValue = initialConfigObject.get("mjpeg" + number); if (mjpegValue != null) { final String mjpeg = mjpegValue.isString().stringValue(); int width = 320; int height = 240; if (initialConfigObject.get("mjpegWidth" + number) != null) { final JSONValue mjpegWidth = initialConfigObject.get("mjpegWidth" + number); if (mjpegWidth.isNumber() != null) { width = (int) mjpegWidth.isNumber().doubleValue(); } else if (mjpegWidth.isString() != null) { width = Integer.parseInt(mjpegWidth.isString().stringValue()); } } if (initialConfigObject.get("mjpegHeight" + number) != null) { final JSONValue mjpegHeight = initialConfigObject.get("mjpegHeight" + number); if (mjpegHeight.isNumber() != null) { height = (int) mjpegHeight.isNumber().doubleValue(); } else if (mjpegHeight.isString() != null) { height = Integer.parseInt(mjpegHeight.isString().stringValue()); } } webcam.setStreamingUrl(mjpeg, width, height); } }
From source file:es.deusto.weblab.client.experiments.pic18.ui.Pic18Experiment.java
License:Open Source License
private boolean parseWebcamConfig(String initialConfiguration) { final JSONValue initialConfigValue = JSONParser.parseStrict(initialConfiguration); final JSONObject initialConfigObject = initialConfigValue.isObject(); if (initialConfigObject == null) { Window.alert("Error parsing robot configuration: not an object: " + initialConfiguration); return true; }//w ww .j a v a 2 s . c om final JSONValue webcamValue = initialConfigObject.get("webcam"); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); this.webcam.setUrl(urlWebcam); } final JSONValue mjpegValue = initialConfigObject.get("mjpeg"); if (mjpegValue != null) { final String mjpeg = mjpegValue.isString().stringValue(); int width = 320; int height = 240; if (initialConfigObject.get("mjpegWidth") != null) { final JSONValue mjpegWidth = initialConfigObject.get("mjpegWidth"); if (mjpegWidth.isNumber() != null) { width = (int) mjpegWidth.isNumber().doubleValue(); } else if (mjpegWidth.isString() != null) { width = Integer.parseInt(mjpegWidth.isString().stringValue()); } } if (initialConfigObject.get("mjpegHeight") != null) { final JSONValue mjpegHeight = initialConfigObject.get("mjpegHeight"); if (mjpegHeight.isNumber() != null) { height = (int) mjpegHeight.isNumber().doubleValue(); } else if (mjpegHeight.isString() != null) { height = Integer.parseInt(mjpegHeight.isString().stringValue()); } } this.webcam.setStreamingUrl(mjpeg, width, height); } return false; }
From source file:es.deusto.weblab.client.experiments.visir.VisirSetupData.java
License:Open Source License
/** * Parses the string, storing the received parameters for them * to be retrieved through various getters. * @param response Response that was received * @return true if the response was successfully parsed, false otherwise *///from w w w . j a v a 2s. c o m public boolean parseData(String response) { try { final JSONValue val = JSONParser.parseStrict(response); final JSONObject obj = val.isObject(); if (obj == null) return false; final JSONValue cookieval = obj.get("cookie"); final JSONValue savedataval = obj.get("savedata"); final JSONValue urlval = obj.get("url"); final JSONValue teacherval = obj.get("teacher"); final JSONValue circuitsList = obj.get("circuits"); if (cookieval == null || savedataval == null || urlval == null) return false; final JSONString cookiestr = cookieval.isString(); final JSONString savedatastr = savedataval.isString(); final JSONString urlstr = urlval.isString(); if (cookiestr == null || savedatastr == null || urlstr == null) return false; this.cookie = cookiestr.stringValue(); this.saveData = savedatastr.stringValue(); this.url = urlstr.stringValue(); if (teacherval != null) { JSONBoolean teacherbool = teacherval.isBoolean(); this.teacher = teacherbool != null && teacherbool.booleanValue(); } else this.teacher = false; // We will now parse the list of available circuits. This is a list containing // the names of available circuits. Their actual data is not included and needs to // be requested separatedly. this.circuitsAvailable = new ArrayList<String>(); if (circuitsList == null) { } else { JSONArray circuitsAvailableArray = circuitsList.isArray(); for (int i = 0; i < circuitsAvailableArray.size(); ++i) { final JSONValue circuitName = circuitsAvailableArray.get(i); final String circuitNameStr = circuitName.isString().stringValue(); this.circuitsAvailable.add(circuitNameStr); } } } catch (Throwable e) { return false; } return true; }
From source file:es.deusto.weblab.client.lab.comm.LabSerializerJSON.java
License:Open Source License
private String extractString(String data, String fieldName) throws SerializationException { try {/*from w w w. j av a2 s .co m*/ if (data == null) return null; final JSONValue value = JSONParser.parseStrict(data); if (value == JSONNull.getInstance()) { return null; } final JSONString stringValue = value.isString(); if (stringValue == null) throw new SerializationException( "Invalid " + fieldName + ": expected a string and found a " + value.getClass().getName()); return stringValue.stringValue(); } catch (final IllegalArgumentException e) { throw new SerializationException("Invalid " + fieldName + ": " + e.getMessage(), e); } catch (final JSONException e) { throw new SerializationException("Invalid " + fieldName + ": " + e.getMessage(), e); } }
From source file:es.deusto.weblab.client.ui.widgets.WlStreamImage.java
License:Open Source License
public void configureImageStream(JSONObject initialConfigObject) { final JSONValue webcamValue = initialConfigObject.get("webcam"); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); setUrl(urlWebcam);//from w w w. j a v a 2 s. c o m } }
From source file:es.deusto.weblab.client.ui.widgets.WlWebcam.java
License:Open Source License
public void configureWebcam(JSONObject initialConfigObject) { final JSONValue webcamValue = initialConfigObject.get("webcam"); if (webcamValue != null) { final String urlWebcam = webcamValue.isString().stringValue(); setUrl(urlWebcam);// w w w . j a va 2s .c om } final JSONValue mjpegValue = initialConfigObject.get("mjpeg"); if (mjpegValue != null) { final String mjpeg = mjpegValue.isString().stringValue(); int width = 320; int height = 240; if (initialConfigObject.get("mjpegWidth") != null) { final JSONValue mjpegWidth = initialConfigObject.get("mjpegWidth"); if (mjpegWidth.isNumber() != null) { width = (int) mjpegWidth.isNumber().doubleValue(); } else if (mjpegWidth.isString() != null) { width = Integer.parseInt(mjpegWidth.isString().stringValue()); } } if (initialConfigObject.get("mjpegHeight") != null) { final JSONValue mjpegHeight = initialConfigObject.get("mjpegHeight"); if (mjpegHeight.isNumber() != null) { height = (int) mjpegHeight.isNumber().doubleValue(); } else if (mjpegHeight.isString() != null) { height = Integer.parseInt(mjpegHeight.isString().stringValue()); } } setStreamingUrl(mjpeg, width, height); } }