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

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

Introduction

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

Prototype

@Override
public native String toString() ;

Source Link

Document

Returns the JSON representation of this number.

Usage

From source file:com.tasktop.c2c.server.wiki.web.ui.client.presenter.EditWikiPagePresenter.java

License:Open Source License

private void attachmentsSubmitted(SubmitCompleteEvent event) {
    JSONValue value = JSONParser.parseLenient(event.getResults());
    JSONValue uploadResultValue = value.isObject().get("uploadResult");
    JSONObject uploadResult = uploadResultValue == null ? null
            : value.isObject().get("uploadResult").isObject();
    if (uploadResult != null) {
        // get updated modification stamp and list of attachments
        JSONObject updatedPage = uploadResult.get("page") == null ? null : uploadResult.get("page").isObject();
        if (updatedPage != null) {
            JSONNumber number = updatedPage.get("modificationDate") == null ? null
                    : updatedPage.get("modificationDate").isNumber();
            if (number != null) {
                page.setModificationDate(new Date(new Long(number.toString())));
            }//from   w  w w .  java 2s  .  co m
        }
        ProfileGinjector.get.instance().getNotifier().displayMessage(Message
                .createSuccessMessage(super.wikiMessages.attachmentUploaded(view.getAttachmentFileName())));
        getEventBus().fireEvent(new ClearCacheEvent());
        view.clearAttachementForm();
        // Ideally we would simply update with the results for the json content.
        fetchAttachments();
    } else {
        String message = super.commonProfileMessages.unexpectedServerResponse();
        JSONValue errorValue = value.isObject().get("error");
        JSONObject errorObject = errorValue == null ? null : errorValue.isObject();
        if (errorObject != null) {
            JSONString errorMessage = errorObject.get("message").isString();
            if (errorMessage != null) {
                message = errorMessage.stringValue();
            }
        }
        ProfileGinjector.get.instance().getNotifier().displayMessage(Message.createErrorMessage(message));
    }
}

From source file:es.deusto.weblab.client.comm.CommonSerializerJSON.java

License:Open Source License

private void throwException(JSONObject responseObject) throws WebLabServerException {
    // {"message": "No UserAuth found", "code": "JSON:Server.WebLab", "is_exception": true}
    final String faultCode = responseObject.get("code").isString().stringValue();
    final JSONString strMessage = responseObject.get("message").isString();
    final String faultString;
    if (strMessage == null) {
        JSONNumber intMessage = responseObject.get("message").isNumber();
        if (intMessage == null)
            faultString = "unknown message: " + responseObject.get("message").toString();
        else/*from  w w w . ja  v  a 2  s  .  c  om*/
            faultString = "Error retrieved from server: " + intMessage.toString()
                    + "; probably a database configuration error. Contact the administrator.";
    } else {
        faultString = strMessage.stringValue();
    }

    throw this.buildException(faultCode, faultString);
}

From source file:fast.servicescreen.client.gui.codegen_js.CodeGenerator.java

License:Open Source License

/**
 * This method send the current template to
 * an service which writes a js and a html file with it as content. 
 * *///from w w  w  .j  a  v  a  2  s . com
public void write_JS_File(boolean isLocal) {
    //create GWT service impl.
    service = GWT.create(RequestService.class);

    //send pre - trans - post code to server
    service.saveJsFileOnServer(isLocal, screen.getName(), prehtml, helperMethods + rootTemplate, posthtml,
            new AsyncCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    GWT.log("Writing .js file to RequestService succed..", null);

                    Window.alert(result);
                }

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log("ERROR while writing .js file to RequestService..", null);

                    Window.alert(caught.getLocalizedMessage());
                }
            });

    //shareBuildingBlock():
    //url and header
    String url = "http://localhost:13337/" /*URL_Settings.getGVS_URL()*/ + "buildingblock/resource";
    final String cookie = "fastgvsid=" + Cookies.getCookie("fastgvsid");
    final HashMap<String, String> headers = new HashMap<String, String>();
    headers.put("Cookie", cookie);

    //build operator
    String jsonObject = createBuildingBlock();
    String body = "buildingblock=" + jsonObject;

    //upload to GVS
    service.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() {
        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(String result) {
            if (result != null && result != "-1" && result.startsWith("{")) {
                JSONValue resourceVal = JSONParser.parse(result);
                JSONObject resourceObj = resourceVal.isObject();
                JSONValue idVal = resourceObj.get("id");
                JSONNumber idNum = idVal.isNumber();
                String id = idNum.toString();

                if (id != null) {
                    String shareUrl = "http://127.0.0.1:13337/" + "buildingblock/" + id + "/sharing";
                    service.sendHttpRequest_POST(shareUrl, headers, "", new AsyncCallback<String>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            //Resource couldn't be shared
                            System.out.println("Resource couldn't be shared" + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(String result) {
                            //Resource was shared
                            System.out.println("Resource was shared: " + result);
                        }
                    });
                }
            }
        }
    });
}

From source file:fast.servicescreen.client.rpc.ShareResourceHandler.java

