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:org.nuxeo.ecm.platform.gwt.client.model.Document.java

License:Open Source License

public boolean getBooleanProperty(String schema, String property, boolean defaultValue) {
    JSONValue v = getProperty(schema, property);
    if (v != null && v.isString() != null) {
        return v.isBoolean().booleanValue();
    }//from w ww  . j av a 2 s .  co  m
    return defaultValue;
}

From source file:org.nuxeo.ecm.platform.gwt.client.model.Document.java

License:Open Source License

public double getNumberProperty(String schema, String property, double defaultValue) {
    JSONValue v = getProperty(schema, property);
    if (v != null && v.isString() != null) {
        return v.isNumber().doubleValue();
    }//from   ww  w . j a va 2  s.c  o m
    return defaultValue;
}

From source file:org.nuxeo.ecm.platform.gwt.client.model.JSONWrapper.java

License:Open Source License

protected String getString(String key) {
    if (json != null) {
        JSONValue value = json.get(key);
        if (value != null && value.isString() != null) {
            return value.isString().stringValue();
        }//from w ww  .  java2  s.  c  om
    }
    return null;
}

From source file:org.nuxeo.ecm.platform.gwt.client.model.JSONWrapper.java

License:Open Source License

protected String[] getStringArray(JSONObject obj, String key) {
    if (obj != null) {
        JSONValue value = obj.get(key);/*from  w w w . ja v a2s .  c o  m*/
        if (value != null && value.isArray() != null) {
            JSONArray array = value.isArray();
            int size = array.size();
            String[] ret = new String[size];
            for (int i = 0; i < size; i++) {
                JSONValue v = array.get(i);
                if (v != null && v.isString() != null) {
                    ret[i] = v.isString().stringValue();
                } else {
                    ret[i] = "";
                }
            }
            return ret;
        }
    }
    return null;
}

From source file:org.onebusaway.webapp.gwt.common.rpc.JsonLibrary.java

License:Apache License

public static String getJsonString(JSONObject object, String key) {
    JSONValue value = object.get(key);
    if (value == null)
        return null;
    JSONString string = value.isString();
    if (string == null)
        return null;
    return string.stringValue();
}

From source file:org.opencms.acacia.client.widgets.complex.CmsDataViewClientWidget.java

License:Open Source License

/**
 * Creates the correct widget based on the configuration.<p>
 *
 * @return the new widget/*from  w  w  w . j a v a 2 s .c  o  m*/
 */
Widget createWidget() {

    if (isTrue(m_jsonConfig, CmsDataViewConstants.CONFIG_PREVIEW)) {
        return new CmsDataViewPreviewWidget(m_config, m_valueAccessor,
                new CmsDataViewPreviewWidget.ContentImageLoader());
    } else {
        I_ImageProvider provider = null;
        CmsDataViewValue val = m_valueAccessor.getValue();
        JSONValue iconVal = m_jsonConfig.get(CmsDataViewConstants.CONFIG_ICON);
        if ((iconVal != null) && (iconVal.isString() != null)) {
            provider = new CmsDataViewPreviewWidget.SimpleImageLoader(iconVal.isString().stringValue());
        }
        return new CmsDataViewPreviewWidget(m_config, m_valueAccessor, provider);
    }

}

From source file:org.opencms.acacia.client.widgets.complex.CmsDataViewClientWidget.java

License:Open Source License

/**
 * Checks if a property in a JSON object is either the boolean value 'true' or a string representation of that value.<p>
 *
 * @param obj the JSON object//w  w  w. j  av a  2s.co m
 * @param property the property name
 * @return true if the value represents the boolean 'true'
 */
private boolean isTrue(JSONObject obj, String property) {

    JSONValue val = obj.get(property);
    if (val == null) {
        return false;
    }
    boolean stringTrue = ((val.isString() != null) && Boolean.parseBoolean(val.isString().stringValue()));
    boolean boolTrue = ((val.isBoolean() != null) && val.isBoolean().booleanValue());
    return stringTrue || boolTrue;
}

From source file:org.opencms.ade.sitemap.client.alias.CmsClientAliasImportResult.java

License:Open Source License

/**
 * Helper method to get a string value from a JSON object.<p>
 *
 * @param json the JSON object// ww w.j av  a2 s .c om
 * @param key the key whose value should be extracted as a string
 *
 * @return the string value for the given key
 */
protected static String getString(JSONObject json, String key) {

    JSONValue value = json.get(key);
    JSONString str = value.isString();
    if (str == null) {
        return null;
    }
    return str.stringValue();
}

From source file:org.openehealth.ipf.platform.camel.flow.admin.client.JSONUtil.java

License:Apache License

public static List<String> toStringList(JSONArray array) {
    List<String> list = new ArrayList<String>(array.size());
    for (int idx = 0; idx < array.size(); ++idx) {
        JSONValue jsonValue = array.get(idx);
        JSONString jsonString = jsonValue.isString();
        if (jsonString == null) {
            throw new AssertionError("JSON value is not a string");
        }//ww  w  .  jav  a  2  s  . c  om
        list.add(jsonString.stringValue());
    }
    return list;
}

From source file:org.openremote.modeler.client.gxtextends.NestedJsonLoadResultReader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//www  .  ja va 2  s . c  o m
public D read(Object loadConfig, Object data) {
    JSONObject jsonRoot = null;
    if (data instanceof JavaScriptObject) {
        jsonRoot = new JSONObject((JavaScriptObject) data);
    } else {
        jsonRoot = (JSONObject) JSONParser.parse((String) data);
    }

    // You can specify root using dot separate. eg, vendors.vendor 
    String[] roots = myModelType.getRoot().split("\\.");
    JSONValue rootValue = null;
    JSONArray root = null;
    for (int i = 0; i < roots.length; i++) {
        rootValue = jsonRoot.get(roots[i]);
        if (i == roots.length - 1) {
            if (rootValue instanceof JSONObject) {
                root = new JSONArray();
                root.set(0, rootValue);
            } else {
                root = (JSONArray) rootValue;
            }
        } else {
            jsonRoot = (JSONObject) jsonRoot.get(roots[i]);
        }
    }

    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 < myModelType.getFieldCount(); j++) {
            DataField field = myModelType.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 {
                    // convert no type number to string.
                    model.set(name, value.isNumber().toString());
                }
            } 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 (field.getFormat().equals("timestamp")) {
                            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 (myModelType.getTotalName() != null) {
        totalCount = getTotalCount(jsonRoot);
    }
    return (D) createReturnData(loadConfig, models, totalCount);
}