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:org.jahia.ajax.gwt.client.widget.toolbar.action.ExecuteActionItem.java

License:Open Source License

protected void doAction() {
    final List<GWTJahiaNode> gwtJahiaNodes = linker.getSelectionContext().getMultipleSelection();
    for (GWTJahiaNode gwtJahiaNode : gwtJahiaNodes) {
        String baseURL = org.jahia.ajax.gwt.client.util.URL
                .getAbsoluteURL(JahiaGWTParameters.getContextPath() + "/cms/render");
        String localURL = baseURL + "/default/" + JahiaGWTParameters.getLanguage()
                + URL.encode(gwtJahiaNode.getPath());
        linker.loading(Messages.get("label.executing", "Executing action ..."));
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                localURL.replaceAll("#", "%23") + "." + action + ".do");
        try {//from ww  w  . j  a  v a  2 s  . co  m
            String requestData = getRequestData();
            // Add parameters values to the request data to be sent.
            if (parameterData != null) {
                requestData = requestData != null && requestData.length() > 0
                        ? (requestData + "&" + parameterData)
                        : parameterData;
            }
            if (requestData != null) {
                builder.setHeader("Content-type", "application/x-www-form-urlencoded");
            }
            builder.setHeader("accept", "application/json");
            builder.sendRequest(requestData, new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                    com.google.gwt.user.client.Window.alert("Cannot create connection");
                    linker.loaded();
                    actionExecuted(500);
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() != 200) {
                        com.google.gwt.user.client.Window
                                .alert("Cannot contact remote server : error " + response.getStatusCode());
                    }
                    try {
                        JSONObject jsondata = JSONParser.parseStrict(response.getText()).isObject();
                        if (jsondata.get("refreshData") != null) {
                            JSONObject refreshData = jsondata.get("refreshData").isObject();
                            @SuppressWarnings("rawtypes")
                            Map data = new HashMap();
                            for (String s : refreshData.keySet()) {
                                data.put(s, refreshData.get(s));
                            }
                            linker.refresh(data);
                        }
                        if (jsondata.get("messageDisplay") != null) {
                            JSONObject object = jsondata.get("messageDisplay").isObject();
                            String title = object.get("title").isString().stringValue();
                            String text = object.get("text").isString().stringValue();
                            String type = object.get("messageBoxType").isString().stringValue();
                            if ("alert".equals(type)) {
                                MessageBox.alert(title, text, null);
                            } else {
                                MessageBox.info(title, text, null);
                            }
                        }
                    } catch (Exception e) {
                        // Ignore
                    }
                    linker.loaded();
                    actionExecuted(response.getStatusCode());
                }
            });

        } catch (RequestException e) {
            // Code omitted for clarity
        }
    }
}

From source file:org.jboss.bpm.console.client.common.AbstractRESTAction.java

License:Open Source License

public void execute(final Controller controller, final Object object) {
    final String url = getUrl(object);
    RequestBuilder builder = new RequestBuilder(getRequestMethod(), URL.encode(url));

    ConsoleLog.debug(getRequestMethod() + ": " + url);

    try {//  w w  w  .  j ava  2 s.c om
        //controller.handleEvent( LoadingStatusAction.ON );
        if (getDataDriven(controller) != null) {
            getDataDriven(controller).setLoading(true);
        }

        final Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // Couldn't connect to server (could be timeout, SOP violation, etc.)
                handleError(url, exception);
                controller.handleEvent(LoadingStatusAction.OFF);
            }

            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getText().indexOf("HTTP 401") != -1) // HACK
                    {
                        appContext.getAuthentication().handleSessionTimeout();
                    } else if (200 == response.getStatusCode()) {
                        handleSuccessfulResponse(controller, object, response);
                    } else {
                        final String msg = response.getText().equals("") ? "Unknown error" : response.getText();
                        handleError(url, new RequestException("HTTP " + response.getStatusCode() + ": " + msg));
                    }
                } finally {
                    //controller.handleEvent( LoadingStatusAction.OFF );
                    if (getDataDriven(controller) != null) {
                        getDataDriven(controller).setLoading(false);
                    }
                }
            }
        });

        // Timer to handle pending request
        Timer t = new Timer() {

            public void run() {
                if (request.isPending()) {
                    request.cancel();
                    handleError(url, new IOException("Request timeout"));
                }

            }
        };
        t.schedule(20000);

    } catch (RequestException e) {
        // Couldn't connect to server
        handleError(url, e);
        //controller.handleEvent( LoadingStatusAction.OFF );

        if (getDataDriven(controller) != null) {
            getDataDriven(controller).setLoading(false);
        }
    }
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getProcessInstancesURL(String processId) {
    String encodedId = URL.encode(processId);
    System.out.println("the decoded Id is: " + processId);
    System.out.println("the encoded Id is: " + encodedId);
    return config.getConsoleServerUrl() + "/rs/process/definition/" + encodedId + "/instances";
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getUserInRoleURL(String[] possibleRoles) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < possibleRoles.length; i++) {
        sb.append(URL.encode(possibleRoles[i]));
        if (i < possibleRoles.length - 1)
            sb.append(",");
    }//from  www  .ja v  a 2s.co m
    return config.getConsoleServerUrl() + "/rs/identity/user/roles?roleCheck=" + sb.toString();
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

@Deprecated
public String getRemoveDefinitionURL(String processId) {
    String encodedId = URL.encode(processId);
    return config.getConsoleServerUrl() + "/rs/process/definition/" + encodedId + "/remove";
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getProcessImageURL(String processId) {
    String encodedId = URL.encode(processId);
    return config.getConsoleServerUrl() + "/rs/process/definition/" + encodedId + "/image";
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getActivityImage(String processId, String instanceId) {
    String encodedId = URL.encode(processId);
    //This version number is just for forcing the browser to load the image every time, is not used by server-side.
    String versionNo = String.valueOf(new Date().getTime());
    return config.getConsoleServerUrl() + "/rs/process/definition/" + encodedId + "/image/" + instanceId + "?v="
            + versionNo;//from   ww  w  . j ava  2  s . co m
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getStartNewInstanceURL(String processId) {
    String encodedID = URL.encode(processId);
    return config.getConsoleServerUrl() + "/rs/process/definition/" + encodedID + "/new_instance";
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getTaskListURL(String idRef) {
    return config.getConsoleServerUrl() + "/rs/tasks/" + URL.encode(idRef);
}

From source file:org.jboss.bpm.console.client.URLBuilder.java

License:Open Source License

public String getParticipationTaskListURL(String idRef) {
    return config.getConsoleServerUrl() + "/rs/tasks/" + URL.encode(idRef) + "/participation";
}