License:Open Source License

public String share(BuildingBlock res) {
    final String resultString = "";

    //url and header
    String url = gvsUrl + "buildingblock/resource";
    final String cookie = "fastgvsid=" + Cookies.getCookie("fastgvsid");
    final HashMap<String, String> headers = new HashMap<String, String>();
    headers.put("Cookie", cookie);

    //build operator
    String body = "buildingblock=" + buildResource(res);

    //      Window.alert("Resource: " + body);

    //upload to GVS
    shResService = GWT.create(RequestService.class);
    shResService.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() {
        @Override/*from   www . j av a2  s  .com*/
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(String result) {
            if (result != null && result != "-1") {
                JSONValue resourceVal = JSONParser.parse(result);
                JSONObject resourceObj = resourceVal.isObject();
                JSONValue idVal = resourceObj.get("id");
                JSONNumber idNum = idVal.isNumber();
                String id = idNum.toString();

                if (id != null) {
                    String shareUrl = gvsUrl + "buildingblock/" + id + "/sharing";
                    shResService.sendHttpRequest_POST(shareUrl, headers, "", new AsyncCallback<String>() {
                        @Override
                        public void onFailure(Throwable caught) {
                            //Resource couldn't be shared
                            System.out.println("Resource couldn't be shared" + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(String result) {
                            //Resource was shared
                            System.out.println("Resource was shared: " + result);
                        }
                    });
                }
            }
        }
    });

    return resultString;
}

From source file:org.emfjson.gwt.map.Values.java

License:Open Source License

public void setOrAdd(EObject owner, EAttribute attribute, JSONValue value) {
    JSONString stringValue = value.isString();
    if (stringValue != null) {
        EObjects.setOrAdd(owner, attribute, stringValue.stringValue());
    }/*from   ww w .j a va 2  s. co m*/

    JSONBoolean booleanValue = value.isBoolean();
    if (booleanValue != null) {
        EObjects.setOrAdd(owner, attribute, booleanValue.toString());
    }

    JSONNumber numberValue = value.isNumber();
    if (numberValue != null) {
        EObjects.setOrAdd(owner, attribute, numberValue.toString());
    }
}

From source file:org.emfjson.gwt.map.ValueSerializer.java

License:Open Source License

public void setOrAdd(EObject owner, EAttribute attribute, JSONValue value) {
    String asString = null;//from www .  j a v a 2 s . c o  m
    JSONString stringValue = value.isString();
    if (stringValue != null) {
        asString = stringValue.stringValue();
    }

    JSONBoolean booleanValue = value.isBoolean();
    if (booleanValue != null) {
        asString = booleanValue.toString();
    }

    JSONNumber numberValue = value.isNumber();
    if (numberValue != null) {
        asString = numberValue.toString();
    }

    if (asString != null) {
        Object converted = EcoreUtil.createFromString(attribute.getEAttributeType(), asString);
        EObjects.setOrAdd(owner, attribute, converted);
    }
}

From source file:org.lirazs.gbackbone.client.core.data.Options.java

License:Apache License

public Options(JSONValue jsonObject) {
    JSONObject object = jsonObject.isObject();

    if (object != null) {
        for (String s : object.keySet()) {
            JSONValue jsonValue = object.get(s);
            Object value = jsonValue;

            JSONNumber number = jsonValue.isNumber();
            if (number != null) {
                if (number.toString().contains(".")) {
                    value = number.doubleValue();
                } else {
                    value = (int) number.doubleValue();
                }/*from   w w w.  j  a  v  a 2 s .  co m*/
            }

            JSONBoolean jsonBoolean = jsonValue.isBoolean();
            if (jsonBoolean != null)
                value = jsonBoolean.booleanValue();

            JSONNull jsonNull = jsonValue.isNull();
            if (jsonNull != null)
                value = null;

            JSONString jsonString = jsonValue.isString();
            if (jsonString != null)
                value = jsonString.stringValue();

            put(s, value);
        }
    }
}

From source file:org.sonar.api.web.gwt.client.webservices.JsonUtils.java

License:Open Source License

public static String getString(JSONObject json, String field) {
    JSONValue jsonValue;/* ww w.j  a  va  2  s  .  c  o m*/
    JSONString jsonString;
    if ((jsonValue = json.get(field)) == null) {
        return null;
    }
    if ((jsonString = jsonValue.isString()) == null) {
        JSONNumber jsonNumber = jsonValue.isNumber();
        return jsonNumber != null ? jsonNumber.toString() : null;
    }
    return jsonString.stringValue();
}

From source file:org.sonar.gwt.JsonUtils.java

License:Open Source License

public static String getAsString(JSONValue jsonValue) {
    if (jsonValue == null) {
        return null;
    }/*from   w  w  w  . j av a 2 s.  com*/
    JSONString jsonString;
    if ((jsonString = jsonValue.isString()) == null) {
        JSONNumber jsonNumber = jsonValue.isNumber();
        return jsonNumber != null ? jsonNumber.toString() : null;
    }
    return jsonString.stringValue();
}