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

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

Introduction

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

Prototype

public JSONValue get(String key) 

Source Link

Document

Gets the JSONValue associated with the specified property.

Usage

From source file:anzsoft.xmpp4gwt.client.User.java

License:Open Source License

public boolean resume() {
    String cookie = Cookies.getCookie(COOKIENAME);
    if (cookie == null || cookie.length() == 0)
        return false;
    JSONObject jUser = JSONParser.parse(cookie).isObject();
    if (jUser == null)
        return false;

    this.username = jUser.get(STORAGE_USERNAME).isString().stringValue();
    this.domainname = jUser.get(STORAGE_DOMAIN).isString().stringValue();
    //this.password = jUser.get("password").isString().stringValue();  
    //jUser.put("priority", new JSONString(String.valueOf(priority)));
    this.resource = jUser.get(STORAGE_RESOURCE).isString().stringValue();
    this.priority = Integer.parseInt(jUser.get(STORAGE_PRIORITY).isString().stringValue());
    Cookies.removeCookie(COOKIENAME);/* w ww .ja  v  a  2 s.  c o  m*/
    if (username.length() == 0 || domainname.length() == 0)
        return false;
    return true;
}

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 a  v  a  2 s.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:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java

License:Apache License

/**
 * Creates a WjrConfig from Json string.
 * //from   w  w  w.  jav  a  2  s.c o  m
 * @param jsonString
 *          the Json string.
 * @return the created WjrConfig instance.
 */
WjrConfig createWjrConfigFromJson(String jsonString) {
    WjrConfigMeta m = WjrConfigMeta.meta();
    WjrConfig wjrConfig = new WjrConfig();

    JSONObject j = JSONParser.parseStrict(jsonString).isObject();
    wjrConfig.setConfigId(j.get(m.configId).isString().stringValue());
    wjrConfig.setConfigName(j.get(m.configName).isString().stringValue());
    wjrConfig.setCpumsEnabled(j.get(m.cpumsEnabled).isString().stringValue());
    wjrConfig.setApimsEnabled(j.get(m.apimsEnabled).isString().stringValue());
    wjrConfig.setLogHookEnabled(j.get(m.logHookEnabled).isString().stringValue());
    wjrConfig.setLogHookTimezone(j.get(m.logHookTimezone).isString().stringValue());
    wjrConfig.setRetryOverQuotaEnabled(j.get(m.retryOverQuotaEnabled).isString().stringValue());
    wjrConfig.setRetryOverQuotaInterval(j.get(m.retryOverQuotaInterval).isString().stringValue());
    wjrConfig.setRetryOverQuotaMaxCount(j.get(m.retryOverQuotaMaxCount).isString().stringValue());

    return wjrConfig;
}

From source file:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java

License:Apache License

/**
 * Creates a WjrStore from Json string./*w ww.ja v  a2 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:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java

License:Apache License

/**
 * Creates a WjrMethodItem from Json string.
 * /*from   w  w w.j a v  a 2 s. c  om*/
 * @param jsonString
 *          the Json string.
 * @return the created WjrMethodItem instance.
 */
WjrMethodItem createWjrMethodItemFromJson(String jsonString) {
    WjrMethodItemMeta m = WjrMethodItemMeta.meta();
    JSONObject j = JSONParser.parseStrict(jsonString).isObject();

    String className = j.get(m.className).isString().stringValue();
    String methodName = j.get(m.methodName).isString().stringValue();
    WjrMethodItem wjrMethodItem = new WjrMethodItem(className, methodName);

    wjrMethodItem.setTrace(j.get(m.trace).isString().stringValue());
    wjrMethodItem.setLog(j.get(m.log).isString().stringValue());
    wjrMethodItem.setTime(j.get(m.time).isString().stringValue());
    wjrMethodItem.setCpuTime(j.get(m.cpuTime).isString().stringValue());
    wjrMethodItem.setApiTime(j.get(m.apiTime).isString().stringValue());
    wjrMethodItem.setOverQuota(j.get(m.isOverQuota).isBoolean().booleanValue());
    wjrMethodItem.setRetryCount(new Integer(j.get(m.retryCount).isNumber().toString()));
    wjrMethodItem.setMaxRetryCount(new Integer(j.get(m.maxRetryCount).isNumber().toString()));
    wjrMethodItem.setWaitingSeconds(new Integer(j.get(m.waitingSeconds).isNumber().toString()));
    wjrMethodItem.setState(State.valueOf(j.get(m.state).isString().stringValue()));

    return wjrMethodItem;
}

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/*  ww w .  ja  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.upei.ic.timetable.client.CourseCalendarViewController.java

License:Apache License

/**
 * Add a course to the Calendar/*from   www .  ja v  a2 s. co m*/
 * 
 * @param id
 * @param course
 */
