Example usage for com.google.gwt.core.client JsonUtils safeToEval

List of usage examples for com.google.gwt.core.client JsonUtils safeToEval

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsonUtils safeToEval.

Prototype

public static native boolean safeToEval(String text) ;

Source Link

Document

Returns true if the given JSON string may be safely evaluated by eval() without undersired side effects or security risks.

Usage

From source file:com.google.api.gwt.client.GoogleApiRequestTransport.java

License:Apache License

private void makeRequest(String payload, TransportReceiver receiver) {
    if (JsonUtils.safeToEval(payload)) {
        nativeSend(payload, receiver);/* ww  w. ja v  a  2 s  .  c  om*/
    } else {
        receiver.onTransportFailure(new ServerFailure("Request payload is invalid."));
    }
}

From source file:cz.cas.lib.proarc.webapp.client.presenter.JsonTokenizer.java

License:Open Source License

public static JSONValue parse(String token) {
    try {//from   w w  w  . j  a va  2s  .  c  o m
        if (JsonUtils.safeToEval(token)) {
            JSONValue jsonv = JSONParser.parseStrict(token);
            return jsonv;
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, token, ex);
    }
    return null;
}

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  ww  w  . jav  a 2 s  .c o m*/
        }
        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:org.wte4j.ui.client.templates.upload.TemplateUploadPresenter.java

License:Apache License

private FileUploadResponse parseResponse(String results) {
    if (results != null) {
        // json is wrapped in <pre/> tag
        String resultConent = results.replaceAll("\\<[^>]*>", "");
        if (JsonUtils.safeToEval(resultConent)) {
            return JsonUtils.<FileUploadResponseJso>safeEval(resultConent);
        }//from w ww .j ava  2s . c o m

    }
    return new FileUploadResponseDto(false, results);
}