List of usage examples for com.google.gwt.core.client JsonUtils safeEval
public static native <T extends JavaScriptObject> T safeEval(String json) ;
From source file:fr.gael.dhus.gwt.client.page.SearchPage.java
License:Open Source License
private static void search(final int start, final int length, final JavaScriptObject function) { destroyFeaturesFromAllFootprintLayer(); String searchPoly = getCurrentPolygonSearchString(); String advancedSearch = ""; if (advancedSearchActive) { boolean first = true; String productType = advancedProductType.getValue(); String polarisation = advancedPolarisation.getValue(); String sensorMode = advancedSensorMode.getValue(); String swath = advancedSwath.getValue(); String sensingDate = advancedSensingDate.getValue(); String ingestionDate = advancedIngestionDate.getValue(); String sensingDateEnd = advancedSensingDateEnd.getValue(); String ingestionDateEnd = advancedIngestionDateEnd.getValue(); if (productType != null && !productType.isEmpty()) { advancedSearch += " productType:\"" + productType + "\" "; first = false;//from w w w . ja va 2 s. c om } if (polarisation != null && !polarisation.isEmpty()) { advancedSearch += (!first ? " AND " : "") + " polarisationMode:\"" + polarisation + "\" "; first = false; } if (sensorMode != null && !sensorMode.isEmpty()) { advancedSearch += (!first ? " AND " : "") + " sensorOperationalMode:\"" + sensorMode + "\" "; first = false; } if (swath != null && !swath.isEmpty()) { advancedSearch += (!first ? " AND " : "") + " swathIdentifier:\"" + swath + "\" "; first = false; } if ((sensingDate != null && !sensingDate.isEmpty()) || (sensingDateEnd != null && !sensingDateEnd.isEmpty())) { String range = "[" + ((sensingDate != null && !sensingDate.isEmpty()) ? sensingDate + "T00:00:00.000Z" : "*") + " TO " + ((sensingDateEnd != null && !sensingDateEnd.isEmpty()) ? sensingDateEnd + "T23:59:59.999Z" : "NOW") + "]"; advancedSearch += (!first ? " AND " : "") + "( beginPosition:" + range + " AND endPosition:" + range + " ) "; first = false; } if ((ingestionDate != null && !ingestionDate.isEmpty()) || (ingestionDateEnd != null && !ingestionDateEnd.isEmpty())) { String range = "[" + ((ingestionDate != null && !ingestionDate.isEmpty()) ? ingestionDate + "T00:00:00.000Z" : "*") + " TO " + ((ingestionDateEnd != null && !ingestionDateEnd.isEmpty()) ? ingestionDateEnd + "T23:59:59.999Z" : "NOW") + " ]"; advancedSearch += (!first ? " AND" : "") + "( ingestionDate:" + range + " ) "; first = false; } } String tmpSearch = search_value.getValue(); tmpSearch += (!tmpSearch.isEmpty() && !advancedSearch.isEmpty() ? " AND " : "") + advancedSearch; tmpSearch += (!tmpSearch.isEmpty() && !searchPoly.isEmpty() ? " AND " : "") + searchPoly; if (firstSearch && tmpSearch.isEmpty()) { firstSearch = false; GWTClient.callback(function, JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); return; } firstSearch = false; final String search = tmpSearch.isEmpty() ? "*" : tmpSearch.trim(); search_request.setValue(search); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); productCartService.getProductsIdOfCart(GWTClient.getCurrentUser().getId(), new AccessDeniedRedirectionCallback<List<Long>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while getting your cart.\n" + caught.getMessage()); } @Override public void onSuccess(final List<Long> result) { cart = result; searchService.count(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting your search of '" + search + "'\n" + caught.getMessage()); } @Override public void onSuccess(final Integer total) { searchService.search(search, start, length, GWTClient.getCurrentUser().getId(), new AccessDeniedRedirectionCallback<List<ProductData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'\n" + caught.getMessage()); } @Override public void onSuccess(List<ProductData> products) { String json = toJson(GWT.getHostPageBaseURL(), products, GWTClient.getCurrentUser(), total); // Update the layer with footprints. for (ProductData product : products) { JavaScriptObject js = ProductData .getJsFootprintLayer(product.getFootprint(), false); if (js != null) addFeatureToAllFootprintLayer(js); } if (JsonUtils.safeToEval(json)) GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.SearchViewPage.java
License:Open Source License
private static void getDrbTree(final JavaScriptObject function) { if (!firstCallDone) { firstCallDone = true;//ww w . j a va 2s .c o m GWTClient.callback(function, JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); generateDownloadLink(); return; } if (!initialized) { initialized = true; GWTClient.callback(function, JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); generateDownloadLink(); } DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); if (root == null) { root = new XMLNodeData(displayedProduct.getIdentifier(), "", "", 0); root.setDeep(-1); } if (root.getDisplayedChildren() != null && !root.getDisplayedChildren().isEmpty()) { String json = "{\"aaData\": ["; json += computeJSON(root); if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : 1, \"iTotalDisplayRecords\" : 1}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); generateDownloadLink(); return; } requestXMLNode(root, false, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } @Override public void onSuccess(Void result) { String json = "{\"aaData\": ["; json += computeJSON(root); if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : 1, \"iTotalDisplayRecords\" : 1}"; GWTClient.callback(function, JsonUtils.safeEval(json)); generateDownloadLink(); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); }
From source file:fr.gael.dhus.gwt.client.page.statistics.StatisticsConnections.java
License:Open Source License
private static void getUsers(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,//from w w w . j av a 2s . co m JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); userService.countAll(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting users"); } @Override public void onSuccess(final Integer total) { userService.getAllUsers(start, length, search, new AccessDeniedRedirectionCallback<List<UserData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<UserData> users) { String json = "{\"aaData\": ["; for (UserData user : users) { boolean checked = (selectedUsers != null && selectedUsers.contains(user.getUsername())); String name = user.getUsername(); if (user.isDeleted()) { name += " (deleted)"; } json += "[{\"checked\":" + checked + ", \"name\":\"" + user.getUsername() + "\" }, {\"name\":\"" + name + "\", \"deleted\":" + user.isDeleted() + "}],"; } if (users.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.statistics.StatisticsDownloads.java
License:Open Source License
private static void getUsers(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,//from ww w. j a v a 2 s . c o m JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); userService.countAll(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting users"); } @Override public void onSuccess(final Integer total) { userService.getAllUsers(start, length, search, new AccessDeniedRedirectionCallback<List<UserData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<UserData> users) { String json = "{\"aaData\": ["; for (UserData user : users) { boolean checked = (selectedUsers != null && selectedUsers.contains(user.getUsername())); ; String name = user.getUsername(); if (user.isDeleted()) { name += " (deleted)"; } json += "[{\"checked\":" + checked + ", \"name\":\"" + user.getUsername() + "\" }, {\"name\":\"" + name + "\", \"deleted\":" + user.isDeleted() + "}],"; } if (users.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.statistics.StatisticsUsers.java
License:Open Source License
private static void getUsers(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,//from w w w . ja va2 s.c om JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); userService.countAll(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting users"); } @Override public void onSuccess(final Integer total) { userService.getAllUsers(start, length, search, new AccessDeniedRedirectionCallback<List<UserData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<UserData> users) { String json = "{\"aaData\": ["; for (UserData user : users) { boolean checked = (selectedUsers != null && selectedUsers.contains(user.getUsername())); ; json += "[{\"checked\":" + checked + ", \"name\":\"" + user.getUsername() + "\" }, \"" + user.getUsername() + "\"],"; } if (users.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.UploadPage.java
License:Open Source License
private static void getCollections(final JavaScriptObject function) { GWTClient.callback(function,//from w ww. j a v a2 s . com JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); refreshingCollections(); if (root == null) { root = new CollectionData(); root.setId(null); root.setDeep(-1); } collectionsToRefresh = new ArrayList<Long>(); for (CollectionData c : displayedCollections.values()) { if (c.getDisplayedChildren() != null && c.getDisplayedChildren().size() > 0) { collectionsToRefresh.add(c.getId()); } } displayedCollections.clear(); requestCollections(root, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { collectionsCheckAllChecked = true; String json = "{\"aaData\": ["; json += computeJSON(root); boolean children = false; if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) { json = json.substring(0, json.length() - 1); children = true; } json += "],\"iTotalRecords\" : " + (children ? 1 : 0) + ", \"iTotalDisplayRecords\" : " + (children ? 1 : 0) + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); collectionsCheckAll = SimpleCheckBox.wrap(RootPanel.get("upload_collectionsCheckAll").getElement()); collectionsCheckAll.setValue(children && collectionsCheckAllChecked); collectionsCheckAll.setEnabled(children && !collectionsTableDisabled); } }); }
From source file:fr.gael.dhus.gwt.client.page.UploadPage.java
License:Open Source License
private static void getScanners(final int start, final int length, final JavaScriptObject function) { displayedScanners.clear();//from w w w . jav a2 s . co m GWTClient.callback(function, JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); uploadService.countFileScanners(new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error while counting your saved file scanners."); } @Override public void onSuccess(final Integer total) { uploadService.getFileScanners(new AccessDeniedRedirectionCallback<List<FileScannerData>>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error while getting your saved file scanners."); } @Override public void onSuccess(List<FileScannerData> result) { String json = "{\"aaData\": ["; for (FileScannerData scanner : result) { displayedScanners.put(scanner.getId(), scanner); String display = scanner.getUrl().replace("\\", "/"); if (scanner.getUsername() != null && !scanner.getUsername().isEmpty()) { display += " - user: " + scanner.getUsername(); } json += "[{\"status\": \"" + scanner.getStatus() + "\", \"label\":\"" + display + "\"}," + "{\"id\":" + scanner.getId() + ", \"active\":" + scanner.isActive() + "}," + scanner.getId() + "],"; } if (total >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); } }); } }); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.restarea.RestAreaActivity.java
License:Open Source License
@Override public void start(AcceptsOneWidget panel, final EventBus eventBus) { view = clientFactory.getRestAreaView(); analytics = clientFactory.getAnalytics(); accessibility = clientFactory.getAccessibility(); this.eventBus = eventBus; view.setPresenter(this); Place place = clientFactory.getPlaceController().getWhere(); if (place instanceof RestAreaPlace) { RestAreaPlace restAreaPlace = (RestAreaPlace) place; int restAreaId = Integer.valueOf(restAreaPlace.getId()); String jsonString = AppBundle.INSTANCE.restAreaData().getText(); RestAreaFeed restAreas = JsonUtils.safeEval(jsonString); view.setTitle("Safety Rest Area"); SafeHtmlBuilder detailsHTMLBuilder = new SafeHtmlBuilder(); detailsHTMLBuilder.appendEscaped(restAreas.getRestAreas().get(restAreaId).getRoute() + " - " + restAreas.getRestAreas().get(restAreaId).getLocation()); detailsHTMLBuilder.appendHtmlConstant("<br>"); detailsHTMLBuilder.appendEscaped("Milepost: " + restAreas.getRestAreas().get(restAreaId).getMilepost() + " - " + restAreas.getRestAreas().get(restAreaId).getDirection()); view.setDetails(detailsHTMLBuilder.toSafeHtml()); if (restAreas.getRestAreas().get(restAreaId).getNotes() == null) { view.hideNotesHeading();//ww w . j av a 2 s . c om view.setNotes(""); } else { view.showNotesHeading(); view.setNotes(restAreas.getRestAreas().get(restAreaId).getNotes()); } SafeHtmlBuilder amenitiesHTMLBuilder = new SafeHtmlBuilder(); amenitiesHTMLBuilder.appendHtmlConstant("<ul>"); for (int i = 0; i < restAreas.getRestAreas().get(restAreaId).getAmenities().length; i++) { amenitiesHTMLBuilder.appendHtmlConstant("<li>"); amenitiesHTMLBuilder.appendEscaped(restAreas.getRestAreas().get(restAreaId).getAmenities()[i]); amenitiesHTMLBuilder.appendHtmlConstant("</li>"); } if (restAreas.getRestAreas().get(restAreaId).getAmenities().length == 0) { view.hideAmenitiesHeading(); } else { view.showAmenitiesHeading(); } amenitiesHTMLBuilder.appendHtmlConstant("</ul>"); view.setAmenities(amenitiesHTMLBuilder.toSafeHtml()); view.setLatLon(Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLatitude()), Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLongitude())); view.refresh(); } panel.setWidget(view); accessibility.postScreenChangeNotification(); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.TrafficMapActivity.java
License:Open Source License
private void getRestAreas() { String jsonString = AppBundle.INSTANCE.restAreaData().getText(); RestAreaFeed restAreas = JsonUtils.safeEval(jsonString); RestAreaItem item;// www . j a va 2 s .c om for (int i = 0; i < restAreas.getRestAreas().length(); i++) { item = new RestAreaItem(); item.setId(i); item.setRoute(restAreas.getRestAreas().get(i).getRoute()); item.setLocation(restAreas.getRestAreas().get(i).getLocation()); item.setDescription(restAreas.getRestAreas().get(i).getDescription()); item.setMilepost(restAreas.getRestAreas().get(i).getMilepost()); item.setDirection(restAreas.getRestAreas().get(i).getDirection()); item.setLatitude(restAreas.getRestAreas().get(i).getLatitude()); item.setLongitude(restAreas.getRestAreas().get(i).getLongitude()); item.setNotes(restAreas.getRestAreas().get(i).getNotes()); item.setHasDump(restAreas.getRestAreas().get(i).hasDump()); item.setOpen(restAreas.getRestAreas().get(i).isOpen()); item.setAmenities(restAreas.getRestAreas().get(i).getAmenities()); restAreaItems.add(item); } drawRestAreasLayer(); }
From source file:io.reinert.requestor.serialization.json.JsonObjectSerdes.java
License:Apache License
/** * Performs evaluation of serialized response obeying the #useSafeEval configuration. * <p/>/*w w w .ja va 2s.com*/ * * If #useSafeEval is {@code true} then the eval is performed using {@link JsonUtils#safeEval}, * otherwise then content will be loosely evaluated by {@link JsonUtils#unsafeEval}. * * @param response The serialized content * * @return The converted JavaScriptObject */ protected JavaScriptObject eval(String response) { return useSafeEval() ? JsonUtils.safeEval(response) : JsonUtils.unsafeEval(response); }