Example usage for com.google.gwt.json.client JSONValue isNumber

List of usage examples for com.google.gwt.json.client JSONValue isNumber

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isNumber.

Prototype

public JSONNumber isNumber() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONNumber.

Usage

From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java

License:Open Source License

protected int json2int(JSONValue value) throws SerializationException {
    if (value == null)
        throw new SerializationException("Int expected, found null");
    final JSONNumber jsonnumber = value.isNumber();
    if (jsonnumber == null)
        throw new SerializationException("Int expected, found: " + value);
    return (int) jsonnumber.doubleValue();
}

From source file:es.deusto.weblab.client.configuration.ConfigurationRetriever.java

License:Open Source License

/**
 * Retrieves an integer property. Will throw if the property is not found
 * after searching the retriever and its parent.
 * @param key String which uniquely identifies the property
 *//*  w  w  w.j  a v a  2  s.  c  om*/
@Override
public int getIntProperty(String key)
        throws ConfigurationKeyNotFoundException, InvalidConfigurationValueException {
    final JSONValue value = this.getJSONProperty(key);
    if (value == null)
        throw new ConfigurationKeyNotFoundException("Configuration key: " + key + " not found");

    final JSONNumber numberValue = value.isNumber();
    if (numberValue == null)
        throw new InvalidConfigurationValueException("Invalid number format for key " + key);
    return (int) numberValue.doubleValue();
}

From source file:es.deusto.weblab.client.configuration.ConfigurationRetriever.java

License:Open Source License

/**
 * Retrieves an integer property.//ww  w .  ja  v  a2 s. c  o m
 * @param key String which uniquely identifies the property
 */
@Override
public int getIntProperty(String key, int def) {
    final JSONValue value = this.getJSONProperty(key);
    if (value == null)
        return def;

    final JSONNumber numberValue = value.isNumber();
    if (numberValue == null)
        return def;

    return (int) numberValue.doubleValue();
}

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  va2s.  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.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 ww  w.  j a  va  2  s . 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  w  w.  j a v a 2s . com*/

    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.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);//ww  w .  ja  v  a 2 s . 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);
    }
}

From source file:fast.servicescreen.client.gui.codegen_js.CodeGenerator.java

License:Open Source License

/**
 * This method send the current template to
 * an service which writes a js and a html file with it as content. 
 * *//*from  w w  w . j av a  2  s. c o m*/
public void write_JS_File(boolean isLocal) {
    //create GWT service impl.
    service = GWT.create(RequestService.class);

    //send pre - trans - post code to server
    service.saveJsFileOnServer(isLocal, screen.getName(), prehtml, helperMethods + rootTemplate, posthtml,
            new AsyncCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    GWT.log("Writing .js file to RequestService succed..", null);

                    Window.alert(result);
                }

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log("ERROR while writing .js file to RequestService..", null);

                    Window.alert(caught.getLocalizedMessage());
                }
            });

    //shareBuildingBlock():
    //url and header
    String url = "http://localhost:13337/" /*URL_Settings.getGVS_URL()*/ + "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 jsonObject = createBuildingBlock();
    String body = "buildingblock=" + jsonObject;

    //upload to GVS
    service.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() {
        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(String result) {
            if (result != null && result != "-1" && result.startsWith("{")) {
                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 = "http://127.0.0.1:13337/" + "buildingblock/" + id + "/sharing";
                    service.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);
                        }
                    });
                }
            }
        }
    });
}

From source file:fast.servicescreen.client.gui.RuleUtil.java

License:Open Source License

/**
 * Recursive method for retrieving all jsonvalues for a specified tagName
 * *///from   w w w  .  j  a va  2  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/*w  w  w.ja  v a2 s . c om*/
 * */
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 "";
}