List of usage examples for com.google.gwt.http.client UrlBuilder setHost
public UrlBuilder setHost(String host)
From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java
License:Apache License
public static UrlBuilder getBaseUrlBuilder() { UrlBuilder builder = new UrlBuilder(); builder.setProtocol(Window.Location.getProtocol()); builder.setHost(Window.Location.getHostName()); String port = Window.Location.getPort(); if (port != null && port.length() > 0) { builder.setPort(Integer.parseInt(port)); }//from w ww. ja v a 2 s .co m return builder; }
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 {/*www. java 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)); urlBuilder.setPath(matchPath(url));/*w ww .j av a2 s . com*/ 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: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);//from w w w . j a v a 2 s .c o m for (Entry<String, List<String>> entry : Location.getParameterMap().entrySet()) { if ("session_id".equals(entry.getKey())) { // do not copy the session id parameter } else { 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/*w ww .j a v a2 s. c o m*/ */ 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. */// w w w.j av a 2s.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: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)); }// w ww . j a v a2 s .c o 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); }
From source file:org.eurekastreams.web.client.ui.pages.master.ConnectEntryPoint.java
License:Apache License
/** * Determines the URL to use to launch the main app. *///from w ww . j a v a 2 s . co m private void determineLaunchPage() { String param = Window.Location.getParameter("_main"); if (param != null && !param.isEmpty()) { mainAppLaunchUrl = param; } else { String path = Window.Location.getPath(); int index = path.lastIndexOf('/'); if (index >= 0 && path.length() > index + 1) { UrlBuilder builder = new UrlBuilder(); builder.setProtocol(Window.Location.getProtocol()); builder.setHost(Window.Location.getHost()); try { builder.setPort(Integer.parseInt(Window.Location.getPort())); } catch (Exception ex) { int makeCheckstyleShutUp = 1; } builder.setPath(path.substring(0, index)); mainAppLaunchUrl = builder.buildString(); } } }
From source file:org.pentaho.mantle.client.ui.tabs.MantleTab.java
License:Open Source License
public void createDeepLink() { if (getContent() instanceof IFrameTabPanel) { PromptDialogBox dialogBox = new PromptDialogBox(Messages.getString("deepLink"), //$NON-NLS-1$ Messages.getString("ok"), Messages.getString("cancel"), false, //$NON-NLS-1$ //$NON-NLS-2$ true);//from www . ja v a 2 s .c o m String startup = ((IFrameTabPanel) getContent()).getUrl(); if (!StringUtils.isEmpty(((IFrameTabPanel) getContent()).getDeepLinkUrl())) { startup = ((IFrameTabPanel) getContent()).getDeepLinkUrl(); } UrlBuilder builder = new UrlBuilder(); builder.setProtocol(Window.Location.getProtocol()); builder.setHost(Window.Location.getHostName()); try { builder.setPort(Integer.parseInt(Window.Location.getPort())); } catch (NumberFormatException e) { builder.setPort(UrlBuilder.PORT_UNSPECIFIED); } builder.setPath(Window.Location.getPath()); //UrlBuilder will encode spaces as '+' which is a valid special character so we replace all spaces with '%20' builder.setParameter("name", getLabelText().replaceAll("\\s", "%20")); //the startup string is already encoded with ':' being replaced with '\t' and then encoded again... builder.setParameter("startup-url", startup); final TextArea urlbox = new TextArea(); //encode any space characters urlbox.setText(builder.buildString()); urlbox.setReadOnly(true); urlbox.setVisibleLines(3); dialogBox.setContent(urlbox); urlbox.setHeight("80px"); urlbox.setWidth("600px"); urlbox.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { urlbox.selectAll(); } }); dialogBox.center(); urlbox.selectAll(); } }
From source file:org.sigmah.client.util.ClientUtils.java
License:Open Source License
/** * Returns the current application URL (with current optional parameters) with the given additional parameter * {@code paramName}./*from www. j a v a 2 s.c om*/ * * @param withParameters * {@code true} to retrieve existing current URL parameters, {@code false} to forget them. * @param paramName * The parameter name. * @param paramValues * The parameter value(s). * @return the current application URL (with current optional parameters) with the given additional parameter * {@code paramName}. */ public static String getApplicationUrl(boolean withParameters, String paramName, String... paramValues) { final UrlBuilder urlBuilder = new UrlBuilder(); urlBuilder.setProtocol(Location.getProtocol()); urlBuilder.setHost(Location.getHost()); final Integer port = asInt(Location.getPort()); if (port != null) { urlBuilder.setPort(port); } urlBuilder.setPath(Location.getPath()); if (Location.getParameterMap() != null) { // "?gwt.codesvr=127.0.0.1:9997" for example. for (final Entry<String, List<String>> param : Location.getParameterMap().entrySet()) { if ("gwt.codesvr".equalsIgnoreCase(param.getKey()) && isNotEmpty(param.getValue())) { // Hosted mode parameter exception. urlBuilder.setParameter(param.getKey(), param.getValue().get(0)); } else if (withParameters) { final String[] values = param.getValue() != null ? param.getValue().toArray(new String[param.getValue().size()]) : null; urlBuilder.setParameter(param.getKey(), values); } } } if (isNotBlank(paramName) && paramValues != null) { urlBuilder.setParameter(paramName, paramValues); } return urlBuilder.buildString(); }