Example usage for com.google.gwt.json.client JSONObject keySet

List of usage examples for com.google.gwt.json.client JSONObject keySet

Introduction

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

Prototype

public Set<String> keySet() 

Source Link

Document

Returns the set of properties defined on this JSONObject.

Usage

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

License:Open Source License

/** {@inheritDoc} */
@Override//from ww w.jav a2s .  co  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:ccc.client.gwt.core.GWTTextParser.java

License:Open Source License

/** {@inheritDoc} */
@Override/*w w  w. ja  v  a 2 s .c o m*/
public Map<String, String> parseStringMap(final String text) {
    final JSONObject result = JSONParser.parse(text).isObject();
    final Map<String, String> map = new HashMap<String, String>();
    for (final String key : result.keySet()) {
        map.put(key, result.get(key).isString().stringValue());
    }
    return map;
}

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

License:Open Source License

/**
 * Assuming a json object, parses the result and returns as a Hash
 * @param result/*  ww  w .  ja  v a2s. c  o  m*/
 * @return a Hash with key value pairs (all Strings)
 */
public static Map<String, String> getValueFromResult(AjaxData result) {
    JSONObject values = new JSONObject(result.getValues());
    Map<String, String> output = new HashMap<String, String>();
    for (String key2 : values.keySet()) {
        if (values.get(key2) != null && values.get(key2).isString() != null)
            output.put(key2, values.get(key2).isString().stringValue());
        else
            output.put(key2, values.get(key2).toString());
    }
    return output;
}

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

License:Open Source License

/**
 * Assuming a json array of json objects, it transforms them in a list of Hashes
 * @param values the result to parse/* w  w  w.j  a  v  a  2s. com*/
 * @return a List of Hash with String key value pairs
 */
public static List<Map<String, String>> getValuesFromResult(JSONObject values) {
    List<Map<String, String>> output = new ArrayList<Map<String, String>>();
    for (String key : values.keySet()) {
        JSONValue student = values.get(key);
        JSONObject starr = student.isObject();
        Map<String, String> obj = new HashMap<String, String>();
        for (String key2 : starr.keySet()) {
            if (starr.get(key2) != null && starr.get(key2).isString() != null)
                obj.put(key2, starr.get(key2).isString().stringValue());
            else
                obj.put(key2, starr.get(key2).toString());
        }
        output.add(obj);
    }
    return output;
}

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

License:Open Source License

/**
 * Assuming a String, parses the result and returns as a Hash
 * @param result//from ww  w  . ja v a 2  s  .  c  o m
 * @return a Hash with key value pairs (all Strings)
 */
public static Map<String, String> getValueFromResultString(String result) {
    JSONValue jsonValue;
    JSONObject values;

    jsonValue = JSONParser.parseStrict(result);
    values = jsonValue.isObject();

    Map<String, String> output = new HashMap<String, String>();
    for (String key2 : values.keySet()) {
        if (values.get(key2) != null && values.get(key2).isString() != null)
            output.put(key2, values.get(key2).isString().stringValue());
        else
            output.put(key2, values.get(key2).toString());
    }

    return output;
}

From source file:cl.webcursos.salas.client.AjaxRequest.java

License:Open Source License

/**
 * Assuming a json object, parses the result and returns as a Hash
 * @param result/*w w  w  . ja  va  2 s .  c  o  m*/
 * @return a Hash with key value pairs (all Strings)
 */
public static Map<String, String> getValueFromResult(AjaxData result) {
    JSONObject values = new JSONObject(result.getValues());
    Map<String, String> output = new HashMap<String, String>();
    for (String key2 : values.keySet()) {
        if (values.get(key2) != null && values.get(key2).isString() != null)
            output.put(key2, values.get(key2).isString().stringValue());
        else
            output.put(key2, values.get(key2).toString());
    }

    return output;
}

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

License:Open Source License

