Example usage for com.google.gwt.http.client URL encodeQueryString

List of usage examples for com.google.gwt.http.client URL encodeQueryString

Introduction

In this page you can find the example usage for com.google.gwt.http.client URL encodeQueryString.

Prototype

public static String encodeQueryString(String decodedURLComponent) 

Source Link

Document

Returns a string where all characters that are not valid for a URL component have been escaped.

Usage

From source file:org.rstudio.studio.client.common.DefaultGlobalDisplay.java

License:Open Source License

@Override
public void openRStudioLink(String linkName, boolean includeVersionInfo) {
    // build url//from w  ww . j  a  va 2 s . c om
    final SessionInfo sessionInfo = session_.getSessionInfo();
    String url = "http://www.rstudio.org/links/";
    url += URL.encodePathSegment(linkName);
    if (includeVersionInfo) {
        url += "?version=" + URL.encodeQueryString(sessionInfo.getRstudioVersion());
        url += "&mode=" + URL.encodeQueryString(sessionInfo.getMode());
    }

    // open window
    openWindow(url);
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

public String getFileUrl(FileSystemItem file) {
    if (Desktop.isDesktop()) {
        return Desktop.getFrame().getUriForPath(file.getPath());
    }//from  w ww .  j a  va2 s . c o  m

    if (!file.isDirectory()) {
        if (file.isWithinHome()) {
            return getApplicationURL(FILES_SCOPE) + "/" + file.homeRelativePath();
        } else {
            String url = getApplicationURL(FILE_SHOW);
            url += "?path=" + URL.encodeQueryString(file.getPath());
            return url;
        }
    } else {
        return null;
    }
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

public String getFileExportUrl(String name, FileSystemItem file) {
    return getApplicationURL(EXPORT_SCOPE) + "/" + URL.encodePathSegment(name) + "?" + "name="
            + URL.encodeQueryString(name) + "&" + "file=" + URL.encodeQueryString(file.getPath());
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

public String getFileExportUrl(String name, FileSystemItem parentDirectory, ArrayList<String> filenames) {
    // build url params for files
    StringBuilder files = new StringBuilder();
    for (int i = 0; i < filenames.size(); i++) {
        files.append("file").append(i).append("=");
        files.append(URL.encodeQueryString(filenames.get(i)));
        files.append("&");
    }//from w w w.ja v a2 s .c o m

    // return url
    return getApplicationURL(EXPORT_SCOPE) + "/" + URL.encodePathSegment(name) + "?" + "name="
            + URL.encodeQueryString(name) + "&" + "parent=" + URL.encodeQueryString(parentDirectory.getPath())
            + "&" + files.toString();
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

public String getProgressUrl(String message) {
    String url = getApplicationURL(SOURCE_SCOPE + "/" + "progress");
    url += "?message=" + URL.encodeQueryString(message);
    return url;/*  ww w. j  a  v  a 2 s  .  com*/
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.java

License:Open Source License

void previewRd() {
    saveThenExecute(null, new Command() {
        @Override/*from ww w.  j  a v  a  2  s.  c om*/
        public void execute() {
            String previewURL = "help/preview?file=";
            previewURL += URL.encodeQueryString(docUpdateSentinel_.getPath());
            events_.fireEvent(new ShowHelpEvent(previewURL));
        }
    });
}

From source file:org.sigmah.client.util.ClientUtils.java

License:Open Source License

/**
 * Sends the browser a new {@code mailto} request with the given subject and mail addresses.
 * /*from   w w w  .  j  a  v  a  2  s. c  o  m*/
 * @param subject
 *          The mail's subject (can be null).
 * @param body
 *          The mail's body (can be null).
 * @param addresses
 *          The mail's addresses collection.
 */
public static final void mailTo(final String subject, final String body, final Collection<String> addresses) {

    if (isEmpty(addresses)) {
        return;
    }

    // Filters mails addresses.
    final List<String> filteredMails = new ArrayList<String>(addresses.size());
    for (final String address : addresses) {

        if (isNotBlank(address) && EMAIL_CLIENT_REGEXP.test(address.trim())) {
            filteredMails.add(address);
        }
    }
    if (isEmpty(filteredMails)) {
        return;
    }
    Collections.sort(filteredMails);

    // Builds mailto link.
    final StringBuilder mailTos = new StringBuilder("mailto:");
    for (final String mail : filteredMails) {
        mailTos.append(mail);
        mailTos.append(";");
    }
    mailTos.deleteCharAt(mailTos.length() - 1);
    if (isNotBlank(subject)) {
        mailTos.append("?subject=");
        mailTos.append(URL.encodeQueryString(subject));
    }
    if (isNotBlank(body)) {
        mailTos.append((isNotBlank(subject) ? "&" : "?") + "body=");
        mailTos.append(URL.encodeQueryString(body));
    }

    Window.Location.assign(mailTos.toString());

}

From source file:org.sigmah.shared.servlet.ServletRequestBuilder.java

License:Open Source License

/**
 * Sends the request with its optional parameter(s) (including {@code POST} parameters).
 * /*from   www  . ja va 2  s  . co m*/
 * @param callback
 *          The {@code RequestCallback}.
 * @throws ServletRequestException
 *           If an error occurs during request call.
 */
public void send(final RequestCallback callback) throws ServletRequestException {

    final RequestBuilder requestBuilder = new RequestBuilder(requestMethod, urlBuilder.toString());

    requestBuilder.setCallback(callback != null ? callback : Void);

    final StringBuilder builder = new StringBuilder();

    if (ClientUtils.isNotEmpty(requestAttributes)) {

        final Iterator<String> iterator = requestAttributes.keySet().iterator();

        while (iterator.hasNext()) {
            final String next = iterator.next();
            final String attribute = requestAttributes.get(next);

            if (attribute != null) {
                builder.append(URL.encodeQueryString(next));
                builder.append('=');
                builder.append(URL.encodeQueryString(attribute));
                if (iterator.hasNext()) {
                    builder.append('&');
                }
            }
        }
    }

    if (isPostMethod()) {
        requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
        requestBuilder.setRequestData(builder.length() > 0 ? builder.toString() : null);
    }

    try {

        requestBuilder.send();

    } catch (final RequestException e) {
        throw new ServletRequestException("Servlet request '" + builder + "' execution fails.", e);
    }
}

From source file:org.sigmah.shared.servlet.ServletUrlBuilder.java

License:Open Source License

/**
 * <p>/*w w w .  j a v a2 s .com*/
 * Builds the URL with all its parameters.
 * </p>
 * <p>
 * Necessary parameters (<em>authentication token</em>, etc.) are automatically added into the request parameters.
 * </p>
 * 
 * @return The generated URL.
 */
private String buildUrl() {

    // Adds session token id in parameters map.
    addParameter(ServletConstants.AUTHENTICATION_TOKEN,
            ClientUtils.toList(authenticationProvider.get().getAuthenticationToken()));
    addParameter(ServletConstants.SERVLET_METHOD, ClientUtils.toList(servletMethod.getName()));
    addParameter(ServletConstants.ORIGIN_PAGE_TOKEN, ClientUtils.toList(pageManager.getCurrentPageToken()));
    addParameter(ServletConstants.RANDOM, ClientUtils.toList(Math.random()));

    final StringBuilder builder = new StringBuilder();

    builder.append(servlet.getUrl()).append('?');
    final Iterator<String> keyIt = parameters.keySet().iterator();

    while (keyIt.hasNext()) {

        final String key = keyIt.next();
        final String encodedKey = URL.encodeQueryString(key);
        final List<String> params = parameters.get(key);

        builder.append(encodedKey).append('=');

        if (ClientUtils.isNotEmpty(params)) {
            // Key value(s).
            final Iterator<String> paramIt = params.iterator();

            while (paramIt.hasNext()) {
                builder.append(URL.encodeQueryString(paramIt.next()));
                if (paramIt.hasNext()) {
                    builder.append('&').append(encodedKey).append('=');
                }
            }
        }

        if (keyIt.hasNext()) {
            builder.append('&');
        }
    }

    return builder.toString();
}

From source file:org.swellrt.api.CustomJsoSearchBuilderImpl.java

License:Apache License

private static String getUrl(SearchRequest searchRequest) {
    String query = URL.encodeQueryString(searchRequest.getQuery());
    String params = "?query=" + query + "&index=" + searchRequest.getIndex() + "&numResults="
            + searchRequest.getNumResults();
    return SEARCH_URL_BASE + "/" + params;
}