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:org.sigmah.offline.status.ConnectionStatus.java

License:Open Source License

public void updateStatus() {
    final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, "sigmah/online.nocache.json");
    try {/*from  www.j  a va  2s.  com*/
        requestBuilder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) {
                if (response != null && response.getText() != null && !response.getText().isEmpty()) {
                    try {
                        final JSONValue value = JSONParser.parseStrict(response.getText());
                        final JSONObject object = value.isObject();
                        if (object != null) {
                            final JSONValue online = object.get("online");
                            final JSONBoolean isOnline = online.isBoolean();
                            setOnline(isOnline != null && isOnline.booleanValue());
                        } else {
                            setOnline(false);
                        }
                    } catch (JSONException ex) {
                        setOnline(false);
                        Log.error(
                                "An error occured while parsing the JSON string: '" + response.getText() + "'.",
                                ex);
                    }
                } else {
                    setOnline(false);
                }
            }

            @Override
            public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
                setOnline(false);
            }
        });

    } catch (RequestException ex) {
        setOnline(false);
        Log.error("An error occured while checking the connection state.", ex);
    }
}

From source file:org.sonar.api.web.gwt.client.webservices.JsonUtils.java

License:Open Source License

public static Boolean getBoolean(JSONObject json, String field) {
    JSONValue jsonValue;
    JSONBoolean jsonBoolean;// w w  w . j  a va2  s.  c om
    if ((jsonValue = json.get(field)) == null) {
        return null;
    }
    if ((jsonBoolean = jsonValue.isBoolean()) == null) {
        return null;
    }
    return jsonBoolean.booleanValue();
}

From source file:org.sonatype.nexus.gwt.ui.client.data.JSONResourceParser.java

License:Open Source License

private Object toObject(JSONValue json) {
    Object obj = null;/*from  w  ww  .  j  a  v  a  2 s.c  o m*/

    if (json instanceof JSONBoolean) {
        obj = Boolean.valueOf(json.isBoolean().booleanValue());
    } else if (json instanceof JSONString) {
        obj = json.isString().stringValue();
    } else if (json instanceof JSONNumber) {
        obj = new Double(json.isNumber().doubleValue());
    }

    return obj;
}

From source file:org.sonatype.nexus.gwt.ui.client.table.JSONArrayTableModel.java

License:Open Source License

public Object getCell(int rowIndex, int colIndex) {
    JSONObject obj = (JSONObject) getRow(rowIndex);

    JSONValue val = JSONUtil.getValue(obj, props[colIndex]);

    if (val != null) {
        if (val.isString() != null) {
            return val.isString().stringValue();
        } else if (val.isBoolean() != null) {
            return Boolean.valueOf(val.isBoolean().booleanValue());
        } else if (val.isNumber() != null) {
            return new Double(val.isNumber().doubleValue());
        } else if (val.isNull() != null) {
            return null;
        } else {//from  w  w w .ja v a  2 s  .co m
            return val;
        }
    }

    return null;
}

From source file:org.spiffyui.client.JSONUtil.java

License:Apache License

/**
 * Get a boolean from the JSON object or defaultValue if it doesn't exist or
 * isn't a boolean/*from w ww.  ja  va 2 s . c  om*/
 * 
 * @param obj    the object with the value
 * @param key    the key for the object 
 * @param defaultValue  the default value if the key can not be found  
 * 
 * @return the value or false it could not be decoded
 */
public static boolean getBooleanValue(JSONObject obj, String key, boolean defaultValue) {
    if (!obj.containsKey(key)) {
        return defaultValue;
    }

    JSONValue v = obj.get(key);
    if (v != null) {
        JSONBoolean b = v.isBoolean();
        if (b != null) {
            return b.booleanValue();
        } else {
            JSONString s = v.isString();
            if (s != null) {
                return Boolean.parseBoolean(s.stringValue());
            }
        }
    }

    return defaultValue;
}

From source file:org.talend.mdm.webapp.browserecords.client.rest.ExplainRestServiceHandler.java

License:Open Source License

private String getStringValue(JSONValue jsonValue) {
    String value = null;//from   w w  w . j a v  a  2s.  c  om
    if (jsonValue != null) {
        if (jsonValue.isString() != null) {
            value = jsonValue.isString().toString().replaceAll("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (jsonValue.isBoolean() != null) {
            value = jsonValue.isBoolean().toString();
        } else if (jsonValue.isNumber() != null) {
            value = jsonValue.isNumber().toString();
        }
    }
    return value;
}

From source file:org.utgenome.gwt.utgb.client.db.DatabaseTable.java

License:Apache License

public void setValue(int row, int column, JSONValue value) {
    if (value == null)
        return;// w w  w  . j a v a2s. c om

    DataType dataType = _relation.getDataType(column);

    JSONBoolean bool;
    if ((bool = value.isBoolean()) != null) {
        CheckBox cb = new CheckBox();
        cb.setValue(bool.booleanValue());
        _table.setWidget(row, column, cb);
    } else {
        _table.setText(row, column, dataType.toString(value));
    }
}

From source file:org.utgenome.gwt.utgb.client.db.datatype.BooleanType.java

License:Apache License

public String toString(JSONValue json) {
    JSONBoolean b = json.isBoolean();
    if (b == null)
        return super.toString(json);
    else//from  w  w w  .j  av  a  2s  .  co  m
        return b.booleanValue() ? "true" : "false";
}

From source file:org.waveprotocol.wave.client.gadget.renderer.GadgetMetadata.java

License:Apache License

/**
 * Helper function to extract a boolean value from given JSON object.
 *
 * @param json JSON object to extract the value from.
 * @param key key of the value to extract.
 * @return the Boolean object extracted from JSON (can be null if the value
 *         does not exist or is invalid.
 *//*ww w .ja va  2 s  .com*/
private static Boolean getJsonBooleanValue(JSONObject json, String key) {
    JSONValue value = json.get(key);
    JSONBoolean bool = (value == null) ? null : value.isBoolean();
    if (bool != null) {
        return bool.booleanValue();
    } else {
        return null;
    }
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.style.StyleDescriptorJSONParser.java

License:Open Source License

/**
 * Creates a new style descriptor from a JSON object representing a style descriptor.
 * /*  w  w  w.j av  a 2  s  .c  o  m*/
 * @param jsDescriptor a JSON object representing a style descriptor
 * @return a new style descriptor matching the given JSON object
 */
private StyleDescriptor createStyleDescriptor(JSONObject jsDescriptor) {
    JSONValue oName = jsDescriptor.get("name");
    if (oName == null) {
        return null;
    }
    JSONString sName = oName.isString();
    if (sName == null) {
        return null;
    }
    String name = sName.stringValue().trim();
    if (name.length() == 0) {
        return null;
    }
    JSONValue oLabel = jsDescriptor.get("label");
    JSONString sLabel = oLabel != null ? oLabel.isString() : null;
    String label = sLabel != null ? sLabel.stringValue().trim() : name;
    JSONValue inline = jsDescriptor.get("inline");
    JSONBoolean bInline = inline != null ? inline.isBoolean() : null;
    return new StyleDescriptor(name, label, bInline != null ? bInline.booleanValue() : true);
}