List of usage examples for com.google.gwt.json.client JSONValue isNumber
public JSONNumber isNumber()
From source file:com.ait.lienzo.client.core.shape.json.validators.NumberValidator.java
License:Open Source License
@Override public void validate(JSONValue jval, ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError("Number"); return;//from w w w . ja va 2 s .co m } JSONNumber s = jval.isNumber(); if (null == s) { ctx.addBadTypeError("Number"); } if (false == isNumber(s.doubleValue())) { ctx.addBadTypeError("Number"); } }
From source file:com.ait.lienzo.client.core.shape.json.validators.TransformValidator.java
License:Open Source License
@Override public void validate(JSONValue jval, ValidationContext ctx) throws ValidationException { super.validate(jval, ctx); if (null != jval) { JSONArray jarr = jval.isArray(); if (null != jarr) { if (jarr.size() != 6) { ctx.addBadArraySizeError(6, jarr.size()); } else { for (int i = 0; i < 6; i++) { ctx.pushIndex(i);// w ww . j av a 2s. c o m JSONValue val = jarr.get(i); if (val == null || val.isNumber() == null) { ctx.addBadTypeError("Number"); } ctx.pop(); // i } } } } }
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 w ww . j a v a 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.blockwithme.util.client.webworkers.thread.impl.WebWorkerLogHandler.java
License:Apache License
/** Reads LogRecord from a JSONObject. */ public static LogRecord fromJSONObject(final JSONObject json) { if (json == null) { return null; }/*from w w w . j a v a2 s.c om*/ Level level = Level.INFO; String loggerName = ""; String message = null; long millis = 0; String thrown_type = null; final JSONValue levelValue = json.get("level"); if ((levelValue != null) && (levelValue.isString() != null)) { try { level = Level.parse(levelValue.isString().stringValue()); } catch (final Throwable t) { // NOP } } final JSONValue loggerNameValue = json.get("loggerName"); if ((loggerNameValue != null) && (loggerNameValue.isString() != null)) { loggerName = loggerNameValue.isString().stringValue(); } final JSONValue messageValue = json.get("message"); if ((messageValue != null) && (messageValue.isString() != null)) { message = messageValue.isString().stringValue(); } final JSONValue millisValue = json.get("millis"); if ((millisValue != null) && (millisValue.isNumber() != null)) { millis = (long) millisValue.isNumber().doubleValue(); } final JSONValue thrown_typeValue = json.get("thrown_type"); if ((thrown_typeValue != null) && (thrown_typeValue.isString() != null)) { thrown_type = thrown_typeValue.isString().stringValue(); } final LogRecord result = new LogRecord(level, message); result.setLoggerName(loggerName); result.setMillis(millis); if (thrown_type != null) { final JSONValue thrown_msgValue = json.get("thrown_msg"); String thrown_msg = null; if ((thrown_msgValue != null) && (thrown_msgValue.isString() != null)) { thrown_msg = thrown_msgValue.isString().stringValue(); } result.setThrown(new JsonLogRecordThrowable(thrown_type, thrown_msg)); } else if ((message == null) || message.isEmpty()) { return null; } return result; }
From source file:com.eduworks.gwt.client.net.packet.AjaxPacket.java
License:Apache License
public Integer getInteger(String key) { JSONValue jv; try {/* ww w. j a v a 2 s . c o m*/ jv = super.get(key); } catch (NullPointerException e) { return null; } if (jv != null && jv.isNumber() != null) return Integer.parseInt(String.valueOf(jv.isNumber().doubleValue())); return null; }
From source file:com.eduworks.gwt.client.net.packet.AjaxPacket.java
License:Apache License
public Double getDouble(String key) { JSONValue jv; try {/*w w w .ja va 2 s . c om*/ jv = super.get(key); } catch (NullPointerException e) { return null; } if (jv != null && jv.isNumber() != null) return (Double) jv.isNumber().doubleValue(); 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;//w ww. jav 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.data.JsonReader.java
License:sencha.com license
protected int getTotalCount(JSONObject root) { if (modelType.getTotalName() != null) { JSONValue v = root.get(modelType.getTotalName()); if (v != null) { if (v.isNumber() != null) { return (int) v.isNumber().doubleValue(); } else if (v.isString() != null) { return Integer.parseInt(v.isString().stringValue()); }/*w w w. ja v a2 s . com*/ } } return -1; }
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 va2 s . co 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.github.gilbertotorrezan.gwtcloudinary.client.CloudinaryUploadWidget.java
License:Open Source License
private Integer getSafeInteger(JSONValue value) { if (value == null) { return null; }//from w w w .j a v a 2 s . c o m JSONNumber number = value.isNumber(); if (number == null) { return null; } return (int) number.doubleValue(); }