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

License:Open Source License

/**
 * @param view//  ww  w.  j  a  v  a2 s. co  m
 */
public void fetchFiles(final FileNodeBrowser view, String repoURI, String prefix) {
    String url = repoURI + "/list";
    if (!isNullOrBlank(prefix)) {
        url += "?prefix=" + URL.encodeQueryString(prefix);
    }
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    GWT.log(response.getText());
                    RepoListResponse result = RepoListResponse.parseJSON(response.getText());
                    List<FileNode> crumbs = result.getCrumbs();
                    List<FileNode> namesWithPlaceholders = result.getFiles();
                    if (crumbs != null && CommandActivity.this.placeholderMap != null) {
                        String lastPath = "";
                        if (crumbs.size() > 1) {
                            FileNode lastCrumb = crumbs.get(crumbs.size() - 1);
                            lastPath = getCanonicalName(lastCrumb) + "/";
                        }
                        GWT.log("lastPath=" + lastPath);
                        if (CommandActivity.this.placeholderMap.containsKey(lastPath)) {
                            java.util.Collection<FileNode> placeholders = CommandActivity.this.placeholderMap
                                    .get(lastPath).values();
                            namesWithPlaceholders = new ArrayList<FileNode>(
                                    placeholders.size() + result.getFiles().size());
                            GWT.log("adding placeholder");
                            namesWithPlaceholders.addAll(placeholders);
                            namesWithPlaceholders.addAll(result.getFiles());
                        }
                    }
                    view.show(result.getCrumbs(), namesWithPlaceholders);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }

}

From source file:n3phele.client.presenter.CommandActivity.java

License:Open Source License

/**
 * @param view//from   www  .  j  av a  2  s  .c om
 * @param repoURI
 * @param filename
 */
public void checkExists(final FileNodeBrowser view, String repoURI, final String filename) {
    String url = repoURI + "/validate";
    if (filename != null) {
        url += "?filename=" + URL.encodeQueryString(filename);
    }
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    GWT.log(response.getText());
                    boolean result = ValidationResponse.parseJSON(response.getText()).getExists();
                    if (result)
                        view.enableRun(filename);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }

}

From source file:n3phele.client.presenter.CommandListActivity.java

License:Open Source License

public void fetch(final int start, String search, boolean preferred) {
    lastStart = start;/*from ww  w .  j a  va  2s .co m*/
    String url = URL.encode(
            collectionUrl + "&start=" + start + "&end=" + (start + PAGESIZE) + "&preferred=" + preferred);
    if (!isBlankOrNull(search))
        url += "&search=" + URL.encodeQueryString(search);
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Request error " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    Collection<Command> c = Command.asCollection(response.getText());
                    updateData(c.getUri(), c.getElements(), start, c.getTotal());
                } else {
                    Window.alert("Response error " + response.getStatusText());
                }
            }
        });
    } catch (RequestException exception) {
        Window.alert("Request exception " + exception.getMessage());
    }
}

From source file:n3phele.client.presenter.CreateServiceActivity.java

License:Open Source License

private void updateAccountDetails(String url, String name, String description, String cloud, String cloudId,
        final String password) {

    // Send request to server and catch any errors.
    if (url == null || url.trim().length() == 0 || url.equals("null")) {
        url = cacheManager.ServiceAddress + "account";
    }/* w  w  w  .  ja v a 2  s  .  co  m*/
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("name=");
    args.append(URL.encodeQueryString(name));
    if (description != null && description.length() != 0) {
        args.append("&description=");
        args.append(URL.encodeQueryString(description));
    }
    args.append("&cloud=");
    args.append(URL.encodeQueryString(cloud));
    if (password != null && password.length() > 0) {
        args.append("&accountId=");
        args.append(URL.encodeQueryString(cloudId));
        args.append("&secret=");
        args.append(URL.encodeQueryString(password));
    }
    try {
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    goToPrevious();
                } else if (201 == response.getStatusCode()) {
                    goToPrevious();
                } else {
                    Window.alert("Account update error " + response.getStatusCode() + response.getStatusText());
                }
            }

        });
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.CreateServiceActivity.java

License:Open Source License

public void exec(String name, Context context) {
    List<String> params = new ArrayList<String>();
    String action = "StackService";
    if (name == null || name.trim().length() == 0) {
        name = null;//  w ww.ja  v a 2 s .c  om
    }
    params.add("action=" + URL.encodeQueryString(action));
    String arg = "";
    params.add("arg=" + URL.encodeQueryString(arg.trim()));
    if (name != null)
        params.add("name=" + URL.encodeQueryString(name.trim()));

    String url = cacheManager.ServiceAddress + "process/exec";
    String seperator = "?";
    for (String param : params) {
        url = url + seperator + param;
        seperator = "&";
    }
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/json");

    try {
        GWT.log("Context :" + context.toJSON().toString());
        Request msg = builder.sendRequest(context == null ? null : context.toJSON().toString(),
                new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        GWT.log("Couldn't retrieve JSON " + exception.getMessage());
                        Window.alert("Couldn't retrieve JSON " + exception.getMessage());
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (201 == response.getStatusCode()) {
                            GWT.log(response.getText() + " " + response.getHeader("location"));
                            goToPrevious();
                        } else {
                            Window.alert("Error code: " + response.getStatusCode() + " Status Text:"
                                    + response.getStatusText() + "\n" + response.getText());
                            GWT.log("Couldn't submit command (" + response.getStatusText() + " "
                                    + response.getText() + ")");

                        }
                    }
                });
    } catch (RequestException e) {
        Window.alert("Request exception " + e.getMessage() + "\n" + e.toString());
    }
}

