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

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

Introduction

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

Prototype

public JSONBoolean isBoolean() 

Source Link

Document

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

Usage

From source file:ca.nanometrics.gflot.client.util.JSONObjectWrapper.java

License:Open Source License

protected Boolean getBoolean(String key) {
    JSONValue value = get(key);
    if (value == null) {
        return null;
    }//from   ww w .j a v  a2  s . c  o  m
    JSONBoolean str = value.isBoolean();
    return str == null ? null : str.booleanValue();
}

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

License:Open Source License

/** {@inheritDoc} */
@Override/*  w  w w  .  j av a  2s .  c  o m*/
public Boolean getBool(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;
    }
    return Boolean.valueOf(value.isBoolean().booleanValue());
}

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

License:Apache License

static public boolean getBoolean(JSONObject _o, String _key, boolean _default) {
    JSONValue v = _o.get(_key);
    if (v == null)
        return _default;
    if (v.isBoolean() == null)
        return _default;
    return v.isBoolean().booleanValue();
}

From source file:com.ait.lienzo.client.core.shape.json.validators.BooleanValidator.java

License:Open Source License

@Override
public void validate(JSONValue jval, ValidationContext ctx) throws ValidationException {
    if (null == jval) {
        ctx.addBadTypeError("Boolean");

        return;/*from  w  w w . j  av  a 2  s .co  m*/
    }
    JSONBoolean s = jval.isBoolean();

    if (null == s) {
        ctx.addBadTypeError("Boolean");
    }
}

From source file:com.arcbees.analytics.client.ClientAnalytics.java

License:Apache License

public void fallback(JsArrayMixed arguments) {
    if ("send".equals(arguments.getString(0))) {
        JSONObject jsonOptions = new JSONObject(arguments.getObject(arguments.length() - 1));
        StringBuilder url = new StringBuilder();
        url.append(fallbackPath).append("?");
        url.append(ProtocolTranslator.getFieldName("hitType")).append("=")
                .append(URL.encodeQueryString(arguments.getString(1)));

        for (String key : jsonOptions.keySet()) {
            if (!"hitCallback".equals(key)) {
                JSONValue jsonValue = jsonOptions.get(key);
                String strValue = "";
                if (jsonValue.isBoolean() != null) {
                    strValue = jsonValue.isBoolean().booleanValue() + "";
                } else if (jsonValue.isNumber() != null) {
                    strValue = jsonValue.isNumber().doubleValue() + "";
                } else if (jsonValue.isString() != null) {
                    strValue = jsonValue.isString().stringValue();
                }/*from   www.j a  va  2s .  c  o m*/
                url.append("&").append(ProtocolTranslator.getFieldName(key)).append("=")
                        .append(URL.encodeQueryString(strValue));
            }
        }
        try {
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url.toString());
            requestBuilder.setCallback(new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    // TODO call hitcallback if needed.
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    // TODO Auto-generated method stub
                }
            });
            requestBuilder.send();
        } catch (RequestException e) {
        }
    }
}

From source file:com.eduworks.gwt.client.net.packet.AjaxPacket.java

License:Apache License

public Boolean getBoolean(String key) {
    JSONValue jv;
    try {//www  . ja  v  a2s.c o  m
        jv = super.get(key);
    } catch (NullPointerException e) {
        return null;
    }
    if (jv != null && jv.isBoolean() != null)
        return (Boolean) jv.isBoolean().booleanValue();
    return null;
}

From source file:com.extjs.gxt.ui.client.data.JsonReader.java

License:sencha.com license

