List of usage examples for com.google.gwt.json.client JSONArray size
public native int size() ;
From source file:anzsoft.xmpp4gwt.client.xmpp.presence.PresencePlugin.java
License:Open Source License
public void doResume() { try {//from ww w . j a va2s .c o m final String prefix = Session.instance().getUser().getStorageID(); Storage storage = Storage.createStorage(STORAGEKEY, prefix); if (storage == null) return; //get self presence String showStr = storage.get(STORAGE_CURRENTSHOW); if (showStr != null && !(showStr.length() == 0)) currentShow = Show.valueOf(showStr); String priorityStr = storage.get(STORAGE_PRIORITY); if (priorityStr != null && !(priorityStr.length() == 0)) priority = Integer.valueOf(priorityStr); String initStr = storage.get(STORAGE_INIT_PRESENCE); if (initStr != null) initialPresenceSended = initStr.equals("true"); //get presence data String data = storage.get("data"); if (data == null) return; JSONArray jPresences = JSONParser.parse(data).isArray(); if (jPresences == null) return; for (int index = 0; index < jPresences.size(); index++) { String packetStr = jPresences.get(index).isString().stringValue(); if (packetStr == null || packetStr.length() == 0) continue; final Packet pPacket = parse(packetStr); process(pPacket); } } catch (Exception e) { System.out.println(e.toString()); } }
From source file:anzsoft.xmpp4gwt.client.xmpp.roster.RosterItem.java
License:Open Source License
public void fromJsonObject(JSONObject object) { try {//from w ww . j a v a2s . c o m this.jid = object.get("jid").isString().stringValue(); if (object.get("name") != null) this.name = object.get("name").isString().stringValue(); this.subscription = Subscription.valueOf(object.get("subscription").isString().stringValue()); this.ask = object.get("ask").isString().stringValue().equals("true") ? true : false; JSONArray jGroup = object.get("groups").isArray(); if (jGroup != null) { this.groups = new String[jGroup.size()]; for (int index = 0; index < jGroup.size(); index++) { this.groups[index] = jGroup.get(index).isString().stringValue(); } } if (object.get("order") != null) this.order = object.get("order").isString().stringValue(); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:anzsoft.xmpp4gwt.client.xmpp.roster.RosterPlugin.java
License:Open Source License
public boolean resume() { try {//ww w.j a v a 2 s . c o m final String prefix = Session.instance().getUser().getStorageID(); Storage storage = Storage.createStorage(STORAGEKEY, prefix); String indexString = storage.get("index"); if (indexString == null) return false; JSONArray jRoster = JSONParser.parse(indexString).isArray(); if (jRoster == null) return false; rosterItemsByBareJid.clear(); for (int index = 0; index < jRoster.size(); index++) { String jid = jRoster.get(index).isString().stringValue(); if (jid == null || jid.length() == 0) continue; String objectString = storage.get(jid); if (objectString == null || objectString.length() == 0) continue; JSONObject object = JSONParser.parse(objectString).isObject(); if (object == null) continue; RosterItem ri = new RosterItem(); ri.fromJsonObject(object); rosterItemsByBareJid.put(ri.getJid(), ri); } this.rosterReceived = true; Iterator<RosterItem> iterator = this.rosterItemsByBareJid.values().iterator(); while (iterator.hasNext()) { RosterItem ri = iterator.next(); this.fireAddRosterItem(ri); } } catch (Exception e) { System.out.println(e.toString()); } return true; }
From source file:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java
License:Apache License
/** * Creates a WjrStore from Json string.//w w w . j a va 2 s . co m * * @param jsonString * the Json string. * @return the created WjrStore instance. */ WjrStore createWjrStoreFromJson(String jsonString) { WjrStoreMeta m = WjrStoreMeta.meta(); WjrStore wjrStore = new WjrStore(); JSONObject j = JSONParser.parseStrict(jsonString).isObject(); JSONArray classItems = j.get(m.classItems).isArray(); int classItemsSize = classItems.size(); for (int i = 0; i < classItemsSize; i++) { wjrStore.addClassItem(createWjrClassItemFromJson(classItems.get(i).toString())); } JSONArray methodItems = j.get(m.methodItems).isArray(); int methodItemsSize = methodItems.size(); for (int i = 0; i < methodItemsSize; i++) { wjrStore.addMethodItem(createWjrMethodItemFromJson(methodItems.get(i).toString())); } return wjrStore; }
From source file:ca.nanometrics.gflot.client.util.JSONObjectWrapper.java
License:Open Source License
protected String[] getStringArray(String key) { JSONArray array = getArray(key); if (array == null) { return null; }// w ww .j a v a 2 s .c o m String[] result = new String[array.size()]; for (int i = 0; i < array.size(); i++) { JSONString value = array.get(i).isString(); if (null != value) { result[i] = value.stringValue(); } } return result; }
From source file:ca.nanometrics.gflot.client.util.JSONObjectWrapper.java
License:Open Source License
protected Integer[] getIntegerArray(String key) { JSONArray array = getArray(key); if (array == null) { return null; }//from www .j a v a 2s. c o m Integer[] result = new Integer[array.size()]; for (int i = 0; i < array.size(); i++) { JSONNumber value = array.get(i).isNumber(); if (null != value) { result[i] = (int) value.doubleValue(); } } return result; }
From source file:ca.upei.ic.timetable.client.CourseModelView.java
License:Apache License
public void loadJSON(JSONValue value) { JSONArray array = (JSONArray) value; // load the values for (int i = 0; i < array.size(); i++) { // set value and name JSONObject o = (JSONObject) array.get(i); int id = (int) ((JSONNumber) o.get("id")).doubleValue(); addCourse(id, o, false);/* w ww . j a v a2s . c om*/ } }
From source file:ca.upei.ic.timetable.client.CourseViewController.java
License:Apache License
public void search() { JSONObject department = new JSONObject(); for (String d : departmentCriteria_.keySet()) { if (departmentCriteria_.get(d)) { department.put(d, JSONBoolean.getInstance(true)); }//from www.jav a 2 s . c o m } JSONObject level = new JSONObject(); for (String l : levelCriteria_.keySet()) { if (levelCriteria_.get(l)) { level.put(l, JSONBoolean.getInstance(true)); } } JSONObject semester = new JSONObject(); for (String s : semesterCriteria_.keySet()) { if (semesterCriteria_.get(s)) semester.put(s, JSONBoolean.getInstance(true)); } JSONObject value = new JSONObject(); value.put("department", department); value.put("level", level); value.put("semester", semester); value.put("day", new JSONString(courseDay_)); value.put("startTime", new JSONString(courseStartTime_)); Service.defaultInstance().askCourses(value.toString(), new RequestCallback() { public void onError(Request request, Throwable exception) { app_.error(ApplicationController.OOPS, exception); } public void onResponseReceived(Request request, Response response) { try { JSONArray parsedArray = (JSONArray) JSONParser.parse(response.getText()); // remove the selected courses // filtered array JSONArray filteredArray = new JSONArray(); int filtered_index = 0; for (int i = 0; i < parsedArray.size(); i++) { JSONObject o = (JSONObject) parsedArray.get(i); int id = (int) ((JSONNumber) o.get("id")).doubleValue(); if (!isSelected(id)) { filteredArray.set(filtered_index++, o); } } // clear out the view so we can add courses view_.clear(); // add the selected values first for (int index : selectionIndexes_) { view_.addCourse(index, selectionValues_.get(index), true); } // add the remaining courses view_.loadJSON(filteredArray); } catch (Throwable e) { app_.error("Error: " + response.getText(), e); } } }); }
From source file:ca.upei.ic.timetable.client.DepartmentModelView.java
License:Apache License
public void loadJSON(JSONValue value) { JSONArray array = (JSONArray) value; // iterate all json results for (int i = 0; i < array.size(); i++) { JSONString s = (JSONString) array.get(i); CheckBox box = new CheckBox(s.stringValue()); box.setName(s.stringValue());/* w w w .j a v a 2 s .c o m*/ // add the click listener box.addClickListener(new ClickListener() { public void onClick(Widget sender) { final CheckBox box = (CheckBox) sender; final String name = box.getName(); controller_.setDepartmentCriteria(name, box.isChecked()); } }); panel_.add(box); } }
From source file:ca.upei.ic.timetable.client.LevelModelView.java
License:Apache License
public void loadJSON(JSONValue value) { JSONArray array = (JSONArray) value; // load the values for (int i = 0; i < array.size(); i++) { // set value and name JSONString s = (JSONString) array.get(i); CheckBox box = new CheckBox("Level " + s.stringValue()); box.setName(s.stringValue()); // to store the value box.setChecked(true);/*from w w w. j a v a 2s . c o m*/ controller_.setLevelCriteria(s.stringValue(), true); // add click listener box.addClickListener(new ClickListener() { public void onClick(Widget sender) { final CheckBox box = (CheckBox) sender; final String name = box.getName(); controller_.setLevelCriteria(name, box.isChecked()); } }); panel_.add(box); } }