From source file:n3phele.client.presenter.RepoActivity.java

License:Open Source License

private void updateRepoDetails(String url, String name, String description, String target, String kind,
        String root, boolean isPublic, String authId, String password) {

    if (url == null || url.trim().length() == 0) {
        url = cacheManager.ServiceAddress + "repository";
    }/*from   w  w  w . j  ava2  s  .  c o  m*/
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("name=");
    args.append(URL.encodeQueryString(name));
    if (description != null && description.length() != 0) {
        args.append("&description=");
        args.append(URL.encodeQueryString(description));
    }
    args.append("&target=");
    args.append(URL.encodeQueryString(target));
    args.append("&kind=");
    args.append(URL.encodeQueryString(kind));
    args.append("&root=");
    args.append(URL.encodeQueryString(root));
    args.append("&isPublic=");
    args.append(URL.encode(isPublic ? "true" : "false"));
    if (password != null && password.length() > 0) {
        args.append("&repositoryId=");
        args.append(URL.encodeQueryString(authId));
        args.append("&secret=");
        args.append(URL.encodeQueryString(password));
    }
    GWT.log(args.toString());
    GWT.log(authId);
    GWT.log(password);
    try {
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    goToPrevious();
                } else if (201 == response.getStatusCode()) {
                    goToPrevious();
                } else {
                    Window.alert(
                            "Repository update error " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.RepoContentActivity.java

License:Open Source License

/**
 * @param node//w  w w. j  a  v  a2  s .com
 */
public void makePublic(final FileNode node, boolean isPublic) {
    String url = node.getRepository() + "/permissions";
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("isPublic=");
    args.append(URL.encodeQueryString(Boolean.toString(isPublic)));
    args.append("&filename=");
    args.append(URL.encodeQueryString(getCanonicalName(node)));
    try {
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    GWT.log("Reply is" + response.getText());
                    GWT.log("Headers is " + response.getHeadersAsString());
                    GWT.log("Status Text " + response.getStatusText());
                    fetchFiles(repositoryUri, node.getPath());
                } else {
                    Window.alert("Update failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Update exception: " + e.toString());
    }
}

From source file:n3phele.client.presenter.RepoContentActivity.java

License:Open Source License

/**
 * @param node/*from   w  w w  . j a  va 2 s  .  c  om*/
 * @param fileDetailsPanel 
 */
public void getOrigin(final FileNode node, final FileDetailsPanel fileDetailsPanel) {

    String url = node.getRepository() + "/origin" + "?name=" + URL.encodeQueryString(node.getName());
    if (!isNullOrBlank(node.getPath())) {
        url += "&path=" + URL.encodeQueryString(node.getPath());
    }

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    Origin origin = Origin.asOrigin(response.getText());
                    provideOrigin(node, origin, fileDetailsPanel);
                } else {
                    Window.alert(
                            "Origin fetch failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Origin fetch exception: " + e.toString());
    }

}

From source file:n3phele.client.presenter.RepoContentActivity.java

License:Open Source License

/**
 * @param node/*ww w  .  ja  va 2  s .  c o m*/
 * @param originPanel 
 */
public void getSignature(final String file) {

    String url = this.repo.getUri() + "/sign?name=" + URL.encodeQueryString(file);
    final String uri = this.repositoryUri;

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    if (uri.equals(RepoContentActivity.this.repositoryUri)) {
                        UploadSignature signature = UploadSignature.asUploadSignature(response.getText());
                        provideSignature(signature);
                    }
                } else {
                    Window.alert(
                            "Signature fetch failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Signature fetch exception: " + e.toString());
    }

}

From source file:n3phele.client.presenter.RepoContentActivity.java

License:Open Source License

/**
 * @param view//from w w w .j av  a 2  s  .c  om
 */
public void fetchFiles(String repoURI, final String prefix) {
    String url = repoURI + "/list";
    if (prefix != null) {
        url += "?prefix=" + URL.encodeQueryString(prefix);
    }
    this.lastRepoURI = repoURI;
    this.lastPrefix = prefix;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    GWT.log(response.getText());
                    RepoListResponse result = RepoListResponse.parseJSON(response.getText());
                    List<FileNode> crumbs = result.getCrumbs();
                    List<FileNode> namesWithPlaceholders = result.getFiles();
                    if (crumbs != null && placeholderMap != null) {
                        String lastPath = "";
                        if (crumbs.size() > 1) {
                            FileNode lastCrumb = crumbs.get(crumbs.size() - 1);
                            lastPath = getCanonicalName(lastCrumb) + "/";
                        }
                        GWT.log("lastPath=" + lastPath);
                        if (placeholderMap.containsKey(lastPath)) {
                            java.util.Collection<FileNode> placeholders = placeholderMap.get(lastPath).values();
                            namesWithPlaceholders = new ArrayList<FileNode>(
                                    placeholders.size() + result.getFiles().size());
                            GWT.log("adding placeholder");
                            namesWithPlaceholders.addAll(placeholders);
                            namesWithPlaceholders.addAll(result.getFiles());
                        }
                    }
                    updateRepoContent(result.getCrumbs(), namesWithPlaceholders);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }

}