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:n3phele.client.presenter.UserActivity.java

License:Open Source License

public UserActivity(String name, ClientFactory factory) {
    if (name == null || name.length() == 0) {
        name = AuthenticatedRequestFactory.getUser().getName();
    }/*from ww w .  j a  v  a2  s  .co m*/
    if (isSelf = name.equals(AuthenticatedRequestFactory.getUser().getName())) {
        this.user = AuthenticatedRequestFactory.getUser();
    }
    this.name = name;
    this.placeController = factory.getPlaceController();
    this.display = factory.getUserView();
    userUrl = URL.encode(factory.getCacheManager().ServiceAddress + "user");
}

From source file:name.cphillipson.experimental.gwt.client.module.common.widget.suggest.MultivalueSuggestBox.java

License:Apache License

/**
 * Retrieve Options (name-value pairs) that are suggested from the REST endpoint
 * //from w  w  w  .  jav a2s  . co m
 * @param query
 *            - the String search term
 * @param from
 *            - the 0-based begin index int
 * @param to
 *            - the end index inclusive int
 * @param callback
 *            - the OptionQueryCallback to handle the response
 */
private void queryOptions(final String query, final int from, final int to,
        final OptionQueryCallback callback) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
            URL.encode(m_restEndpointUrl + "?q=" + query + "&indexFrom=" + from + "&indexTo=" + to));

    // Set our headers
    builder.setHeader("Accept", "application/json");
    builder.setHeader("Accept-Charset", "UTF-8");

    builder.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) {
            final JSONValue val = JSONParser.parse(response.getText());
            final JSONObject obj = val.isObject();
            final int totSize = (int) obj.get(OptionResultSet.TOTAL_SIZE).isNumber().doubleValue();
            final OptionResultSet options = new OptionResultSet(totSize);
            final JSONArray optionsArray = obj.get(OptionResultSet.OPTIONS).isArray();

            if (options.getTotalSize() > 0 && optionsArray != null) {

                for (int i = 0; i < optionsArray.size(); i++) {
                    if (optionsArray.get(i) == null) {
                        /*
                         * This happens when a JSON array has an invalid trailing comma
                         */
                        continue;
                    }

                    final JSONObject jsonOpt = optionsArray.get(i).isObject();
                    final Option option = new Option();
                    option.setName(jsonOpt.get(OptionResultSet.DISPLAY_NAME).isString().stringValue());
                    option.setValue(jsonOpt.get(OptionResultSet.VALUE).isString().stringValue());
                    options.addOption(option);
                }
            }
            callback.success(options);
        }

        @Override
        public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
            callback.error(exception);
        }
    });

    try {
        builder.send();
    } catch (final RequestException e) {
        updateFormFeedback(FormFeedback.ERROR, "Error: " + e.getMessage());
    }
}

From source file:net.dancioi.webdav.client.Propfind.java

License:Open Source License

/**
 * Override the method to set the "Depth" parameter.
 *///w w w  . ja v  a  2 s  . co m
protected void logOn(String command, String url, String username, String password) {
    RequestBuilderWebdav builder = new RequestBuilderWebdav(command, URL.encode(url));
    builder.setHeader("Depth", "0");
    builder.setUser(username);
    builder.setPassword(password);
    tryRequest(builder);
}

From source file:net.dancioi.webdav.client.Put.java

License:Open Source License

private void execute() {
    RequestBuilderWebdav builder = new RequestBuilderWebdav("PUT", URL.encode(url));

    builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    builder.setUser(username);/*  w  w w  .j a va  2  s .co  m*/
    builder.setPassword(password);

    tryRequest(builder);
}

From source file:net.dancioi.webdav.client.WdHttpMethod.java

License:Open Source License

/**
 * Make HTTP request and process the associated response.
 * @param command GET, PUT, MKCOL, DELETE, PROPFIND
 * @param url//from  w w  w.  java2 s .c o m
 * @param username
 * @param password
 */
protected void logOn(String command, String url, String username, String password) {
    RequestBuilderWebdav builder = new RequestBuilderWebdav(command, URL.encode(url));

    builder.setUser(username);
    builder.setPassword(password);

    tryRequest(builder);
}

From source file:net.sylvek.sharemyposition.client.Client.java

License:Open Source License

private void addLinks(String url, String address) {
    location.setVisible(false);/*  w  w w .j a va2s.  c  om*/

    RootPanel.get("links").add(new HTML("<a class='tinylink' href='"
            + "mailto:?subject=my%20current%20position&body=i%20am%20here,%20" + url + " " + URL.encode(address)
            + "'>share my position by mail</a><br/>or copy this link and send it by sms"));

    RootPanel.get("tinyurl").add(new HTML("<a class='tinylink' href='" + url + "'>" + url + "</a>"));
}

From source file:next.celebs.api.HTTP.java

License:Apache License

public static void doPost(String url, String postData, ResponseReader reader) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    try {/*  www .j  a v  a  2  s.c o m*/
        builder.sendRequest(postData, new Callback_(reader));
    } catch (RequestException e) {
        reader.onError(null, e);
    }
}

From source file:next.celebs.api.HTTP.java

License:Apache License

public static void doPostJSON(String url, String jsonData, ResponseReader reader) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    builder.setHeader("Content-Type", "application/json");
    try {/*from  w w  w . jav a  2 s .  c o  m*/
        builder.sendRequest(jsonData, new Callback_(reader));
    } catch (RequestException e) {
        reader.onError(null, e);
    }
}

From source file:next.celebs.api.HTTP.java

License:Apache License

public static void doGet(String url, ResponseReader responseReader) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));

    try {/*from  www. j a  v a2s. c  o  m*/
        builder.sendRequest(null, new Callback_(responseReader));
    } catch (RequestException e) {
        Window.alert("doGet:exc " + e.getMessage());
        Log.error("RequestException: " + e.getMessage());
        responseReader.onError(null, e);
    }
}

From source file:next.celebs.api.HTTP.java

License:Apache License

public static void doGetRelaxed(String url, ResponseReader responseReader) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    try {/*from w  ww  . j av a2 s .  c o m*/
        builder.sendRequest(null, new RelaxedCallback_(responseReader));
    } catch (RequestException e) {
        responseReader.onError(null, e);
    }
}