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

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

Introduction

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

Prototype

public static String encodePathSegment(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.gss_project.gss.web.client.FileList.java

License:Open Source License

/**
 * Makes a command to search for full name from a given username. 
 * Only after the completion of the command the celltable is shown
 * or the search for the next full name continues.
 *  //from  w w  w. j a  v a 2  s .c o  m
 * @param filesInput
 */
private void findFullNameAndUpdate(final List<FileResource> filesInput) {
    String aUserName = filesInput.get(0).getOwner();
    String path = GSS.get().getApiPath() + "users/" + URL.encodePathSegment(aUserName);

    GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path,
            false, null) {
        @Override
        public void onComplete() {
            final UserSearchResource result = getResult();
            for (UserResource user : result.getUsers()) {
                String username = user.getUsername();
                String userFullName = user.getName();
                GSS.get().putUserToMap(username, userFullName);
                if (filesInput.size() >= 1) {
                    filesInput.remove(filesInput.get(0));
                    if (filesInput.isEmpty()) {
                        showCellTable();
                    } else {
                        handleFullNames(filesInput);
                    }
                }
            }
        }

        @Override
        public void onError(Throwable t) {
            GWT.log("", t);
            GSS.get().displayError(
                    "Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
            if (filesInput.size() >= 1) {
                filesInput.remove(filesInput.get(0));
                handleFullNames(filesInput);
            }
        }
    };
    DeferredCommand.addCommand(gg);

}

From source file:org.gss_project.gss.web.client.PermissionsAddDialog.java

License:Open Source License

/**
 * Update the list of suggestions./*  w w  w  .  java  2 s  .co m*/
 */
protected void updateSuggestions() {
    final GSS app = GSS.get();
    String query = selectedUser.substring(0, selectedUser.length() - 1);
    GWT.log("Searching for " + query, null);

    GetCommand<UserSearchResource> eg = new GetCommand<UserSearchResource>(UserSearchResource.class,
            app.getApiPath() + "users/" + URL.encodePathSegment(query), false, null) {

        @Override
        public void onComplete() {
            suggestBox.hideSuggestionList();
            oracle.clear();
            UserSearchResource s = getResult();
            for (UserResource user : s.getUsers()) {
                GWT.log("Found " + user.getUsername(), null);
                oracle.add(user.getUsername());
            }
            suggestBox.showSuggestionList();
        }

        @Override
        public void onError(Throwable t) {
            if (t instanceof RestException)
                app.displayError("Unable to perform search: " + ((RestException) t).getHttpStatusText());
            else
                app.displayError("System error while searching for users: " + t.getMessage());
            GWT.log("", t);
            DisplayHelper.log(t.getMessage());
        }

    };
    DeferredCommand.addCommand(eg);
}

From source file:org.gss_project.gss.web.client.SearchResults.java

License:Open Source License

/**
 * Makes a command to search for full name from a given username. 
 * Only after the completion of the command the celltable is shown
 * or the search for the next full name continues.
 *  //from  w  ww. j a v  a 2  s  .  c om
 */
private void findFullNameAndUpdate(final String username, final Iterator<FileResource> iter) {
    String path = GSS.get().getApiPath() + "users/" + URL.encodePathSegment(username);

    GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path,
            false, null) {
        @Override
        public void onComplete() {
            final UserSearchResource result = getResult();
            for (UserResource user : result.getUsers()) {
                String username = user.getUsername();
                String userFullName = user.getName();
                GSS.get().putUserToMap(username, userFullName);
                handleFullNames(iter);
            }
        }

        @Override
        public void onError(Throwable t) {
            GWT.log("", t);
            GSS.get().displayError("Unable to fetch user's full name from the given username " + username);
            handleFullNames(iter);
        }
    };
    DeferredCommand.addCommand(gg);

}

From source file:org.gss_project.gss.web.client.VersionsList.java

License:Open Source License

/**
 * Makes a request to search for full name from a given username
 * and continues checking the next element of the List.
 *  /*w w  w .j a  v a2s.  c o m*/
 * @param input
 */

private void findFullNameAndUpdate(final List<FileResource> input) {
    final String aUserName = input.get(0).getOwner();
    String path = GSS.get().getApiPath() + "users/" + URL.encodePathSegment(aUserName);

    GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path,
            false, null) {
        @Override
        public void onComplete() {
            final UserSearchResource result = getResult();
            for (UserResource user : result.getUsers()) {
                String username = user.getUsername();
                String userFullName = user.getName();
                GSS.get().putUserToMap(username, userFullName);
                if (input.size() >= 1) {
                    input.remove(input.get(0));
                    if (input.isEmpty()) {
                        showVersionsTable();
                        return;
                    }
                    handleFullNames(input);
                }
            }
        }

        @Override
        public void onError(Throwable t) {
            GSS.get().displayError("Unable to fetch user's full name from the given username " + aUserName);
            if (input.size() >= 1) {
                input.remove(input.get(0));
                handleFullNames(input);
            }
        }
    };
    DeferredCommand.addCommand(gg);

}

From source file:org.jboss.as.quickstarts.gwthelloworld.client.local.HelloWorldClient.java

License:Apache License

/**
 * Handles a click of the button by sending an AJAX request to the HelloWorldResource and then updating the {@code result}
 * label in response./*from   www  . j av  a  2  s  .c  o m*/
 * 
 * @param e Details of the click event. Ignored by this handler.
 */
