List of usage examples for com.google.gwt.json.client JSONValue isArray
public JSONArray isArray()
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);// ww w. j a va 2 s . c o m JSONValue val = jarr.get(i); if (val == null || val.isNumber() == null) { ctx.addBadTypeError("Number"); } ctx.pop(); // i } } } } }
From source file:com.ait.lienzo.client.core.shape.MultiPath.java
License:Open Source License
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); }// w w w.j a v a 2 s. com } } } } }
From source file:com.codenvy.ide.ext.java.jdt.internal.compiler.parser.Parser.java
License:Open Source License
private static String[] parseJsonArray(JSONValue value) { if (value.isObject() != null) { value = value.isObject().get("rsc").isArray(); }//from w ww .j a va 2 s . c om if (value.isArray() == null) throw new IllegalArgumentException("'json' parameter must represent a JSON array"); JSONArray array = value.isArray(); String result[] = new String[array.size()]; for (int i = 0; i < array.size(); i++) { result[i] = array.get(i).isNull() == null ? array.get(i).isString().stringValue() : null; } return result; }
From source file:com.data2semantics.yasgui.client.tab.optionbar.endpoints.EndpointDataSource.java
License:Open Source License
public void addEndpointsFromJson(String jsonString) throws Exception { JSONValue jsonVal = JSONParser.parseStrict(jsonString); if (jsonVal != null) { JSONArray endpoints = jsonVal.isArray(); if (endpoints != null) { for (int i = 0; i < endpoints.size(); i++) { JSONValue endpointVal = endpoints.get(i); if (endpointVal != null) { JSONObject endpoint = endpointVal.isObject(); if (endpoint != null) { addEndpointFromJson(endpoint); }/*from ww w. j a va2 s . c om*/ } } } } setCacheData(records.toArray(new ListGridRecord[records.size()])); }
From source file:com.data2semantics.yasgui.client.tab.results.input.JsonResults.java
License:Open Source License
/** * Gets JSON value as array, and throws exception when value is null * //from w w w . j av a2 s . c o m * @param jsonValue * @param message * @return * @throws SparqlParseException */ public JSONArray getAsArray(JSONObject jsonObject, String key) throws SparqlParseException { JSONValue jsonValue = jsonObject.get(key); if (jsonValue == null) { throw new SparqlParseException("Unable to get " + key + " as array"); } JSONArray result = jsonValue.isArray(); if (result == null) { throw new SparqlParseException("Unable to get " + key + " as array"); } return result; }
From source file:com.data2semantics.yasgui.client.View.java
License:Open Source License
/** * For a given endpoint, check whether it is defined in our endpoints datasource. * If it isnt, add it /*from www.j av a2 s . c o m*/ * * @param endpoint */ public void checkAndAddEndpointToDs(String endpoint) { if (!getSettings().inSingleEndpointMode()) { Record[] records = endpointDataSource.getCacheData(); boolean exists = false; for (Record record : records) { String recordEndpoint = record.getAttribute(Endpoints.KEY_ENDPOINT); if (recordEndpoint != null && recordEndpoint.equals(endpoint)) { exists = true; break; } } if (!exists) { //Ok, so endpoint is not in our datasource. let's add it ListGridRecord listGridRecord = new ListGridRecord(); listGridRecord.setAttribute(Endpoints.KEY_ENDPOINT, endpoint); Record[] newRecords = new Record[records.length + 1]; newRecords[0] = listGridRecord; System.arraycopy(records, 0, newRecords, 1, records.length); endpointDataSource = new EndpointDataSource(this, newRecords); if (Storage.isSupported()) { //we have html5. add it to local storage as well so we keep it persistent between sessions String endpointsJsonString = LocalStorageHelper.getEndpointsFromLocalStorage(); if (endpointsJsonString == null) { //There are no endpoints in our storage. //This is kinda strange, but lets create a json array with this new endpoint anyway JSONArray jsonArray = new JSONArray(); JSONObject newEndpointObject = new JSONObject(); newEndpointObject.put(Endpoints.KEY_ENDPOINT, new JSONString(endpoint)); jsonArray.set(0, newEndpointObject); LocalStorageHelper.setEndpoints(jsonArray.toString()); } else { //Prepend the new endpoint to the array in our json object JSONValue jsonVal = JSONParser.parseStrict(endpointsJsonString); if (jsonVal != null) { JSONArray endpoints = jsonVal.isArray(); JSONArray newEndpointsArray = new JSONArray(); JSONObject newEndpointObject = new JSONObject(); newEndpointObject.put(Endpoints.KEY_ENDPOINT, new JSONString(endpoint)); newEndpointsArray.set(0, newEndpointObject); if (endpoints != null) { for (int i = 0; i < endpoints.size(); i++) { newEndpointsArray.set(newEndpointsArray.size(), endpoints.get(i)); } } LocalStorageHelper.setEndpoints(newEndpointsArray.toString()); } } } } } }
From source file:com.dawg6.web.dhcalc.client.JsonUtil.java
License:Open Source License
public static <T extends Enum<T>> Set<T> parseSet(Class<T> clazz, String text) { if ((text == null) || (text.trim().length() == 0)) return null; Set<T> set = new TreeSet<T>(); JSONValue value = JSONParser.parseLenient(text); JSONArray array = value.isArray(); if (array == null) return null; for (int i = 0; i < array.size(); i++) { JSONValue e = array.get(i);/*from ww w . j ava 2s. c o m*/ if (e != null) { JSONString str = e.isString(); if (str != null) { String name = str.stringValue(); if (name != null) { T elem = Enum.valueOf(clazz, name); if (elem != null) { set.add(elem); } } } } } return set; }
From source file:com.dawg6.web.dhcalc.client.JsonUtil.java
License:Open Source License
public static Hero[] parseHeroList(String text) { if (text == null) { return new Hero[0]; } else {//from w ww .j a va 2s.c o m try { JSONValue value = JSONParser.parseLenient(text); JSONArray array = value.isArray(); if (array == null) return null; List<Hero> list = new Vector<Hero>(array.size()); for (int i = 0; i < array.size(); i++) { JSONValue e = array.get(i); if (e != null) { JSONObject obj = e.isObject(); if (obj != null) { Hero h = JsonUtil.toHero(obj); list.add(h); } } } return list.toArray(new Hero[0]); } catch (Exception e) { return new Hero[0]; } } }
From source file:com.dimdim.conference.ui.json.client.ResponseAndEventReader.java
License:Open Source License
public UIServerResponse readGetEventsResponse(JSONValue value) { JSONArray eventsArray = value.isArray(); UIServerResponse resp = null;/* w w w . j a v a 2s. c o m*/ if (eventsArray == null) { JSONObject obj = value.isObject(); //Window.alert("ResponseAndEventReader:readResponse value.isObject()?::"+obj); if (obj != null) { eventsArray = obj.isArray(); //Window.alert("ResponseAndEventReader:readResponse value.isArray()?::"+eventsArray); if (eventsArray == null) { // Read and make array out of it. We know this is an array. eventsArray = new JSONArray(); // String[] keys = obj.getKeys(); // for (int i=0; i<keys.length; i++) // { // eventsArray.add(obj.get(keys[i])); // } } } } //Window.alert("ResponseAndEventReader:readResponse array?::"+eventsArray); if (eventsArray != null) { //Window.alert("Reading array"); resp = new UIServerResponse(); resp.setSuccess(true); ArrayList aryList = new ArrayList(); int size = eventsArray.size(); for (int i = 0; i < size; i++) { JSONValue arrayMember = eventsArray.get(i); //Window.alert("Reading array member:"+arrayMember); Object data = readResponse(arrayMember); //Window.alert("Read array member:"+data); aryList.add(data); } resp.setArrayList(aryList); } // else if (obj != null) // { // resp = readResponse(value); // } return resp; }
From source file:com.dimdim.conference.ui.json.client.ResponseAndEventReader.java
License:Open Source License
public UIServerResponse readResponse(JSONValue value) { UIServerResponse resp = new UIServerResponse(); JSONObject obj = value.isObject();//from www . j av a 2s . c om //Window.alert("ResponseAndEventReader:readResponse::"+obj); // Window.alert("ResponseAndEventReader:readResponse::"+obj.isArray()); // Window.alert("ResponseAndEventReader:readResponse::"+obj.isObject()); if (obj != null) { // At present we use only object returns for all urls. //Window.alert("Reading non array return"); if (obj.containsKey(KEY_TYPE)) { // System.out.println("1"); String str = obj.get(KEY_TYPE).isString().stringValue();//.stringValue(); //Window.alert(KEY_TYPE+":"+str); if (str.equals(KEY_VALUE_SUCCESS) || str.equals(KEY_VALUE_EVENT) || str.equals(KEY_VALUE_MESSAGE)) { resp.setSuccess(true); } } if (obj.containsKey(KEY_FEATURE_ID)) { String featureId = obj.get(KEY_FEATURE_ID).isString().stringValue();//.stringValue(); //Window.alert(KEY_FEATURE_ID+":"+featureId); resp.setFeatureId(featureId); } if (obj.containsKey(KEY_EVENT_ID)) { String eventId = obj.get(KEY_EVENT_ID).isString().stringValue();//.stringValue(); //Window.alert(KEY_EVENT_ID+":"+eventId); resp.setEventId(eventId); } JSONValue v = obj.get(KEY_DATA); if (v != null) { //Window.alert(KEY_DATA+":"); if (obj.containsKey(KEY_DATA_TYPE)) { // Supported types are array, string and object. String dataType = obj.get(KEY_DATA_TYPE).isString().stringValue();//.stringValue(); //Window.alert(KEY_DATA_TYPE+":"+dataType); if (dataType.equals(KEY_VALUE_DATA_TYPE_OBJECT)) { Object data = readObject(obj.get(KEY_DATA).isObject()); resp.setData(data); } else if (dataType.equals(KEY_VALUE_DATA_TYPE_STRING)) { // Assume a simple string. String str = obj.get(KEY_DATA).toString(); resp.setData(str); } else if (dataType.equals(KEY_VALUE_DATA_TYPE_ARRAY)) { // Assume a simple string. //Window.alert(KEY_DATA+":v:"+v); JSONObject vo = v.isObject(); //Window.alert(KEY_DATA+":v:"+vo); JSONArray ary = v.isArray(); //Window.alert(KEY_DATA+":v:"+ary); if (ary == null && vo != null) { ary = vo.isArray(); } ArrayList aryList = new ArrayList(); if (ary != null) { int size = ary.size(); for (int i = 0; i < size; i++) { JSONObject jsonObj = ary.get(i).isObject(); Object data = readObject(jsonObj); aryList.add(data); } } resp.setArrayList(aryList); } else { //Window.alert("Unrecognized data type:"+dataType); } } } else { //Window.alert("No data found"); } } return resp; }