Example usage for com.google.gwt.http.client UrlBuilder setPath

List of usage examples for com.google.gwt.http.client UrlBuilder setPath

Introduction

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

Prototype

public UrlBuilder setPath(String path) 

Source Link

Document

Set the path portion of the location (ex.

Usage

From source file:ch.unifr.pai.twice.multipointer.client.ExtendedWebsocketControl.java

License:Apache License

@Override
public void start() {
    if (!isInIFrame()) {
        initializeCursorList();//from w  ww  . j ava2 s  .  c om
        if (r != null)
            r.removeHandler();
        r = Window.addResizeHandler(this);
        UrlBuilder b = Window.Location.createUrlBuilder();
        b.setProtocol("ws");
        b.setPath("mouseControlXBrowser");
        b.setHash(null);
        String p = Window.Location.getPort();
        Integer port;
        try {
            port = p != null ? Integer.parseInt(p) : 8080;
        } catch (NumberFormatException e) {
            port = 8080;
        }
        b.setPort(port + 1);
        for (String param : Window.Location.getParameterMap().keySet()) {
            b.removeParameter(param);
        }
        websocket = createWebsocket(this, b.buildString());
        if (websocket != null)
            createOnBeforeUnloadHandler(websocket);
    }
}

From source file:com.google.gerrit.client.Gerrit.java

License:Apache License

public static String selfRedirect(String suffix) {
    // Clean up the path. Users seem to like putting extra slashes into the URL
    // which can break redirections by misinterpreting at either client or server.
    String path = Location.getPath();
    if (path == null || path.isEmpty()) {
        path = "/";
    } else {//from ww  w . j av  a  2  s . c  o m
        while (path.startsWith("//")) {
            path = path.substring(1);
        }
        while (path.endsWith("//")) {
            path = path.substring(0, path.length() - 1);
        }
        if (!path.endsWith("/")) {
            path = path + "/";
        }
    }

    if (suffix != null) {
        while (suffix.startsWith("/")) {
            suffix = suffix.substring(1);
        }
        path += suffix;
    }

    UrlBuilder builder = new UrlBuilder();
    builder.setProtocol(Location.getProtocol());
    builder.setHost(Location.getHost());
    String port = Location.getPort();
    if (port != null && !port.isEmpty()) {
        builder.setPort(Integer.parseInt(port));
    }
    builder.setPath(path);
    return builder.buildString();
}

From source file:com.google.livingstories.client.util.UriParser.java

License:Apache License

public static UrlBuilder parse(String url) {
    UrlBuilder urlBuilder = new UrlBuilder();

    // This utility only needs to support http urls.
    urlBuilder.setProtocol("http");
    urlBuilder.setHost(matchHost(url));//  w ww .  ja v  a  2 s. co  m
    urlBuilder.setPath(matchPath(url));

    String queryString = matchQuery(url);
    if (!queryString.isEmpty()) {
        for (String params : queryString.split("&")) {
            // Doesn't work for urls with multiple values on the same key.
            // But we don't currently need that.
            String[] pair = params.split("=");
            urlBuilder.setParameter(pair[0], pair.length > 1 ? pair[1] : "");
        }
    }

    return urlBuilder;
}

From source file:com.tasktop.c2c.server.common.profile.web.client.place.AbstractPlace.java

License:Open Source License

public String getHref() {

    if (!GWT.isClient()) {
        // For tests
        return "http://localhost/#" + getHistoryToken();
    }// w  w w  .ja  va2 s.  c om
    UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
    urlBuilder.setPath(Path.getBasePath());
    return urlBuilder.setHash(getHistoryToken()).buildString();
}

From source file:eu.riscoss.client.riskanalysis.RiskAnalysisModule.java

License:Apache License

protected void runAnalysis() {

    String pagename = Window.Location.getPath().substring(0, Window.Location.getPath().lastIndexOf("/"));

    pagename += "/report.jsp";

    UrlBuilder ub = Window.Location.createUrlBuilder();

    ub.setPath(pagename);
    ub.setParameter("target", entityLabel.getText());
    ub.setParameter("rc", rcLabel.getText());
    Window.Location.replace(ub.buildString());
}

From source file:nl.sense_os.commonsense.login.client.login.LoginActivity.java

License:Open Source License

private void goToMainPage() {

    UrlBuilder builder = new UrlBuilder();
    builder.setProtocol(Location.getProtocol());
    builder.setHost(Location.getHost());
    String path = Location.getPath().contains("login.html")
            ? Location.getPath().replace("login.html", "index.html")
            : Location.getPath() + "index.html";
    builder.setPath(path);
    for (Entry<String, List<String>> entry : Location.getParameterMap().entrySet()) {
        if ("session_id".equals(entry.getKey())) {
            // do not copy the session id parameter
        } else {//from w w w .jav  a2s  . co m
            builder.setParameter(entry.getKey(), entry.getValue().toArray(new String[0]));
        }
    }
    Location.replace(builder.buildString().replace("127.0.0.1%3A", "127.0.0.1:"));
}

From source file:nl.sense_os.commonsense.login.client.LoginEntryPoint.java

License:Open Source License

/**
 * Redirects the user to the main page//from   w  w  w .  jav a2  s  . c om
 */
public static void goToMainPage() {
    UrlBuilder builder = new UrlBuilder();
    builder.setProtocol(Location.getProtocol());
    builder.setHost(Location.getHost());
    String path = Location.getPath().contains("login.html")
            ? Location.getPath().replace("login.html", "index.html")
            : Location.getPath() + "index.html";
    builder.setPath(path);
    for (Entry<String, List<String>> entry : Location.getParameterMap().entrySet()) {
        if ("session_id".equals(entry.getKey()) || "error".equals(entry.getKey())) {
            // do not copy the session id parameter
        } else {
            builder.setParameter(entry.getKey(), entry.getValue().toArray(new String[0]));
        }
    }
    String newLocation = builder.buildString();

    // do not mangle the GWT development server parameter
    newLocation = newLocation.replace("127.0.0.1%3A", "127.0.0.1:");

    // relocate
    Location.replace(newLocation);
}

From source file:nl.sense_os.commonsense.login.client.newpassword.NewPasswordActivity.java

License:Open Source License

/**
 * Removes any URL parameters that are not useful anymore after a new password was set.
 *//*from   w w  w  .  j a  v  a2s .c  o  m*/
private static void cleanUrlParameters() {

    // clear any session ID to prevent from bouncing back immediately
    SessionManager.removeSessionId();

    UrlBuilder builder = new UrlBuilder();
    builder.setProtocol(Location.getProtocol());
    builder.setHost(Location.getHost());
    builder.setPath(Location.getPath());
    for (Entry<String, List<String>> entry : Location.getParameterMap().entrySet()) {
        if ("session_id".equals(entry.getKey()) || "error".equals(entry.getKey())
                || "token".equals(entry.getKey())) {
            // do not copy the session id, error, or token parameters
        } else {
            builder.setParameter(entry.getKey(), entry.getValue().toArray(new String[0]));
        }
    }
    String newLocation = builder.buildString();

    // do not mangle the GWT development server parameter
    newLocation = newLocation.replace("127.0.0.1%3A", "127.0.0.1:");

    // relocate
    Location.replace(newLocation);
}

From source file:nl.sense_os.commonsense.main.client.viz.panels.table.SensorDataGrid.java

License:Open Source License

private String createUrl(List<ExtSensor> sensors, long startTime, long endTime) {

    int id = sensors.get(0).getId();

    final UrlBuilder urlBuilder = new UrlBuilder().setProtocol(CommonSenseClient.Urls.PROTOCOL)
            .setHost(CommonSenseClient.Urls.HOST);
    urlBuilder.setPath(Urls.PATH_SENSORS + "/" + id + "/data.json");

    final int alias = sensors.get(0).getAlias();
    if (alias != -1) {
        urlBuilder.setParameter("alias", "" + alias);
    }/*from  w  ww . ja v  a2s  . c o  m*/

    urlBuilder.setParameter("start_date", NumberFormat.getFormat("#.000").format(startTime / 1000d));
    if (endTime != -1) {
        urlBuilder.setParameter("end_date", NumberFormat.getFormat("#.000").format(endTime / 1000d));
    }

    // urlBuilder.setParameter("total", "1");

    return urlBuilder.buildString();
}

From source file:org.broadleafcommerce.openadmin.client.BLCMain.java

License:Apache License

public static String buildStoreFrontBaseUrl(String path) {
    String prefix = storeFrontWebAppPrefix;
    if (prefix.startsWith("/")) {
        UrlBuilder urlBuilder = new UrlBuilder();
        urlBuilder.setHost(com.google.gwt.user.client.Window.Location.getHost());
        String port = com.google.gwt.user.client.Window.Location.getPort();
        if (port != null && port.length() > 0) {
            urlBuilder.setPort(Integer.valueOf(port));
        }/*from   ww w .j  a  va 2s  .  co m*/
        urlBuilder.setProtocol(com.google.gwt.user.client.Window.Location.getProtocol());
        urlBuilder.setPath(prefix + (path == null ? "" : path));

        return urlBuilder.buildString();
    }

    return prefix + (path == null ? "" : path);
}