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

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

Introduction

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

Prototype

public static String encode(String decodedURL) 

Source Link

Document

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

Usage

From source file:com.ricbit.gibit.client.SearchState.java

License:Apache License

public String getUrl() {
    String url = "search?";
    if (page != 0) {
        url += "p=" + page + ";";
    }//from   ww  w . j  a v  a  2  s.  com
    url += "q=" + query;
    return URL.encode(url);
}

From source file:com.robustaweb.library.gwt.GwtRestClient.java

License:Apache License

/**
 * Encoding is done automatically with the client. The method will so return the exactly same value
 * @param nameOrValue/*from  w ww . j  a v  a  2 s. c  o  m*/
 * @return the exactly same value
 */
@Override
protected String encodeParameter(String nameOrValue) {
    return URL.encode(nameOrValue);
}

From source file:com.seanchenxi.gwt.uri.template.EncodeRule.java

License:Apache License

protected String doEncode(String input, boolean passReserved) {
    return passReserved ? URL.encodeQueryString(input).replace("!", "%21") : URL.encode(input);
}

From source file:com.seanchenxi.gwt.wordpress.json.core.JRequestURLImpl.java

License:Apache License

@Override
public String setPrefix(String urlPrefix) {
    if (request == null) {
        StringBuilder sb = new StringBuilder(urlPrefix);
        sb.append(SLASH).append(method).append(SLASH);
        if (!params.isEmpty()) {
            sb.append(START);/*from  w  w  w  .ja va  2s.c  o m*/
            for (String name : params.keySet()) {
                sb.append(name).append(EQUAL).append(convert(params.get(name)));
                sb.append(AND);
            }
            sb.deleteCharAt(sb.lastIndexOf(AND));
        }
        request = sb.toString();
        if (encode) {
            request = URL.encode(request);
        }
    }
    return request;
}

From source file:com.sensia.gwt.relaxNG.RNGParser.java

License:Open Source License

public void parse(final String url, final RNGParserCallback callback) {
    this.callback = callback;

    // if grammar has already been parsed
    grammar = grammarCache.get(url);//  w  w  w  .  ja va2 s  .  c o  m
    if (grammar != null) {
        callback.onParseDone(grammar);
        return;
    }

    // otherwise load included grammar and parse it asynchronously
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    try {

        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // Couldn't connect to server (could be timeout, SOP violation, etc.)
            }

            public void onResponseReceived(Request request, Response resp) {
                if (200 == resp.getStatusCode()) {
                    String text = resp.getText();
                    parse(url, text);
                } else {
                    // Handle the error.  Can get the status text from response.getStatusText()
                }
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:com.sensia.gwt.relaxNG.XMLSensorMLParser.java

License:Open Source License

/**
 * Gets the content of the remote file and callback the result.
 * The request is asynchronous//from w ww . j  av a  2  s .c o  m
 *
 * @param url the url
 * @param callback the callback
 */
public void parse(final String url, final RNGParserCallback callback) {
    this.callback = callback;

    // if grammar has already been parsed
    grammar = grammarCache.get(url);
    if (grammar != null) {
        callback.onParseDone(grammar);
        return;
    } else {
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
        try {

            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                    // Couldn't connect to server (could be timeout, SOP
                    // violation, etc.)

                }

                public void onResponseReceived(Request request, Response resp) {
                    if (200 == resp.getStatusCode()) {
                        String text = resp.getText();
                        try {
                            parse(url, text);
                        } catch (Exception ex) {
                            Window.alert(
                                    "An error occured while parsing the file. Check that it is a valid XML file");
                        }
                    } else {
                        // Handle the error. Can get the status text from
                        // response.getStatusText()
                        Window.alert(
                                "Cannot get the file from server, it does not exist or you do not have sufficient security credentials to access it.");
                    }
                }
            });
        } catch (RequestException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.tasktop.c2c.server.common.web.client.navigation.Navigation.java

License:Open Source License

public static String appendQueryParameterToUrl(String url, String paramName, String paramValue) {

    // Make this method null-safe - some calling paths start with a null URL.
    String retUrl = (url == null ? "" : url);

    String encodedValue = URL.encode(paramValue);
    String encodedName = URL.encode(paramName);

    // Check if we already have some parameters in this URL.
    if (retUrl.indexOf('?') > 0) {
        // Already have a parameter, so the next one will be added on with &
        retUrl += "&";
    } else {//from  w w  w  .j a  v a 2 s  . co  m
        // No parameters yet, so indicate the first one with ?
        retUrl += "?";
    }

    // Attach the rest of our parameter now.
    retUrl += encodedName + "=" + encodedValue;

    return retUrl;
}

From source file:com.tasktop.c2c.server.common.web.shared.URLEncoding.java

License:Open Source License

/**
 * encode the given URI part.When {@link GWT#isClient() is client = true}, GWT client URL encoding is used.
 *///from  w w  w. j  ava 2 s.  c om
public static String encode(String part, char[] excludes) {
    if (GWT.isClient()) {
        return URL.encode(part).replace("%20", "+");
    }
    StringBuilder result = new StringBuilder(part.length() + 10);
    for (int x = 0; x < part.length(); ++x) {
        // see http://en.wikipedia.org/wiki/Percent-encoding
        char c = part.charAt(x);
        if (isUnreserved(c) || excluded(c, excludes)) {
            result.append(c);
        } else {
            if (c == ' ') {
                result.append('+');
            } else {
                result.append('%');
                result.append(chars[c >> 4]);
                result.append(chars[c & 0x0F]);
            }
        }
    }
    return result.toString();
}

From source file:com.teardrop.client.EditTree.java

License:Apache License

private void doFetchURL(String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    try {/*from  www  .  ja v  a 2s.  co m*/
        builder.sendRequest("", new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Couldn't connect to server (could be timeout, SOP violation, etc.)");
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    generateAvailableEngineList(JSONParser.parse(response.getText()));
                    editPanel.getView().refresh();
                } else {
                    Window.alert("Incorrect status: " + response.getStatusText());
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Couldn't connect to server (could be timeout, SOP violation, etc.)");
    }
}

From source file:com.teardrop.client.EditTree.java

License:Apache License

private void doPostURL(String post, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    try {//  w w  w .  java  2s . c  o  m
        builder.setHeader("Content-Length", String.valueOf(post.length()));
        builder.sendRequest(post, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Couldn't connect to server (could be timeout, SOP violation, etc.)");
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    centerPanel.remove(editPanel);
                    engTree.loadEngineTree();
                } else {
                    Window.alert("Incorrect status: " + response.getStatusText());
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Couldn't connect to server (could be timeout, SOP violation, etc.)");
    }
}