protected final void validateAttributes(JSONObject json, IFactory<?> factory, String type,
        ValidationContext ctx) throws ValidationException {
    JSONValue aval = json.get("attributes");

    if (null == aval) {
        return; // OK - 'attributes' is optional
    }//w  w  w .  j  av a  2  s.  co m
    ctx.push("attributes");

    JSONObject aobj = aval.isObject();

    if (aobj == null) {
        ctx.addBadTypeError("Object");

        return;
    } else {
        // Make sure all required attributes are defined (and not null)

        Set<String> keys = aobj.keySet();

        for (Attribute attr : factory.getRequiredAttributes()) {
            String attrName = attr.getProperty();

            ctx.push(attrName);

            if (false == keys.contains(attrName)) {
                ctx.addRequiredError(); // value is missing
            } else {
                JSONValue jval = aobj.get(attrName);

                if (((jval == null) || (jval.isNull() != null))) {
                    ctx.addRequiredError(); // value is null
                }
            }
            ctx.pop(); // attrName
        }
        // Now check the attribute values

        for (String attrName : keys) {
            ctx.push(attrName);

            AttributeType atyp = factory.getAttributeType(attrName);

            if (atyp == null) {
                ctx.addInvalidAttributeError(type);
            } else {
                atyp.validate(aobj.get(attrName), ctx);
            }
            ctx.pop(); // attrName
        }
    }
    ctx.pop(); // attributes
}

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

License:Open Source License

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

        return;//from w w w . j  ava  2  s  .co m
    }
    JSONObject jobj = jval.isObject();

    if (null == jobj) {
        ctx.addBadTypeError("BoundingBox");
    } else {
        Set<String> keys = jobj.keySet();

        if (keys.isEmpty()) {
            ctx.addBadTypeError("BoundingBox no keys");

            return;
        }
        for (String ikey : keys) {
            if ((null == ikey) || (ikey.trim().isEmpty())) {
                ctx.addBadTypeError("BoundingBox bad key");

                return;
            }
            jval = jobj.get(ikey);

            if (null == jval) {
                ctx.addBadTypeError("BoundingBox no array");

                return;
            }
            JSONArray jarr = jval.isArray();

            if (null == jarr) {
                ctx.addBadTypeError("BoundingBox not array");

                return;
            }
            if (jarr.size() < 2) {
                ctx.addBadArraySizeError(2, jarr.size());

                return;
            }
            BoundingBoxArrayValidator.INSTANCE.validate(jarr, ctx);
        }
    }
}

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

License:Open Source License

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

        return;/*from w w  w .  j  av  a  2  s  .co  m*/
    }
    JSONObject jobj = jval.isObject();

    if (null == jobj) {
        ctx.addBadTypeError("Object");
    } else {
        Set<String> keys = jobj.keySet();

        // Check required attributes

        for (String attrName : m_requiredAttributes) {
            ctx.push(attrName);

            if (false == keys.contains(attrName)) {
                ctx.addRequiredError(); // value is missing
            } else {
                JSONValue aval = jobj.get(attrName);

                if ((null == aval) || (null != aval.isNull())) {
                    ctx.addRequiredError(); // value is null
                }
            }
            ctx.pop(); // attrName
        }
        // Now check the attribute values

        for (String attrName : keys) {
            ctx.push(attrName);

            IAttributeTypeValidator validator = m_attributes.get(attrName);

            if (null == validator) {
                ctx.addInvalidAttributeError(m_typeName);
            } else if (false == (validator instanceof IgnoreTypeValidator)) {
                JSONValue aval = jobj.get(attrName);

                validator.validate(aval, ctx);
            }
            ctx.pop(); // attrName
        }
    }
}

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

License:Open Source License

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

        return;//from   ww  w .j  a  v  a2  s. c om
    }
    final JSONObject jobj = jval.isObject();

    if (null == jobj) {
        ctx.addBadTypeError(getTypeName());
    } else {
        final Set<String> keys = jobj.keySet();

        if (keys.isEmpty()) {
            ctx.addBadTypeError(getTypeName() + ": empty behavior keys");

            return;
        }
        for (String ikey : keys) {
            final String akey = StringOps.toTrimOrNull(ikey);

            if (null == akey) {
                ctx.addBadTypeError(getTypeName() + ": empty behavior name");

                return;
            }
            final JSONValue ival = jobj.get(akey);

            if (null == ival) {
                ctx.addBadTypeError(getTypeName() + ": missing behavior array for " + akey);

                return;
            }
            final JSONArray jarr = ival.isArray();

            if (null == jarr) {
                ctx.addBadTypeError(getTypeName() + ": invalid behavior array for " + akey);

                return;
            }
            if (jarr.size() < 2) {
                ctx.addBadArraySizeError(2, jarr.size());

                return;
            }
            BoundingBoxArrayValidator.INSTANCE.validate(jarr, ctx);
        }
    }
}