public void addCourse(int id, JSONObject course) {
    // clear the message first
    String name = ((JSONString) course.get("name")).stringValue();
    String location = ((JSONString) course.get("location")).stringValue();
    String date = ((JSONString) course.get("time")).stringValue();

    CalendarItem item = new CalendarItem(name);
    item.setContent(location);

    // analyze the date and add the item.
    // filtered out all invalid characters
    String filteredDate = date.replaceAll("[^MTWHF0-9:-]", "");
    Queue<Integer> day = new LinkedList<Integer>();

    // begin analysis
    for (int i = 0; i < filteredDate.length(); i++) {
        switch (filteredDate.charAt(i)) {
        // weekday
        case 'M':
            day.offer(Calendar.MONDAY);
            break;
        case 'W':
            day.offer(Calendar.WEDNESDAY);
            break;
        case 'F':
            day.offer(Calendar.FRIDAY);
            break;
        case 'T':
            if (i + 1 < filteredDate.length() && filteredDate.charAt(i + 1) == 'H') {
                day.offer(Calendar.THURSDAY);
                i++;
            } else {
                day.offer(Calendar.TUESDAY);
            }
            break;
        // time
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case ':':
        case '-':
            // work until the end of time
            int j = i + 1;
            while (j < filteredDate.length() && (Character.isDigit(filteredDate.charAt(j))
                    || filteredDate.charAt(j) == ':' || filteredDate.charAt(j) == '-')) {
                j++;
            }
            // grab the time
            String time = filteredDate.substring(i, j);
            // check the time format
            if (!time.matches("^\\d{1,2}:\\d{2,2}-\\d{1,2}:\\d{2,2}")) {
                i = j;
                break;
            }

            // get the time
            String[] two = time.split("-");
            // get the begin and end
            int begin = Integer.parseInt(two[0].replaceAll(":", ""));
            int end = Integer.parseInt(two[1].replaceAll(":", ""));

            // offer the calendar
            try {
                while (day.peek() != null) {
                    int weekday = day.poll();
                    item.addTimeInterval(weekday, begin, end);
                }
            } catch (TimetableException e) {
                app_.error(ApplicationController.OOPS, e);
            }

            // done
            i = j;
            break;
        }
    }

    // add the item
    items_.put(id, item);
    // add to calendar
    calendar_.addItem(item);
}

From source file:ca.upei.ic.timetable.client.CourseDetailModelView.java

License:Apache License

public void loadJSON(JSONValue value) {
    // get all the parameters
    JSONObject object = (JSONObject) value;
    boolean success = ((JSONBoolean) object.get("success")).booleanValue();

    if (!success) {
        // do nothing and exit
        throw new RuntimeException("This course id does not exist.");
    }/* w  ww.  j a  v  a 2s .c o  m*/

    String department = ((JSONString) object.get("department")).stringValue();
    String name = ((JSONString) object.get("name")).stringValue();
    String title = ((JSONString) object.get("title")).stringValue();
    String location = ((JSONString) object.get("location")).stringValue();
    String time = ((JSONString) object.get("time")).stringValue();
    String semester = ((JSONString) object.get("semester")).stringValue();
    String status = ((JSONString) object.get("status")).stringValue();
    String description = ((JSONString) object.get("description")).stringValue();
    String instructors = ((JSONString) object.get("instructors")).stringValue();

    // build the dialog box
    clear(); // clear the dialog box first.

    // build the panels
    VerticalPanel panel = PanelUtils.verticalPanel(
            PanelUtils.simplePanel(new HTML("<strong>Name</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(name), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Title</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(title), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Status</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(status), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Department</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(department), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Instructors</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(instructors), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Semester</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(semester), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Location</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(location), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Time</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(time), 300, -1),
            PanelUtils.simplePanel(new HTML("<strong>Description</strong>"), 100, -1),
            PanelUtils.simplePanel(new HTML(description), 300, -1));

    dialogBox_.setWidget(panel);
}

From source file:ca.upei.ic.timetable.client.CourseModelView.java

License:Apache License

public void addCourse(final int id, final JSONObject value, boolean selected) {
    final CheckBox box = new CheckBox();
    String name = ((JSONString) value.get("name")).stringValue();
    String title = ((JSONString) value.get("title")).stringValue();
    String time = ((JSONString) value.get("time")).stringValue();
    box.setText(name + " " + title);
    box.setName(Integer.toString(id));
    box.setChecked(selected);/*  w ww. j av a  2s .c  om*/
    box.setEnabled(time.matches(".*\\d{1,2}:\\d{2,2}\\s*-\\s*\\d{1,2}:\\d{2,2}.*"));

    // add click listener
    box.addClickListener(new ClickListener() {

        public void onClick(Widget sender) {
            final CheckBox box = (CheckBox) sender;
            if (box.isChecked()) {
                controller_.select(id, value);
            } else {
                controller_.unselect(id);
            }
        }

    });

    FocusPanel focus = PanelUtils.focusPanel(box, null, null, null, new MouseListener() {

        public void onMouseDown(Widget sender, int x, int y) {
        }

        public void onMouseEnter(Widget sender) {
            controller_.showCourseDetail(id);
        }

        public void onMouseLeave(Widget sender) {
            controller_.hideCourseDetail();
        }

        public void onMouseMove(Widget sender, int x, int y) {
        }

        public void onMouseUp(Widget sender, int x, int y) {
            //                  box.setChecked( !box.isChecked() );
        }
    });
    panel_.add(focus);
}

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  ava 2 s  .c  o m*/
    }
}