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

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

Introduction

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

Prototype

public JSONString isString() 

Source Link

Document

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

Usage

From source file:ccc.client.gwt.core.GWTJson.java

License:Open Source License

/** {@inheritDoc} */
@Override//  w w  w . j a v a2s.co m
public Collection<String> getStrings(final String key) {
    final JSONValue value = _delegate.get(key);
    if (null == value) {
        throw new S11nException("Missing key: " + key);
    } else if (null != value.isNull()) {
        return null;
    }

    final Collection<String> strings = new ArrayList<String>();

    final JSONArray array = value.isArray();
    for (int i = 0; i < array.size(); i++) {
        final JSONValue arrayElement = array.get(i);
        if (null != arrayElement.isNull()) {
            strings.add(null);
        } else {
            strings.add(arrayElement.isString().stringValue());
        }
    }

    return strings;
}

From source file:ccc.client.gwt.core.GWTJson.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w  w  w  .j  a v a 2 s.  c o  m
public Map<String, String> getStringMap(final String key) {
    final Map<String, String> value = new HashMap<String, String>();
    final JSONValue v = _delegate.get(key);
    if (null == v) {
        throw new S11nException("Missing key: " + key);
    } else if (null != v.isNull()) {
        return null;
    }
    final JSONObject o = v.isObject();
    for (final String mapKey : o.keySet()) {
        final JSONValue mapValue = o.get(mapKey);
        if (null != mapValue.isNull()) {
            value.put(mapKey, null);
        } else {
            value.put(mapKey, mapValue.isString().stringValue());
        }
    }
    return value;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.java

License:Apache License

/**
 * @return the unique identifier of the device that has originated the event
 *///from   ww  w. j  a v  a  2s  .c om
public String getOriginatingDevice() {
    JSONValue value = root.get(ORIGINATINGDEVICE);
    if (value != null && value.isString() != null)
        return value.isString().stringValue();
    return null;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.java

License:Apache License

/**
 * @return the source of the event/*from   w  ww  .j  a v a 2s.c om*/
 */
public String getSourceObject() {
    JSONValue value = root.get(SOURCE);
    if (value != null && value.isString() != null)
        return value.isString().stringValue();
    return null;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.java

License:Apache License

/**
 * @return the context identifier of the event
 *///from  w  w  w  .  j a va 2  s .c  o  m
public String getContext() {
    JSONValue value = root.get(CONTEXT);
    if (value != null && value.isString() != null)
        return value.isString().stringValue();
    return null;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.java

License:Apache License

/**
 * @return the timestamp of the event in ms
 *//*w  ww  .j a  va 2 s . c o m*/
public Long getTimestamp() {
    JSONValue value = root.get(TIMESTAMP);
    if (value != null && value.isString() != null)
        return Long.parseLong(value.isString().stringValue());
    return null;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.java

License:Apache License

/**
 * @param key/*from   w  w  w  . j  av  a 2s.  com*/
 * @return the property value for the given key or null if not set.
 */
public String getProperty(String key) {
    JSONValue v = json.get(key);
    if (v != null && v.isString() != null)
        return v.isString().stringValue();
    return null;
}

From source file:ch.unifr.pai.twice.comm.serverPush.client.RemoteEventDeserializer.java

License:Apache License

public final RemoteEvent<?> deserialize(String string, TWICESecurityManager security)
        throws MessagingException {
    com.google.gwt.json.client.JSONValue value = com.google.gwt.json.client.JSONParser.parseStrict(string);
    com.google.gwt.json.client.JSONObject o = value.isObject();
    if (o != null) {
        com.google.gwt.json.client.JSONValue type = o
                .get(ch.unifr.pai.twice.comm.serverPush.client.RemoteEvent.EVENTTYPEKEY);
        String t = null;//from  w  ww .j  av a 2 s. com
        if (type != null && type.isString() != null) {
            t = type.isString().stringValue();
            return deserialize(o, t, string, security);
        }
    }
    return null;
}

From source file:cl.uai.client.data.AjaxRequest.java

License:Open Source License

/**
 * Assuming a json string (PHP json_encode() format), it transforms the string to a JSONObject.
 * @param Json string to parse./*from w  ww.j av a2s.  c om*/
 * @param Header of the string (this fix the json_encode() PHP format).
 * @param Numeric key of the json collection to get the values.
 * @param 
 * @return a string value of defined key
 */

public static List<Map<String, String>> getValuesFromJsonString(String json, String header) {

    //Defining output
    List<Map<String, String>> output = new ArrayList<Map<String, String>>();
    //Define keys to get from the markers json array
    List<String> markersKeys = Arrays.asList("id", "username", "firstname", "lastname");

    //fix the json format for JSONObject to understand it
    String jsonString = "{\"" + header + "\":" + json + "}";
    //Set json string as a JSONValue
    JSONValue markersValue = JSONParser.parseStrict(jsonString);
    JSONObject markersObject;
    JSONArray markersArray;
    JSONString jsonStringOutput;
    //Object checking
    if ((markersObject = markersValue.isObject()) == null) {
        logger.severe("Error parsing the JSONObject");
    }
    //Array checking
    markersValue = markersObject.get(header);
    if ((markersArray = markersValue.isArray()) == null) {
        logger.severe("Error parsing the JSONArray");
    }
    //Loop for getting each marker info, creating markers info array
    for (int i = 0; i < markersArray.size(); i++) {
        Map<String, String> obj = new HashMap<String, String>();
        //Object checking for defined numeric key of the array
        markersValue = markersArray.get(i);
        if ((markersObject = markersValue.isObject()) == null) {
            logger.severe("Error parsing the JSONValue");
        }
        //String checking for "id", "username", "firstname", "lastname"
        //Loop for getting the info values for each marker
        for (int j = 0; j < markersKeys.size(); j++) {
            markersValue = markersObject.get(markersKeys.get(j).toString());
            if ((jsonStringOutput = markersValue.isString()) == null) {
                logger.severe("Error parsing the JSONString");
            }
            obj.put(markersKeys.get(j).toString(), jsonStringOutput.stringValue());
        }
        output.add(obj);
    }
    //Return markers array output

    return output;
}

From source file:colt.json.gwt.client.UJsonClient.java

License:Apache License

static public String getString(JSONObject _o, String _key, String _default) {
    JSONValue v = _o.get(_key);
    if (v == null)
        return _default;
    if (v.isString() == null)
        return _default;
    return v.isString().stringValue();
}