/** * Adds GET parameters to a path. * * @param url the existing url path * @param parameters are put into the URL as get parameters. * @return the complete url eg http://localhost/app?step=1 */ public static String getPath(final String url, final Map<String, String> parameters) { return getPath(url, parameters, false); }
/** * {@inheritDoc} */ @Override public String getPostPath() { if (windowId == null) { return backing.getPostPath(); } else { Map<String, String> parameters = new HashMap<>(); parameters.put(WWindow.WWINDOW_REQUEST_PARAM_KEY, windowId); String url = getWServletPath(); return WebUtilities.getPath(url, parameters, true); } }
/** * @return the URL which can be used to target this resource. */ public String getTargetUrl() { UIContext uic = UIContextHolder.getCurrent(); if (uic == null) { return null; } String url = uic.getEnvironment().getWServletPath(); Map<String, String> parameters = new HashMap<>(); String resourceCacheKey = InternalResourceMap.getResourceCacheKey(resourceName); parameters.put(WServlet.STATIC_RESOURCE_PARAM_NAME, resourceName); if (resourceCacheKey != null) { parameters.put("cacheKey", resourceCacheKey); } return WebUtilities.getPath(url, parameters, true); } }
/** * Returns a dynamic URL that this wwindow component can be accessed from. * * @return the URL to access this wwindow component. */ public String getUrl() { Environment env = getEnvironment(); Map<String, String> parameters = env.getHiddenParameters(); parameters.put(WWINDOW_REQUEST_PARAM_KEY, getId()); // Override the step count with WWindow step parameters.put(Environment.STEP_VARIABLE, String.valueOf(getStep())); String url = env.getWServletPath(); return WebUtilities.getPath(url, parameters, true); }
/** * Creates a dynamic URL that the poster can be loaded from. In fact the URL points to the main application servlet, * but includes a non-null for the parameter associated with this WComponent (ie, its label). The handleRequest * method below detects this when the browser requests a file. * * @return the url to load the poster from, or null if there is no poster defined. */ public String getPosterUrl() { Image poster = getComponentModel().poster; if (poster == null) { return null; } // this variable needs to be set in the portlet environment. String url = getEnvironment().getWServletPath(); Map<String, String> parameters = getBaseParameterMap(); parameters.put(POSTER_REQUEST_PARAM_KEY, "x"); return WebUtilities.getPath(url, parameters, true); }
/** * Creates dynamic URLs that the video clips can be loaded from. In fact the URL points to the main application * servlet, but includes a non-null for the parameter associated with this WComponent (ie, its label). The * handleRequest method below detects this when the browser requests a file. * * @return the urls to load the video files from, or null if there are no clips defined. */ public String[] getVideoUrls() { Video[] video = getVideo(); if (video == null || video.length == 0) { return null; } String[] urls = new String[video.length]; // this variable needs to be set in the portlet environment. String url = getEnvironment().getWServletPath(); Map<String, String> parameters = getBaseParameterMap(); for (int i = 0; i < urls.length; i++) { parameters.put(VIDEO_INDEX_REQUEST_PARAM_KEY, String.valueOf(i)); urls[i] = WebUtilities.getPath(url, parameters, true); } return urls; }
/** * Creates dynamic URLs that the video clips can be loaded from. In fact the URL points to the main application * servlet, but includes a non-null for the parameter associated with this WComponent (ie, its label). The * handleRequest method below detects this when the browser requests a file. * * @return the urls to load the video files from, or null if there are no clips defined. */ public String[] getTrackUrls() { Track[] tracks = getTracks(); if (tracks == null || tracks.length == 0) { return null; } String[] urls = new String[tracks.length]; // this variable needs to be set in the portlet environment. String url = getEnvironment().getWServletPath(); Map<String, String> parameters = getBaseParameterMap(); for (int i = 0; i < urls.length; i++) { parameters.put(TRACK_INDEX_REQUEST_PARAM_KEY, String.valueOf(i)); urls[i] = WebUtilities.getPath(url, parameters, true); } return urls; }
@Test public void testGetPath() { // Simple case String url = "/foo"; String expected = "/foo"; Assert.assertEquals("Incorrect path returned for " + url, expected, WebUtilities. getPath(url, null)); // Simple case with one param Map<String, String> params = new HashMap<>(); params.put("a", "b"); url = "/foo"; expected = "/foo?a=b"; Assert.assertEquals("Incorrect path returned for " + url + " with a=b", expected, WebUtilities.getPath(url, params)); // Case with existing params and two in the map params = new HashMap<>(); params.put("c", "d"); params.put("e", "f"); url = "/foo?a=b"; expected = "/foo?a=b&c=d&e=f"; assertURLEquals(expected, WebUtilities.getPath(url, params), "&"); // As a javascript url expected = "/foo?a=b&c=d&e=f"; assertURLEquals(expected, WebUtilities.getPath(url, params, true), "&"); }
urls[i] = WebUtilities.getPath(url, parameters, true);
return WebUtilities.getPath(url, parameters, true);
return WebUtilities.getPath(url, parameters, true);
return WebUtilities.getPath(url, parameters, true);
return WebUtilities.getPath(url, parameters, true);
return WebUtilities.getPath(url, parameters, true);