List of usage examples for com.google.gwt.json.client JSONObject isObject
@Override
public JSONObject isObject()
this, as this is a JSONObject. From source file:com.blockwithme.util.client.webworkers.impl.AbstractWebWorkerImpl.java
License:Apache License
@Override public final void handleEvent(final elemental.events.Event evt) { if (evt instanceof MessageEvent) { final Object data = ((MessageEvent) evt).getData(); if (data == null) { logger.severe("got MessageEvent with null data"); } else {/*www. j av a 2 s . com*/ try { JSONObject message = new JSONObject((JavaScriptObject) data); if (message.isObject() == null) { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data) + " : data not a JSONObject"); } else { if (message.containsKey("jsObject")) { final JSONValue jsObject = message.get("jsObject"); if (jsObject.isObject() != null) { message = jsObject.isObject(); } else { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data) + " : data.jsObject not a JSONObject"); message = null; } } if (message != null) { // Get and remove channel at the same time final JSONValue channel = message.put("_channel_", null); String ch = ""; if ((channel != null) && (channel != JSONNull.getInstance())) { final JSONString str = channel.isString(); if (str != null) { // Cannot be null ch = str.stringValue(); } else { ch = stringify(channel); } } if ("java.util.logging".equals(ch)) { final LogRecord record = WebWorkerLogHandler.fromJSONObject(message); if (record != null) { setThreadName(record, name); Logger.getLogger(record.getLoggerName()).log(record); } } else if ("set.thread.name".equals(ch)) { final String name = message.get("value").isString().stringValue(); setThreadName(Thread.currentThread(), name); } else { listener.onMessage(ch, message); } } } } catch (final Throwable t) { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data), t); } } } else if (evt instanceof ErrorEvent) { final ErrorEvent errEvt = (ErrorEvent) evt; final String filename = errEvt.getFilename(); final int lineno = errEvt.getLineno(); final String message = errEvt.getMessage(); logger.severe(filename + ":" + lineno + ": " + message); } else if (evt != null) { logger.severe("Cannot handle message of type " + evt.getClass() + " : " + stringify(evt)); } }
From source file:com.gwittit.client.facebook.FacebookApi.java
License:Apache License
/** * This method returns the same set of subelements, whether or not there are * outstanding notifications in any area. Note that if the unread subelement * value is 0 for any of the pokes or shares elements, the most_recent * element is also 0. Otherwise, the most_recent element contains an * identifier for the most recent notification of the enclosing type. * <p/>/* w w w . j a v a 2 s . c o m*/ * If you are building an application that notifies users of new * messages/pokes/shares, we encourage you to use the following logic when * deciding whether to show a notification: * * @see <a * href="http://wiki.developers.facebook.com/index.php/JS_API_M_FB.ApiClient.Notifications_get">Notifications_get</a> */ @Deprecated public void notificationsGet(final AsyncCallback<List<NotificationRequest>> callback) { JSONObject p = getDefaultParams(); final NotificationRequest.NotificationType[] types = NotificationRequest.NotificationType.values(); final AsyncCallback<JavaScriptObject> internCallback = new AsyncCallback<JavaScriptObject>() { public void onFailure(Throwable caught) { callback.onFailure(caught); } public void onSuccess(JavaScriptObject jso) { List<NotificationRequest> resultList = new ArrayList<NotificationRequest>(); JSONObject result = new JSONObject(jso); for (NotificationRequest.NotificationType t : types) { if (result.isObject().get(t.toString()) != null) { resultList.add(new NotificationRequest(t.toString(), result.isObject().get(t.toString()))); } } callback.onSuccess(resultList); } }; callMethod("notifications.get", p.getJavaScriptObject(), internCallback); }
From source file:com.gwittit.client.facebook.FacebookApi.java
License:Apache License
/** * This method gets all the current session user's notifications, as well as * data for the applications that generated those notifications. It is a * wrapper around the notification and application FQL tables; you can * achieve more fine-grained control by using those two FQL tables in * conjunction with the fql.multiquery API call. * /*from w w w . ja v a 2s. c o m*/ * @param start_time * time Indicates the earliest time to return a notification. * This equates to the updated_time field in the notification FQL * table. If not specified, this call returns all available * notifications. * @param include_read * bool Indicates whether to include notifications that have * already been read. By default, notifications a user has read * are not included. */ @Deprecated public void notificationsGetList(Long startTime, Boolean includeRead, final AsyncCallback<List<Notification>> callback) { Json j = new Json().put("start_time", startTime).put("include_read", includeRead); AsyncCallback<JavaScriptObject> internCallback = new AsyncCallback<JavaScriptObject>() { public void onFailure(Throwable caught) { callback.onFailure(caught); } public void onSuccess(JavaScriptObject jso) { List<Notification> resultList = new ArrayList<Notification>(); JSONObject result = new JSONObject(jso); JSONValue v = result.isObject().get("notifications"); JSONArray a = v.isArray(); for (int i = 0; a != null && i < a.size(); i++) { resultList.add(new Notification(a.get(i).isObject())); } callback.onSuccess(resultList); } }; callMethod("notifications.getList", j.getJavaScriptObject(), internCallback); }
From source file:com.isotrol.impe3.pms.gui.client.util.PmsUtil.java
License:Open Source License
/** * Read the json file "frameColumns.json" to build the arrays to show the default columns in columns palette in the * page design.//from w w w. jav a2 s . co m */ public void loadDesignColumns() { RequestBuilder json = new RequestBuilder(RequestBuilder.GET, "properties.json"); json.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { JSONObject fileJson = null; try { fileJson = (JSONObject) JSONParser.parseLenient(response.getText()).isObject(); } catch (JSONException e) { util.error(pmsMessages.msgErrorParseColumnsJson()); } if (fileJson != null) { JSONObject properties = fileJson.get("properties").isObject(); JSONObject oProp = properties.isObject(); // read frame columns parseFrameColumns(oProp); // read visibility of external services menus and disable login parseOtherProperties(oProp); } } public void onError(Request request, Throwable exception) { GWT.log("Throwable: " + exception.getMessage()); exception.printStackTrace(); } }); try { json.send(); } catch (RequestException e) { GWT.log("RequestException: " + e.getMessage()); e.printStackTrace(); } }
From source file:com.isotrol.impe3.pms.gui.client.util.PmsUtil.java
License:Open Source License
public void loadProperties(Response response) { JSONObject fileJson = null;/*from w w w . j a v a2 s . co m*/ try { fileJson = (JSONObject) JSONParser.parseLenient(response.getText()).isObject(); } catch (JSONException e) { util.error(pmsMessages.msgErrorParseColumnsJson()); } if (fileJson != null) { JSONObject properties = fileJson.get("properties").isObject(); JSONObject oProp = properties.isObject(); // read frame columns parseFrameColumns(oProp); // read visibility of external services menus and disable login parseOtherProperties(oProp); } }
From source file:com.qualogy.qafe.gwt.client.util.JSNIUtil.java
License:Apache License
private static Map<String, Object> resolveJavaMap(JavaScriptObject jsValue) { Map<String, Object> value = new HashMap<String, Object>(); if (jsValue == null) { return value; }//from w w w . j a v a 2s .c o m JSONObject jsonObject = new JSONObject(jsValue); if (jsonObject.isObject() == null) { return value; } value = resolveJavaMap(jsonObject); return value; }
From source file:edu.ucsb.eucalyptus.admin.client.extensions.store.JSONImageStoreResponse.java
License:Open Source License
private JSONImageStoreResponse(JSONObject object) { final JSONValue imagesValue = object.get("images"); hasImageInfos = (imagesValue != null); imageInfos = JSONImageInfo.fromObjectArray(imagesValue); final JSONValue statesValue = object.get("states"); hasImageStates = (statesValue != null); imageStates = JSONImageState.fromObjectArray(statesValue); if (object.containsKey("state") && object.isObject() != null) { // When we access a state URI or perform an action, we get // back an individual state, but we handle it the same way // in the UI. JSONObject stateObject = object.get("state").isObject(); imageStates.add(JSONImageState.fromObject(stateObject)); }//from w w w . jav a 2s .co m final JSONValue sectionsValue = object.get("sections"); hasImageSections = (sectionsValue != null); imageSections = JSONImageSection.fromObjectArray(sectionsValue); errorMessage = JSONUtil.asString(object.get("error-message")); }
From source file:eu.riscoss.client.report.ReportModule.java
License:Apache License
protected void showResults(JSONObject object) { page.clear();//from ww w .j av a 2 s .com if (dock != null) { while (dock.getWidgetCount() > 0) { dock.remove(dock.getWidget(0)); } dock.removeFromParent(); dock = new DockPanel(); } if (object.get("results") == null) return; JSONArray response = object.get("results").isArray(); // Window.alert( "2: " + response ); RiskAnalysisReport report = new RiskAnalysisReport(); report.showResults(null, response, object.isObject().get("argumentation")); DisclosurePanel dp = new DisclosurePanel("Input values used for this evaluation"); JSONArray inputs = getArray(object, "inputs"); Grid inputgrid = new Grid(inputs.size(), 2); for (int i = 0; i < inputs.size(); i++) { JSONObject o = inputs.get(i).isObject(); // Window.alert( "" + o ); inputgrid.setWidget(i, 0, new Label(o.get("id").isString().stringValue())); inputgrid.setWidget(i, 1, new Label(o.get("value").isString().stringValue())); } dp.setContent(inputgrid); Anchor a = new Anchor("Change input values..."); a.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (inputForm != null) inputForm.show(new Callback<JSONObject>() { @Override public void onError(Throwable t) { Window.alert(t.getMessage()); } @Override public void onDone(JSONObject o) { startAnalysisWorkflow(EAnalysisOption.RunThrough, o); } }); } }); dock.setSize("100%", "100%"); // grid.setSize( "100%", "100%" ); dock.add( new HTML("<h1>" + "Risk analysis report of " + object.get("info").isObject().get("entity").isString().stringValue() + "</h1>"), DockPanel.NORTH); dock.add(report, DockPanel.CENTER); dock.add(a, DockPanel.NORTH); dock.add(dp, DockPanel.SOUTH); mainView.setStyleName("mainViewLayer"); mainView.setWidth("100%"); page.setWidth("100%"); Label title = new Label( "Risk analysis report of " + object.get("info").isObject().get("entity").isString().stringValue()); title.setStyleName("title"); page.add(title); a.setStyleName("leftPanel"); page.add(a); //report.setStyleName("leftPanel"); page.add(report); dp.setStyleName("leftPanel"); page.add(dp); //RootPanel.get().add( dock ); RootPanel.get().add(page); }
From source file:info.magnolia.ui.vaadin.gwt.client.jquerywrapper.JQueryWrapper.java
License:Open Source License
public final void setCss(JSONObject value) { final JavaScriptObject jso = value.isObject().getJavaScriptObject(); setCss(jso);/*from w ww . ja v a 2s. co m*/ }
From source file:net.gowithus.client.model.Client.java
License:Apache License
public static Client deser(JSONObject j_o) { Client c = new Client(); try {//ww w .ja v a 2s . co m c.setId((int) j_o.isObject().get("id").isNumber().doubleValue()); c.setName(Helper.getJSONString(j_o.isObject().get("name"))); c.setCity(Helper.getJSONString(j_o.isObject().get("city"))); c.setEmail(Helper.getJSONString(j_o.isObject().get("email"))); c.setPhone(Helper.getJSONString(j_o.isObject().get("phone"))); c.setBirthday(DateTimeFormat.getFormat(UserString.DATE_FORMAT) .parse(j_o.get("birthday").isString().stringValue())); c.setHash(Helper.getJSONString(j_o.isObject().get("hash"))); String bonusTemp = Helper.getJSONString(j_o.isObject().get("bonus")); // Helper.alert(bonusTemp); c.setBonus((bonusTemp.equals("") || bonusTemp.equals("undefined")) ? "0" : bonusTemp); // Helper.alert("writ "+c.getBonus()); //c.setQrCode(Helper.getJSONString(j_o.isObject().get("qrCode"))); c.setAvatar(Helper.getJSONString(j_o.isObject().get("avatar"))); } catch (Exception e) { Window.alert("DESER CLIENT PROVIDER " + e.getMessage()); } return c; }