Search in sources :

Example 11 with JSONValue

use of com.google.gwt.json.client.JSONValue in project gwt-test-utils by gwt-test-utils.

the class JSONObjectParser method getInnerMap.

private static Map<String, JSONValue> getInnerMap(JSONObject jsonObject) {
    JavaScriptObject jsObject = jsonObject.getJavaScriptObject();
    Map<String, JSONValue> map = JavaScriptObjects.getObject(jsObject, JSONOBJECT_MAP);
    if (map == null) {
        map = new LinkedHashMap<String, JSONValue>();
        JavaScriptObjects.setProperty(jsObject, JSONOBJECT_MAP, map);
    }
    return map;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 12 with JSONValue

use of com.google.gwt.json.client.JSONValue in project perun by CESNET.

the class JsonUtils method parseJsonToMap.

/**
	 * Parses a JavaScript map into a Java map.
	 * @param jso
	 * @return
	 */
public static final Map<String, JSONValue> parseJsonToMap(JavaScriptObject jso) {
    if (jso == null) {
        // when null, return empty map
        return new HashMap<String, JSONValue>();
    }
    JSONObject obj = new JSONObject(jso);
    HashMap<String, JSONValue> m = new HashMap<String, JSONValue>();
    for (String key : obj.keySet()) {
        m.put(key, obj.get(key));
    }
    return m;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 13 with JSONValue

use of com.google.gwt.json.client.JSONValue in project perun by CESNET.

the class AddUserExtSource method prepareJSONObject.

/**
	 * Prepares a JSON object
	 *
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    JSONNumber user = new JSONNumber(userId);
    // create Json object from webgui extSource
    JSONObject oldExtSource = new JSONObject(extSource);
    // get only interested in items
    JSONValue uesName = oldExtSource.get("name");
    JSONValue uesId = oldExtSource.get("id");
    JSONValue uesType = oldExtSource.get("type");
    // create a new form of ext source
    JSONObject newExtSource = new JSONObject();
    newExtSource.put("name", uesName);
    newExtSource.put("id", uesId);
    newExtSource.put("type", uesType);
    // create new userExtSource
    JSONObject userExtSource = new JSONObject();
    userExtSource.put("id", new JSONNumber(0));
    userExtSource.put("extSource", newExtSource);
    userExtSource.put("login", new JSONString(login));
    userExtSource.put("loa", new JSONNumber(loa));
    // create whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("user", user);
    jsonQuery.put("userExtSource", userExtSource);
    return jsonQuery;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) JSONNumber(com.google.gwt.json.client.JSONNumber) JSONString(com.google.gwt.json.client.JSONString)

Example 14 with JSONValue

use of com.google.gwt.json.client.JSONValue in project perun by CESNET.

the class SetAttributes method prepareJSONObject.

/**
	 * Prepares a JSON object.
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    // create whole JSON query
    JSONObject jsonQuery = new JSONObject();
    // create attrs field
    JSONArray array = new JSONArray();
    // create attributes
    for (int i = 0; i < attributes.size(); i++) {
        // skip attribute with empty or null value
        if (attributes.get(i).getValue() == null || attributes.get(i).getValue().equalsIgnoreCase("")) {
            continue;
        }
        // create Json object from attribute
        JSONObject attr = new JSONObject(attributes.get(i));
        // get only interested in properties
        JSONValue id = attr.get("id");
        JSONValue friendlyName = attr.get("friendlyName");
        JSONValue namespace = attr.get("namespace");
        JSONValue type = attr.get("type");
        JSONValue description = attr.get("description");
        JSONValue value = attr.get("value");
        JSONValue displayName = attr.get("displayName");
        // create new Attribute jsonObject
        JSONObject newAttr = new JSONObject();
        newAttr.put("value", value);
        newAttr.put("id", id);
        newAttr.put("type", type);
        newAttr.put("description", description);
        newAttr.put("namespace", namespace);
        newAttr.put("friendlyName", friendlyName);
        newAttr.put("displayName", displayName);
        // put attribute into array
        array.set(array.size(), newAttr);
    }
    for (Map.Entry<String, Integer> attrIds : this.ids.entrySet()) {
        jsonQuery.put(attrIds.getKey(), new JSONNumber(attrIds.getValue()));
    }
    jsonQuery.put("attributes", array);
    return jsonQuery;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray) JSONNumber(com.google.gwt.json.client.JSONNumber) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with JSONValue

use of com.google.gwt.json.client.JSONValue in project GwtMobile by dennisjzh.

the class BluetoothUi method listDevices.

public void listDevices() {
    Bluetooth.listDevices(new StringCallback() {

        @Override
        public void onSuccess(String result) {
            try {
                String textHTML = "";
                JSONValue value = JSONParser.parseLenient(result);
                JSONArray devicesArray = value.isArray();
                if (devicesArray != null) {
                    textHTML = "Result:";
                    for (int i = 0; i < devicesArray.size(); i++) {
                        JSONObject deviceObj = devicesArray.get(i).isObject();
                        textHTML = textHTML + "<br/>" + deviceObj.get("name");
                    }
                    text.setHTML(textHTML);
                }
            } catch (Exception e) {
                e.printStackTrace();
                text.setHTML("Error: " + e.getMessage());
            }
        }

        @Override
        public void onError(String message) {
            text.setHTML("Error: " + message);
        }
    });
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) StringCallback(com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback) JSONArray(com.google.gwt.json.client.JSONArray)

Aggregations

JSONValue (com.google.gwt.json.client.JSONValue)23 JSONObject (com.google.gwt.json.client.JSONObject)13 JSONArray (com.google.gwt.json.client.JSONArray)10 JSONString (com.google.gwt.json.client.JSONString)8 HashMap (java.util.HashMap)5 Date (java.util.Date)4 JSONNumber (com.google.gwt.json.client.JSONNumber)3 EntryPoint (com.google.gwt.core.client.EntryPoint)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 RequestBuilder (com.google.gwt.http.client.RequestBuilder)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)2 StringCallback (com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Style (com.google.gwt.dom.client.Style)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1