List of usage examples for com.google.gwt.http.client URL encodePathSegment
public static String encodePathSegment(String decodedURLComponent)
From source file:com.risevision.viewer.client.cache.RiseCacheController.java
License:Open Source License
public static String getCacheVideoUrl(String url, String extension) { if (!isActive) { return url; }// w w w. j a v a2 s . co m if (url.toLowerCase().contains("youtube.com")) { return url; } if (RiseUtils.strIsNullOrEmpty(extension) && url.lastIndexOf(".") != -1) { extension = url.substring(url.lastIndexOf(".") + 1); if (extension.indexOf('?') != -1) { extension = extension.substring(0, extension.indexOf("?")); } } String response = "http://localhost:9494/video" + (RiseUtils.strIsNullOrEmpty(extension) ? "" : "." + extension); response += "?url=" + URL.encodePathSegment(url); return response; }
From source file:com.sciencegadgets.client.URLParameters.java
License:Open Source License
/** * Creates url tolken, compressing when necessary *//*from www . j ava 2 s. c o m*/ public static String makeTolken(HashMap<Parameter, String> parameterMap, boolean encode) { String historyToken = ""; for (Entry<Parameter, String> entry : parameterMap.entrySet()) { Parameter param = entry.getKey(); String value = entry.getValue(); String paramStr = param + ""; if (value == null || "".equals(value)) { continue; } // compress equations switch (param) { case equation: case goal: case system: value = compressEquationXML(value); break; default: } // concat tolken if (encode) { paramStr = URL.encodePathSegment(paramStr); value = URL.encodePathSegment(value); } historyToken = historyToken + PARAMETER_DELIMETER + param + PARAMETER_VALUE_DELIMETER + value; } // The first parameter delimeter is not important historyToken = historyToken.substring(PARAMETER_DELIMETER.length()); return historyToken; }
From source file:edu.caltech.ipac.firefly.core.Application.java
private void initAndShow() { // initialize JossoUtil... supply context information JossoUtil.init(Application.getInstance().getProperties().getProperty("sso.server.url"), GWT.getModuleBaseURL(),/*w ww .ja va2 s. c o m*/ Application.getInstance().getProperties().getProperty("sso.user.profile.url")); commandTable = creator.makeCommandTable(); toolBar = creator.getToolBar(); layoutManager = creator.makeLayoutManager(); if (creator.isApplication()) { requestHandler = getRequestHandler(); History.addValueChangeHandler(requestHandler); } nullFrame = new Frame(); nullFrame.setSize("0px", "0px"); nullFrame.setVisible(false); RootPanel root = RootPanel.get(); root.clear(); root.add(nullFrame); if (BrowserUtil.isTouchInput()) root.addStyleName("disable-select"); if (getLayoutManager() != null) getLayoutManager().layout(creator.getLoadingDiv()); checkMobilAppInstall(); if (SupportedBrowsers.isSupported()) { if (appReady != null) { appReady.ready(); } if (creator.isApplication()) { // save the current state when you leave. DeferredCommand.addCommand(new Command() { public void execute() { Window.addCloseHandler(new CloseHandler<Window>() { public void onClose(CloseEvent<Window> windowCloseEvent) { gotoUrl(null, false); } }); } }); // coming back from prior session String ssoBackTo = Cookies.getCookie(PRIOR_STATE); final Request prevState = Request.parse(ssoBackTo); if (prevState != null && prevState.isSearchResult()) { Cookies.removeCookie(PRIOR_STATE); History.newItem(ssoBackTo, true); } else { // url contains request params String qs = Window.Location.getQueryString().replace("?", ""); if (!StringUtils.isEmpty(qs) && !qs.contains(IGNORE_QUERY_STR)) { String qsDecoded = URL.decodeQueryString(qs); String base = Window.Location.getHref(); base = base.substring(0, base.indexOf("?")); String newUrl = base + "#" + URL.encodePathSegment(qsDecoded); Window.Location.replace(newUrl); } else { String startToken = History.getToken(); if (StringUtils.isEmpty(startToken)) { goHome(); } else { requestHandler.processToken(startToken); } } } if (backgroundMonitor != null) backgroundMonitor.syncWithCache(null); } } else { hideDefaultLoadingDiv(); SupportedBrowsers.showUnsupportedMessage(); } }
From source file:edu.caltech.ipac.firefly.util.WebUtil.java
/** * Returns a string where all characters that are not valid for a complete URL have been escaped. * Also, it will do URL rewriting for session tracking if necessary. * Fires SESSION_MISMATCH if the session ID on the client is different from the one on the server. * * @param url this could be a full or partial url. Delimiter characters will be preserved. * @param paramType if the the parameters are for the server use QUESTION_MARK if the client use POUND * @param params parameters to be appended to the url. These parameters may contain * delimiter characters. Unlike url, delimiter characters will be encoded as well. * @return encoded url//from w w w . j a v a 2s . c o m */ public static String encodeUrl(String url, ParamType paramType, Param... params) { String paramChar = paramType == ParamType.QUESTION_MARK ? "?" : "#"; String[] parts = url.split("\\" + paramChar, 2); String baseUrl = parts[0]; String queryStr = URL.encode(parts.length == 2 ? parts[1] : ""); if (params != null && params.length > 0) { for (int i = 0; i < params.length; i++) { Param param = params[i]; if (param != null && !StringUtils.isEmpty(param.getName())) { String key = URL.encodePathSegment(param.getName().trim()); String val = param.getValue() == null ? "" : URL.encodePathSegment(param.getValue().trim()); queryStr += val.length() == 0 ? key : key + ServerRequest.KW_VAL_SEP + val + (i < params.length ? "&" : ""); } } } return URL.encode(baseUrl) + (queryStr.length() == 0 ? "" : paramChar + queryStr); }
From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.view.search.SearchView.java
License:Open Source License
/** * Constructs a url for searching tweets * * the url has the form:// ww w . ja v a2 s. c o m * * HOST_URL/search/:text/:screenName/:collection/:fromYear/:fromMonth/:fromDay/:toYear/:toMonth/:toDay/:page * * @param e * @return */ private static String getUrl(SearchEvent e) { searchText = e.getSearchText(); searchText = URL.encodePathSegment(searchText); url = Consts.HOST_URL + "/search/" + searchText + "/"; url = url + e.getAccount() + "/" + ((e.getSearchType() == 2) ? "mentions" : "statuses"); url = url + "/" + e.getMediaOnly(); if (e.getStartDate() != null && e.getEndDate() != null) { url = url + e.getStartDate() + e.getEndDate() + "/"; } else if (e.getEndDate() != null) { url = url + "/0/0/0" + e.getEndDate() + "/"; } else if (e.getStartDate() != null) { url = url + e.getStartDate() + "/0/0/0/"; } else { url = url + "/0/0/0/0/0/0/"; } return url; }
From source file:grails.plugin.console.charts.client.application.AbstractApplicationPresenter.java
License:Apache License
@Override public void onViewChanged(String view) { PlaceRequest request = new PlaceRequest.Builder().nameToken(NameTokens.HOME) .with(ParameterTokens.QUERY, AppUtils.encodeBase64(URL.encodePathSegment(AppUtils.QUERY))) .with(ParameterTokens.CONNECTION_STRING, URL.encodePathSegment(AppUtils.CONNECTION_STRING)) .with(ParameterTokens.VIEW, view).build(); placeManager.revealPlace(request);/*from w w w .ja va 2 s.co m*/ }
From source file:grails.plugin.console.charts.client.application.AbstractApplicationPresenter.java
License:Apache License
@Override protected void onReset() { if (result == null) { if (AppUtils.QUERY != null) { if (AppUtils.CONNECTION_STRING == null) { getView().error("Not connected to server"); return; }//from w w w .ja v a2 s .co m if (AppUtils.CONNECT_STATUS == null) { try { String url = AppUtils.getConnectPath() + "?data=" + URL.encodePathSegment(AppUtils.CONNECTION_STRING); RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); rb.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { ConnectStatus status = AutoBeanCodex .decode(AppUtils.BEAN_FACTORY, ConnectStatus.class, response.getText()) .as(); if (status.isConnected()) { AppUtils.CONNECT_STATUS = status; ConnectedEvent.fire(AbstractApplicationPresenter.this, status.getConnectionString(), status.getStatus()); loadData(); } else { String error = (status.getException() != null ? " (" + status.getException() + ") " : "") + status.getError(); Window.alert("Error occurred: " + error); } } @Override public void onError(Request request, Throwable exception) { Window.alert("Error occurred: " + exception.getMessage()); } }); rb.send(); } catch (RequestException e) { Window.alert("Error occurred: " + e.getMessage()); } } else { loadData(); } } } else { getView().view(AppUtils.VIEW, result); } }
From source file:grails.plugin.console.charts.client.application.AbstractApplicationPresenter.java
License:Apache License
private void loadData() { getView().loading();// w w w. j a v a 2s .co m try { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, AppUtils.getDataPath() + "?query=" + URL.encodeQueryString(AppUtils.encodeBase64(AppUtils.QUERY)) + "&appearance=" + URL.encodePathSegment(AppUtils.encodeBase64(AppUtils.APPEARANCE)) + "&connectionString=" + URL.encodePathSegment(AppUtils.CONNECTION_STRING)); rb.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { try { JSONValue value = JSONParser.parseStrict(response.getText()); result = value.isObject(); if (result.get("error") != null) { getView().error(result); return; } getView().view(AppUtils.VIEW, result); } catch (Exception exception) { getView().error("Can't parse data JSON: " + exception.getMessage()); } finally { result = null; } } @Override public void onError(Request request, Throwable exception) { getView().error("Error occurred: " + exception.getMessage()); } }); rb.send(); } catch (RequestException e) { getView().error("Error occurred: " + e.getMessage()); } }
From source file:grails.plugin.console.charts.client.application.editor.AbstractEditorPresenter.java
License:Apache License
@Override public void run() { if (AppUtils.CONNECT_STATUS == null) { Window.alert("You are not connected to the server"); return;/* w w w. j ava2s . c om*/ } String query = getView().getQueryEditor().getValue(); if (query != null && !query.equals("")) { PlaceRequest request = new PlaceRequest.Builder().nameToken(NameTokens.HOME) .with(ParameterTokens.CONNECTION_STRING, URL.encodePathSegment(AppUtils.CONNECTION_STRING)) .with(ParameterTokens.APPEARANCE, URL.encodePathSegment( AppUtils.encodeBase64(getView().getAppearanceEditor().getValue()))) .with(ParameterTokens.QUERY, URL.encodePathSegment(AppUtils.encodeBase64(query))).build(); placeManager.revealPlace(request); } }
From source file:io.reinert.requestor.uri.Uri.java
License:Apache License
private void buildPath() { StringBuilder pathBuilder = new StringBuilder("/"); if (pathSegments != null && pathSegments.length > 0) { for (final String segment : pathSegments) { pathBuilder.append(URL.encodePathSegment(segment)); // Check if there are matrix params for this segment if (matrixParams != null) { Buckets segmentParams = matrixParams.get(segment); if (segmentParams != null) { String[] params = segmentParams.getKeys(); for (String param : params) { String[] values = segmentParams.get(param); // Check if the param has values if (values.length == 0) { // Append only the param name without any value pathBuilder.append(';').append(URL.encodePathSegment(param)); } else { // Append the param and its values for (String value : values) { pathBuilder.append(';').append(URL.encodePathSegment(param)); if (value != null) { pathBuilder.append('=').append(URL.encodePathSegment(value)); }/* w w w . j av a 2s . co m*/ } } } } } pathBuilder.append('/'); } pathBuilder.deleteCharAt(pathBuilder.length() - 1); } path = pathBuilder.toString(); }