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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Converts a JSONObject into a JSON representation that can be used to communicate with a JSON service.

Usage

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

License:Open Source License

public boolean suspend() {
    JSONObject jUser = new JSONObject();
    if (domainname == null || username == null)
        return false;

    jUser.put(STORAGE_DOMAIN, new JSONString(domainname));
    //jUser.put("password", new JSONString(password)); //It's uneeded, and not safe
    String strPriority = String.valueOf(priority);
    if (strPriority != null)
        jUser.put(STORAGE_PRIORITY, new JSONString(String.valueOf(priority)));
    jUser.put(STORAGE_RESOURCE, new JSONString(resource));
    jUser.put(STORAGE_USERNAME, new JSONString(username));

    Cookies.setCookie(COOKIENAME, jUser.toString(), null, null, "/", false);
    return true;// w  w  w . j a va  2s .c o m
}

From source file:br.com.pegasus.solutions.smartgwt.lib.client.view.impl.advanced.bar.infra.ExportUtil.java

License:Apache License

public static String getDataAsJson(ListGrid listGrid) {
    JSONObject jsonObj = new JSONObject();

    ListGridRecord[] records = listGrid.getRecords();
    for (int i = 0; i < records.length; i++) {
        ListGridRecord listGridRecord = records[i];
        ListGridField[] listGridFields = listGrid.getFields();
        JSONObject json = new JSONObject();

        for (int j = 0; j < listGridFields.length; j++) {
            ListGridField listGridField = listGridFields[j];
            String name = listGridField.getName();
            if (name.contains(FIELD_NAME_CLASS_SEPARATOR)) {
                name = name.split(FIELD_NAME_CLASS_SEPARATOR)[0];
            }/*  ww  w . j  a v  a2s  .  c  o m*/

            String value = listGridRecord.getAttribute(listGridField.getName());
            if (value != null) {
                try {
                    BigInteger number = new BigInteger(value);
                    json.put(name, new JSONNumber(number.intValue()));
                } catch (Exception e) {
                    try {
                        BigDecimal decimal = new BigDecimal(value);
                        decimal.setScale(2, RoundingMode.HALF_UP);
                        json.put(name, new JSONNumber(decimal.doubleValue()));
                    } catch (Exception e2) {
                        json.put(name, new JSONString(value));
                    }
                }
            } else {
                json.put(name, new JSONString(""));
            }
        }

        jsonObj.put("jsonRecord" + (i + 1), json);
    }

    return jsonObj.toString();
}

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

    });
}

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

License:Apache License

public void askCourseDetail(int courseId, RequestCallback callback) {
    JSONObject object = new JSONObject();
    object.put("id", new JSONNumber(courseId));
    currentCourseDetailRequest_ = remote_.post("get_course_detail", "application/json", object.toString(),
            callback);//  w ww  . j  a  v a 2  s. co m
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

protected String getFeedbackToAjax() {
    JSONObject outputFeedback = new JSONObject();
    for (int iterator = 0; iterator < feedback.size(); iterator++) {
        JSONArray array = new JSONArray();
        array.set(0, new JSONString(feedback.get(iterator).getNameOER().replaceAll("\\<.*?>", "")));
        array.set(1, new JSONString(feedback.get(iterator).getName().replaceAll("\\<.*?>", "")));
        array.set(2, new JSONString(feedback.get(iterator).getLink()));

        outputFeedback.put(Integer.toString(iterator), array);
    }/* www.  ja va2s . co m*/
    return outputFeedback.toString();
}

From source file:cl.uai.client.page.EditMarkDialog.java

License:Open Source License

public String getFeedback() {
    JSONObject outputFeedback = new JSONObject();
    for (int iterator = 0; iterator < feedbackArray.size(); iterator++) {
        JSONArray array = new JSONArray();
        array.set(0, new JSONString(feedbackArray.get(iterator).getNameOER()));
        array.set(1, new JSONString(feedbackArray.get(iterator).getName()));
        if (feedbackArray.get(iterator).getNameOER().equals("CS50")) {
            array.set(2, new JSONString(feedbackArray.get(iterator).getNameOER()));
        } else {/*from  w w  w. jav a 2s . c om*/
            array.set(2, new JSONString(feedbackArray.get(iterator).getLink()));
        }

        outputFeedback.put(Integer.toString(iterator), array);
    }
    return outputFeedback.toString();
}

From source file:colt.json.gwt.client.JsonClient.java

License:Apache License

public void invoke(String _url, String _serviceName, JSONObject requestData, final IAsyncJSON result) {
    invoke(_url, _serviceName, "JSON=" + requestData.toString(), result);
}

From source file:com.ait.lienzo.client.core.shape.guides.ToolTip.java

License:Open Source License

@Override
public String toJSONString() {
    final JSONObject object = super.toJSONObject();

    if (null != object) {
        object.put("type", new JSONString("ToolTip"));

        return object.toString();
    }/*from  ww  w.  jav a 2s  . c o m*/
    return null;
}

From source file:com.ait.lienzo.client.core.shape.Node.java

License:Open Source License

/**
 * Serializes this Node as a JSON string.
 * The JSON string can be deserialized with 
 * {@link JSONDeserializer#fromString(String)}.
 * //from   www . j a  v a2 s .c o  m
 * @return JSON string
 */
public String toJSONString() {
    JSONObject object = toJSONObject();

    if (null != object) {
        return object.toString();
    }
    return null;
}

From source file:com.ait.lienzo.client.core.types.BoundingBox.java

License:Open Source License

public final String toJSONString() {
    JSONObject object = new JSONObject();

    object.put("x", new JSONNumber(getX()));

    object.put("y", new JSONNumber(getY()));

    object.put("width", new JSONNumber(getWidth()));

    object.put("height", new JSONNumber(getHeight()));

    return object.toString();
}