Example usage for com.google.gwt.safehtml.shared UriUtils encode

List of usage examples for com.google.gwt.safehtml.shared UriUtils encode

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared UriUtils encode.

Prototype

public static String encode(String uri) 

Source Link

Document

Encodes the URL.

Usage

From source file:com.gwtplatform.dispatch.client.rest.RestRequestBuilderFactory.java

License:Apache License

private String encode(RestParameter value) throws ActionException {
    return UriUtils.encode(value.getStringValue());
}

From source file:com.imaginedreal.gwt.palantir.client.activities.search.SearchActivity.java

License:Apache License

@Override
public void onSearchTextChanged(String filter) {
    String url = TITLE_SEARCH_URL + UriUtils.encode(filter) + "/page/1/limit/5";

    view.showProgressIndicator();/*  ww w .j a  v a 2 s . c om*/

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    jsonp.setTimeout(30000); // Set timeout for 30 seconds
    jsonp.requestObject(url, new AsyncCallback<BookJso>() {

        @Override
        public void onFailure(Throwable caught) {
            view.hideProgressIndicator();
        }

        @Override
        public void onSuccess(BookJso result) {
            if (result.getBookShare() != null) {
                books.clear();
                Book book;
                int numBooks = result.getBookShare().getBook().getList().getResult().length();

                for (int i = 0; i < numBooks; i++) {
                    book = new Book();

                    book.setTitle(result.getBookShare().getBook().getList().getResult().get(i).getTitle());
                    book.setBriefSynopsis(
                            result.getBookShare().getBook().getList().getResult().get(i).getBriefSynopsis());

                    String isbn = result.getBookShare().getBook().getList().getResult().get(i).getIsbn13();
                    book.setIsbn13(isbn);
                    book.setBookCoverUrl("http://covers.openlibrary.org/b/isbn/" + isbn + "-M.jpg");

                    books.add(book);
                }
            }

            view.hideProgressIndicator();
            view.render(books);
            view.refresh();
        }
    });

}

From source file:com.itgp.gwtviz.client.comm.ServerComm.java

License:Open Source License

public static void getMRouteData(String mRouteURL, final long fileID, final List<Item> columnData,
        final IMRouteCallable mRouteCallableWidget) {
    String columnURL = ItemUtil.makeColumnURL(columnData) + "";
    String url = mRouteURL + getData + fileID + "/" + columnURL;
    String urlEncoded = UriUtils.encode(url);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, urlEncoded);
    try {//from   ww w  . j  av a  2  s  .c o  m
        builder.sendRequest("", new RequestCallback() {
            public void onError(Request request, Throwable e) {
                alert(e);
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String dataArray = response.getText();
                    ItemUtil.addDataToColumns(dataArray, columnData);
                    MainDesktop.setCurrentDataModel(ItemUtil.copy(columnData), dataArray); // Make a copy for further reference
                    ItemUtil.elimateDuplicateData(columnData);
                    // List<Item> columnData2 = mRoute.decodeColumns(""+fileID,response.getText());
                    mRouteCallableWidget.setData(columnData);
                } else {
                    alert("Received HTTP status code other than 200 : " + response.getStatusText());
                }
            }
        });
    } catch (RequestException e) {
        alert(e);
    }
}

From source file:com.itgp.gwtviz.client.ui.ConfigPanel_1.java

License:Open Source License

public void setHREFinDownloadElementAnchor(String plainTxt) {
    String encodedString = "data:text/plain;charset=utf-8," + UriUtils.encode(plainTxt);
    // downloadElementAnchor.setAttribute("href","XXXX");
    // downloadElementAnchor.setAttribute("href", encodedString);
    Element e = DOM.getElementById(Drupal._DRUPAL_GWTVIZ_DOWNLOAD_LINK);
    e.setAttribute("href", encodedString);
    e.setAttribute("download", makeDownloadFileName(graphConfigImpl.getDataSourceName()));

    String s = "1";
    s = s + "1";/*from w ww.jav a 2 s .c  o  m*/
}

From source file:com.itgp.gwtviz.client.ui.runtime.RuntimeEntry.java

License:Open Source License

public void requestData() {

    String columnURL = ItemUtil.makeColumnURL(run.getColumnDescriptors()) + "";
    final String url = MainDesktop.getMRouteURL() + ServerComm.getData + run.fileID + "/" + columnURL;
    String urlEncoded = UriUtils.encode(url);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, urlEncoded);
    try {//from w w w .ja  v a 2  s  . co  m
        builder.sendRequest("", new RequestCallback() {
            public void onError(Request request, Throwable e) {
                sendError("The following error was returned while attempting to get data from " + url + "\n\n"
                        + e.getMessage());

                return;
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String dataArray = response.getText();
                    run.dataArray = dataArray;
                    RuntimeEntry_Part2 re2 = new RuntimeEntry_Part2(run);
                    re2.runtimeLoop();
                } else {
                    sendError("Error processing the data request.\n\nGot response code: "
                            + response.getStatusCode());

                    return;
                }
            }

        });
    } catch (RequestException e) {
        sendError("The following exception occurred while attempting to get data from " + url + "\n\n"
                + e.getMessage());
    }
}