@UiHandler("sayHelloButton")
public void onButtonClick(ClickEvent e) {
    try {
        new RequestBuilder(RequestBuilder.GET, "hello/json/" + URL.encodePathSegment(name.getValue()))
                .sendRequest(null, new RequestCallback() {

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() == Response.SC_OK) {
                            HelloResponse r = (HelloResponse) JsonUtils.safeEval(response.getText());
                            result.setText(r.getResult());
                        } else {
                            handleError("Server responded with status code " + response.getStatusCode());
                        }
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        handleError(exception.getMessage());
                    }
                });
    } catch (RequestException exception) {
        handleError(exception.getMessage());
    }
}

From source file:org.jboss.errai.bus.client.framework.transports.HttpPollingHandler.java

License:Apache License

/**
 * Sends the given string oon the outbound communication channel (as a POST
 * request to the server).// ww w  . j  av  a  2  s  .  c  om
 *
 * @param payload
 *     The message to send. It is sent verbatim.
 * @param callback
 *     The callback to receive success or error notification. Note that
 *     this callback IS NOT CALLED if the request is cancelled.
 * @param extraParameters
 *     Extra paramets to include in the HTTP request (key is parameter name;
 *     value is parameter value).
 *
 * @throws com.google.gwt.http.client.RequestException
 *     if the request cannot be sent at all.
 */
public Request sendPollingRequest(final String payload, final Map<String, String> extraParameters,
        final RequestCallback callback) throws RequestException {

    // LogUtil.log("[bus] sendPollingRequest(" + payload + ")");

    final String serviceEntryPoint;
    final Map<String, String> parmsMap;
    final boolean waitChannel;
    boolean activeWaitChannel = false;

    final Iterator<RxInfo> iterator = pendingRequests.iterator();
    while (iterator.hasNext()) {
        final RxInfo pendingRx = iterator.next();
        if (pendingRx.getRequest().isPending() && pendingRx.isWaiting()) {
            //  LogUtil.log("[bus] ABORT SEND: " + pendingRx + " is waiting" );
            // return null;
            activeWaitChannel = true;
        }

        if (!pendingRx.getRequest().isPending()) {
            iterator.remove();
        }
    }

    if (!activeWaitChannel && receiveCommCallback.canWait() && !rxActive) {
        parmsMap = new HashMap<String, String>(extraParameters);
        parmsMap.put("wait", "1");
        serviceEntryPoint = messageBus.getInServiceEntryPoint();
        waitChannel = true;
    } else {
        parmsMap = extraParameters;
        serviceEntryPoint = messageBus.getOutServiceEntryPoint();
        waitChannel = false;
    }

    rxActive = true;

    final StringBuilder extraParmsString = new StringBuilder();
    for (final Map.Entry<String, String> entry : parmsMap.entrySet()) {
        extraParmsString.append("&").append(URL.encodePathSegment(entry.getKey())).append("=")
                .append(URL.encodePathSegment(entry.getValue()));
    }

    final long latencyTime = System.currentTimeMillis();

    final RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(messageBus.getApplicationLocation(serviceEntryPoint)) + "?z=" + getNextRequestNumber()
                    + "&clientId=" + URL.encodePathSegment(messageBus.getClientId())
                    + extraParmsString.toString());
    builder.setHeader("Content-Type", "application/json; charset=utf-8");

    final RxInfo rxInfo = new RxInfo(System.currentTimeMillis(), waitChannel);

    try {
        // LogUtil.log("[bus] TX: " + payload);
        final Request request = builder.sendRequest(payload, new RequestCallback() {
            @Override
            public void onResponseReceived(final Request request, final Response response) {
                if (!waitChannel) {
                    measuredLatency = (int) (System.currentTimeMillis() - latencyTime);
                }

                pendingRequests.remove(rxInfo);
                callback.onResponseReceived(request, response);
                rxNumber++;
                rxActive = false;
            }

            @Override
            public void onError(final Request request, final Throwable exception) {
                pendingRequests.remove(rxInfo);
                callback.onError(request, exception);
                rxActive = false;
            }
        });

        rxInfo.setRequest(request);
        pendingRequests.add(rxInfo);

        return request;
    } catch (RequestException e) {
        throw e;
    }
}

From source file:org.jboss.errai.bus.client.framework.transports.SSEHandler.java

License:Apache License

@Override
public void configure(final Message capabilitiesMessage) {
    configured = true;//from   w  w  w.  j a  v  a  2 s  .  c o m

    if (!isSSESupported()) {
        hosed = true;
        unsupportedReason = UNSUPPORTED_MESSAGE_NO_SERVER_SUPPORT;
        LogUtil.log("this browser does not support SSE");
        return;
    }

    this.sseEntryPoint = URL
            .encode(clientMessageBus.getApplicationLocation(clientMessageBus.getInServiceEntryPoint()))
            + "?z=0000&sse=1&clientId=" + URL.encodePathSegment(clientMessageBus.getClientId());

}

From source file:org.jboss.errai.enterprise.client.jaxrs.api.PathSegmentImpl.java

License:Apache License

public String getEncodedPathWithParameters() {
    StringBuilder builder = new StringBuilder(URL.encodePathSegment(path));
    for (String matrixParamName : matrixParameters.keySet()) {
        builder.append(";" + matrixParamName + "=")
                .append(URL.encodePathSegment(matrixParameters.getFirst(matrixParamName)));
    }//from   w w w  .j  a v a2s.  co  m

    return builder.toString();
}

From source file:org.jbpm.formbuilder.client.URLBuilder.java

License:Apache License

private static String encode(String string) {
    return URL.encodePathSegment(string);
}

From source file:org.obiba.opal.web.gwt.app.client.fs.FileDtos.java

License:Open Source License

public static String getLink(FileDto file) {
    // Append / if pasting directly under File System (/)
    return "/files" + file.getPath() + ("/".equals(file.getPath()) ? URL.encodePathSegment("/") : "");
}