List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java
License:Apache License
/** * Creates a WjrClassItem from Json string. * //from w w w . j a va 2s.c o m * @param jsonString * the Json string. * @return the created WjrClassItem instance. */ WjrClassItem createWjrClassItemFromJson(String jsonString) { WjrClassItemMeta m = WjrClassItemMeta.meta(); JSONValue j = JSONParser.parseStrict(jsonString); return new WjrClassItem(j.isObject().get(m.className).isString().stringValue()); }
From source file:ca.nanometrics.gflot.client.options.GridOptions.java
License:Open Source License
/** * @return the background color inside the grid area. The array can contains one color or two colors if it's a * gradient/*from w w w . j a v a 2s . c om*/ */ public String[] getBackgroundColor() { JSONValue value = get(BACKGROUND_COLOR_KEY); if (value == null) { return null; } JSONString str = value.isString(); if (null != str) { return new String[] { str.stringValue() }; } JSONObject obj = value.isObject(); if (null != obj) { JSONValue colors = obj.get(BACKGROUND_COLORS_KEY); JSONArray array = colors.isArray(); if (null != array) { return new String[] { array.get(0).isString().stringValue(), array.get(1).isString().stringValue() }; } } return null; }
From source file:ca.nanometrics.gflot.client.util.JSONArrayWrapper.java
License:Open Source License
protected JSONObject getObject(int index) { JSONValue value = get(index); if (value == null) { return null; }//from www . j ava 2 s . c om return value.isObject(); }
From source file:ca.nanometrics.gflot.client.util.JSONObjectWrapper.java
License:Open Source License
protected JSONObject getObject(String key) { JSONValue value = get(key); if (value == null) { return null; }// w ww . j ava 2 s .c om return value.isObject(); }
From source file:cc.kune.core.client.sitebar.search.MultivalueSuggestBox.java
License:GNU Affero Public License
/** * Retrieve Options (name-value pairs) that are suggested from the REST * endpoint/*from w w w . ja v a 2 s . co m*/ * * @param query * - the String search term * @param from * - the 0-based begin index int * @param to * - the end index inclusive int * @param callback * - the OptionQueryCallback to handle the response */ private void queryOptions(final String query, final int from, final int to, final OptionQueryCallback callback) { final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(mrestEndpointUrl + "?" + SearcherConstants.QUERY_PARAM + "=" + query + "&" + SearcherConstants.START_PARAM + "=" + from + "&" + SearcherConstants.LIMIT_PARAM + "=" + PAGE_SIZE)); // Set our headers builder.setHeader("Accept", "application/json; charset=utf-8"); // Fails on chrome // builder.setHeader("Accept-Charset", "UTF-8"); builder.setCallback(new RequestCallback() { @Override public void onError(final com.google.gwt.http.client.Request request, final Throwable exception) { callback.error(exception); } @Override public void onResponseReceived(final com.google.gwt.http.client.Request request, final Response response) { final JSONValue val = JSONParser.parse(response.getText()); final JSONObject obj = val.isObject(); final int totSize = (int) obj.get(OptionResultSet.TOTAL_SIZE).isNumber().doubleValue(); final OptionResultSet options = new OptionResultSet(totSize); final JSONArray optionsArray = obj.get(OptionResultSet.OPTIONS).isArray(); if (options.getTotalSize() > 0 && optionsArray != null) { for (int i = 0; i < optionsArray.size(); i++) { if (optionsArray.get(i) == null) { /* * This happens when a JSON array has an invalid trailing comma */ continue; } final JSONObject jsonOpt = optionsArray.get(i).isObject(); final Option option = new Option(); final String longName = jsonOpt.get(OptionResultSet.DISPLAY_NAME).isString().stringValue(); final String shortName = jsonOpt.get(OptionResultSet.VALUE).isString().stringValue(); final JSONValue groupTypeJsonValue = jsonOpt.get("groupType"); final String prefix = groupTypeJsonValue.isString() == null ? "" : GroupType.PERSONAL.name().equals(groupTypeJsonValue.isString().stringValue()) ? I18n.t("User") + ": " : I18n.t("Group") + ": "; option.setName(prefix + (!longName.equals(shortName) ? longName + " (" + shortName + ")" : shortName)); option.setValue(jsonOpt.get(OptionResultSet.VALUE).isString().stringValue()); options.addOption(option); } } callback.success(options); } }); try { if (lastQuery != null && lastQuery.isPending()) { lastQuery.cancel(); } lastQuery = builder.send(); } catch (final RequestException e) { updateFormFeedback(FormFeedback.ERROR, "Error: " + e.getMessage()); } }
From source file:ccc.client.gwt.core.GWTJson.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w . ja v a 2 s.co m*/ public Json getJson(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 new GWTJson(value.isObject()); }
From source file:ccc.client.gwt.core.GWTJson.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w . j ava2 s . 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: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 w w. j a v a2 s . c om*/ 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 array of json objects, it transforms them in a list of Hashes * @param values the result to parse//from w w w . j ava2s . co m * @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 w w w . ja v a 2s. 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; }