@SuppressWarnings({ "unchecked", "rawtypes" })
public D read(Object loadConfig, Object data) {
    JSONObject jsonRoot = null;/*from  w  ww. j  av a2  s .c o  m*/
    if (data instanceof JavaScriptObject) {
        jsonRoot = new JSONObject((JavaScriptObject) data);
    } else {
        jsonRoot = (JSONObject) JSONParser.parse((String) data);
    }
    JSONArray root = (JSONArray) jsonRoot.get(modelType.getRoot());
    int size = root.size();
    ArrayList<ModelData> models = new ArrayList<ModelData>();
    for (int i = 0; i < size; i++) {
        JSONObject obj = (JSONObject) root.get(i);
        ModelData model = newModelInstance();
        for (int j = 0; j < modelType.getFieldCount(); j++) {
            DataField field = modelType.getField(j);
            String name = field.getName();
            Class type = field.getType();
            String map = field.getMap() != null ? field.getMap() : field.getName();
            JSONValue value = obj.get(map);

            if (value == null)
                continue;
            if (value.isArray() != null) {
                // nothing
            } else if (value.isBoolean() != null) {
                model.set(name, value.isBoolean().booleanValue());
            } else if (value.isNumber() != null) {
                if (type != null) {
                    Double d = value.isNumber().doubleValue();
                    if (type.equals(Integer.class)) {
                        model.set(name, d.intValue());
                    } else if (type.equals(Long.class)) {
                        model.set(name, d.longValue());
                    } else if (type.equals(Float.class)) {
                        model.set(name, d.floatValue());
                    } else {
                        model.set(name, d);
                    }
                } else {
                    model.set(name, value.isNumber().doubleValue());
                }
            } else if (value.isObject() != null) {
                // nothing
            } else if (value.isString() != null) {
                String s = value.isString().stringValue();
                if (type != null) {
                    if (type.equals(Date.class)) {
                        if ("timestamp".equals(field.getFormat())) {
                            Date d = new Date(Long.parseLong(s) * 1000);
                            model.set(name, d);
                        } else {
                            DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat());
                            Date d = format.parse(s);
                            model.set(name, d);
                        }
                    }
                } else {
                    model.set(name, s);
                }
            } else if (value.isNull() != null) {
                model.set(name, null);
            }
        }
        models.add(model);
    }
    int totalCount = models.size();
    if (modelType.getTotalName() != null) {
        totalCount = getTotalCount(jsonRoot);
    }
    return (D) createReturnData(loadConfig, models, totalCount);
}

From source file:com.extjs.gxt.ui.client.js.JsonConverter.java

License:sencha.com license

/**
 * Decodes a JSONObject to a map.//from  w ww .j av a2s .  c  om
 * 
 * @param jso the JSONObject
 * @return the map
 */
public static Map<String, Object> decode(JSONObject jso) {
    Map<String, Object> map = new FastMap<Object>();
    for (String key : jso.keySet()) {
        JSONValue j = jso.get(key);
        if (j.isObject() != null) {
            map.put(key, decode(j.isObject()));
        } else if (j.isArray() != null) {
            map.put(key, decodeToList(j.isArray()));
        } else if (j.isBoolean() != null) {
            map.put(key, j.isBoolean().booleanValue());
        } else if (j.isString() != null) {
            map.put(key, decodeValue(j.isString().stringValue()));
        }
    }
    return map;
}

From source file:com.extjs.gxt.ui.client.js.JsonConverter.java

License:sencha.com license

protected static List<Object> decodeToList(JSONArray array) {
    List<Object> list = new ArrayList<Object>();
    for (int i = 0; i < array.size(); i++) {
        JSONValue v = array.get(i);
        if (v.isObject() != null) {
            list.add(decode(v.isObject()));
        } else if (v.isArray() != null) {
            list.add(decodeToList(v.isArray()));
        } else if (v.isNull() != null) {
            list.add(null);/*from w  ww  .j a v a  2s  .c  o  m*/
        } else if (v.isNumber() != null) {
            list.add(v.isNumber().doubleValue());
        } else if (v.isBoolean() != null) {
            list.add(v.isBoolean().booleanValue());
        } else if (v.isString() != null) {
            list.add(decodeValue(v.isString().stringValue()));
        }
    }

    return list;
}

From source file:com.flatown.client.SearchBox.java

License:Apache License

/** 
 * Convenience constructor for a SearchBox from a JSONObject. 
 *//*from   ww w  .j a  v a  2  s .  co m*/
public SearchBox(JSONObject searchbox) {
    this();
    _layoutPanel.setSearchQuery(searchbox.get("query").isString().stringValue());
    _layoutPanel.setDatabase(searchbox.get("dbName").isString().stringValue());
    _layoutPanel.setNumResults((int) (searchbox.get("numResults").isNumber().getValue()));

    JSONValue vis;
    if ((vis = searchbox.get("vis")) != null)
        _layoutPanel.setResultsDisplayed(vis.isBoolean().booleanValue());
}