Example usage for com.google.gwt.json.client JSONArray get

List of usage examples for com.google.gwt.json.client JSONArray get

Introduction

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

Prototype

public native JSONValue get(int index) ;

Source Link

Document

Returns the value at the specified index position.

Usage

From source file:anzsoft.xmpp4gwt.client.xmpp.presence.PresencePlugin.java

License:Open Source License

public void doResume() {
    try {/*w  ww  .  j  a  v a2  s.  com*/
        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 w  w . j  av a 2  s.c om
        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 {/* w  ww  .  j a  va2 s .  com*/
        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./*  ww  w . j av a  2  s .c o 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.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 a2 s .  c  o  m
 */
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.options.LegendOptions.java

License:Open Source License

/**
 * @return the distance to the plot edge. The array can contains one value if the margin is applied to both x and y
 * axis or 2 values if the first one is applied to x axis and the second one to y axis.
 *///from  w  w  w  .j av  a 2 s. c om
public Double[] getMargin() {
    JSONValue value = get(MARGIN_KEY);
    if (value == null) {
        return null;
    }
    JSONNumber number = value.isNumber();
    if (null != number) {
        return new Double[] { number.doubleValue() };
    }
    JSONArray array = value.isArray();
    if (null != array) {
        return new Double[] { array.get(0).isNumber().doubleValue(), array.get(1).isNumber().doubleValue() };
    }
    return null;
}

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;
    }/*from  ww  w.j a  va2 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   w w w .j  a  v a  2 s .  com
    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);//from   w w  w  .  j a va2 s.c  o  m
    }
}

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  w  w w.  j av  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);
            }
        }

    });
}