From source file:org.jahia.ajax.gwt.content.server.GWTFileManagerUploadServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    SettingsBean settingsBean = SettingsBean.getInstance();
    final long fileSizeLimit = settingsBean.getJahiaFileUploadMaxSize();
    upload.setHeaderEncoding("UTF-8");
    Map<String, FileItem> uploads = new HashMap<String, FileItem>();
    String location = null;/*  w w w  .  j a va 2s . com*/
    String type = null;
    boolean unzip = false;
    response.setContentType("text/plain; charset=" + settingsBean.getCharacterEncoding());
    final PrintWriter printWriter = response.getWriter();
    try {
        FileItemIterator itemIterator = upload.getItemIterator(request);
        FileSizeLimitExceededException sizeLimitExceededException = null;
        while (itemIterator.hasNext()) {
            final FileItemStream item = itemIterator.next();
            if (sizeLimitExceededException != null) {
                continue;
            }
            FileItem fileItem = factory.createItem(item.getFieldName(), item.getContentType(),
                    item.isFormField(), item.getName());
            long contentLength = getContentLength(item.getHeaders());

            // If we have a content length in the header we can use it
            if (fileSizeLimit > 0 && contentLength != -1L && contentLength > fileSizeLimit) {
                throw new FileSizeLimitExceededException("The field " + item.getFieldName()
                        + " exceeds its maximum permitted size of " + fileSizeLimit + " bytes.", contentLength,
                        fileSizeLimit);
            }
            InputStream itemStream = item.openStream();

            InputStream limitedInputStream = null;
            try {
                limitedInputStream = fileSizeLimit > 0 ? new LimitedInputStream(itemStream, fileSizeLimit) {

                    @Override
                    protected void raiseError(long pSizeMax, long pCount) throws IOException {
                        throw new FileUploadIOException(new FileSizeLimitExceededException(
                                "The field " + item.getFieldName() + " exceeds its maximum permitted size of "
                                        + fileSizeLimit + " bytes.",
                                pCount, pSizeMax));
                    }
                } : itemStream;

                Streams.copy(limitedInputStream, fileItem.getOutputStream(), true);
            } catch (FileUploadIOException e) {
                if (e.getCause() instanceof FileSizeLimitExceededException) {
                    if (sizeLimitExceededException == null) {
                        sizeLimitExceededException = (FileSizeLimitExceededException) e.getCause();
                    }
                } else {
                    throw e;
                }
            } finally {
                IOUtils.closeQuietly(limitedInputStream);
            }

            if ("unzip".equals(fileItem.getFieldName())) {
                unzip = true;
            } else if ("uploadLocation".equals(fileItem.getFieldName())) {
                location = fileItem.getString("UTF-8");
            } else if ("asyncupload".equals(fileItem.getFieldName())) {
                String name = fileItem.getName();
                if (name.trim().length() > 0) {
                    uploads.put(extractFileName(name, uploads), fileItem);
                }
                type = "async";
            } else if (!fileItem.isFormField() && fileItem.getFieldName().startsWith("uploadedFile")) {
                String name = fileItem.getName();
                if (name.trim().length() > 0) {
                    uploads.put(extractFileName(name, uploads), fileItem);
                }
                type = "sync";
            }
        }
        if (sizeLimitExceededException != null) {
            throw sizeLimitExceededException;
        }
    } catch (FileUploadBase.FileSizeLimitExceededException e) {
        printWriter.write("UPLOAD-SIZE-ISSUE: " + getSizeLimitErrorMessage(fileSizeLimit, e, request) + "\n");
        return;
    } catch (FileUploadIOException e) {
        if (e.getCause() != null && (e.getCause() instanceof FileSizeLimitExceededException)) {
            printWriter.write("UPLOAD-SIZE-ISSUE: " + getSizeLimitErrorMessage(fileSizeLimit,
                    (FileSizeLimitExceededException) e.getCause(), request) + "\n");
        } else {
            logger.error("UPLOAD-ISSUE", e);
            printWriter.write("UPLOAD-ISSUE: " + e.getLocalizedMessage() + "\n");
        }
        return;
    } catch (FileUploadException e) {
        logger.error("UPLOAD-ISSUE", e);
        printWriter.write("UPLOAD-ISSUE: " + e.getLocalizedMessage() + "\n");
        return;
    }

    if (type == null || type.equals("sync")) {
        response.setContentType("text/plain");

        final JahiaUser user = (JahiaUser) request.getSession().getAttribute(Constants.SESSION_USER);

        final List<String> pathsToUnzip = new ArrayList<String>();
        for (String fileName : uploads.keySet()) {
            final FileItem fileItem = uploads.get(fileName);
            try {
                StringBuilder name = new StringBuilder(fileName);
                final int saveResult = saveToJcr(user, fileItem, location, name);
                switch (saveResult) {
                case OK:
                    if (unzip && fileName.toLowerCase().endsWith(".zip")) {
                        pathsToUnzip.add(
                                new StringBuilder(location).append("/").append(name.toString()).toString());
                    }
                    printWriter.write("OK: " + UriUtils.encode(name.toString()) + "\n");
                    break;
                case EXISTS:
                    storeUploadedFile(request.getSession().getId(), fileItem);
                    printWriter.write("EXISTS: " + UriUtils.encode(fileItem.getFieldName()) + " "
                            + UriUtils.encode(fileItem.getName()) + " " + UriUtils.encode(fileName) + "\n");
                    break;
                case READONLY:
                    printWriter.write("READONLY: " + UriUtils.encode(fileItem.getFieldName()) + "\n");
                    break;
                default:
                    printWriter.write("UPLOAD-FAILED: " + UriUtils.encode(fileItem.getFieldName()) + "\n");
                    break;
                }
            } catch (IOException e) {
                logger.error("Upload failed for file \n", e);
            } finally {
                fileItem.delete();
            }
        }

        // direct blocking unzip
        if (unzip && pathsToUnzip.size() > 0) {
            try {
                ZipHelper zip = ZipHelper.getInstance();
                //todo : in which workspace do we upload ?
                zip.unzip(pathsToUnzip, true, JCRSessionFactory.getInstance().getCurrentUserSession(),
                        (Locale) request.getSession().getAttribute(Constants.SESSION_UI_LOCALE));
            } catch (RepositoryException e) {
                logger.error("Auto-unzipping failed", e);
            } catch (GWTJahiaServiceException e) {
                logger.error("Auto-unzipping failed", e);
            }
        }
    } else {
        response.setContentType("text/html");
        for (FileItem fileItem : uploads.values()) {
            storeUploadedFile(request.getSession().getId(), fileItem);
            printWriter.write("<html><body>");
            printWriter.write("<div id=\"uploaded\" key=\"" + fileItem.getName() + "\" name=\""
                    + fileItem.getName() + "\"></div>\n");
            printWriter.write("</body></html>");
        }
    }
}

From source file:org.kaaproject.kaa.server.admin.client.servlet.ServletHelper.java

License:Apache License

private static String composeURL(String servletPath, String... params) {
    String ret = servletPath;/*from   w w  w .  jav  a  2  s  . co  m*/
    ret = ret.replaceAll("[\\?&]+$", "");
    String sep = ret.contains("?") ? "&" : "?";
    for (String par : params) {
        ret += sep + par;
        sep = "&";
    }
    for (Entry<String, List<String>> e : Window.Location.getParameterMap().entrySet()) {
        ret += sep + e.getKey() + "=" + e.getValue().get(0);
    }
    ret += sep + "random=" + Math.random();
    return UriUtils.encode(ret);
}

From source file:org.kie.workbench.common.stunner.core.client.util.SvgDataUriGenerator.java

License:Apache License

/**
 * Encodes the specified data-uri string in XML/UTF8 format.
 *///www  .j  a  v  a2s .  co m
public static String encodeUtf8(final String dataUriDecoded) {
    return SVG_DATA_URI_UTF8 + UriUtils.encode(dataUriDecoded).replace("#", "%23");
}

From source file:org.roda.wui.client.common.UserLogin.java

/**
 * Login into RODA Core/*from   w  ww  . j a va  2  s  . com*/
 */
public void login() {
    String currentURL = Window.Location.getHref().replaceAll("#", "%23");
    String hash = Window.Location.getHash();
    if (hash.length() > 0) {
        hash = hash.substring(1);
        hash = UriUtils.encode(hash);
    }
    String locale = LocaleInfo.getCurrentLocale().getLocaleName();
    String moduleBaseURL = GWT.getModuleBaseURL();
    moduleBaseURL = moduleBaseURL.substring(0, moduleBaseURL.length() - 2).substring(0,
            moduleBaseURL.indexOf('/'));
    Window.open(moduleBaseURL + "login?service=" + currentURL + "&hash=" + hash + "&locale=" + locale, "_self",
            "");
}