List of usage examples for org.apache.wicket.protocol.http RequestUtils toAbsolutePath
public static String toAbsolutePath(final String requestPath, String relativePagePath)
From source file:at.molindo.wicketutils.utils.WicketUtils.java
License:Apache License
/** * replacement for {@link RequestUtils}.toAbsolutePath(String) * // w ww .j av a2s .c o m * Calculates absolute path to url relative to another absolute url. * * @param relativePagePath * path, relative to requestPath * @return absolute path for given url */ public final static String toAbsolutePath(final String relativePagePath) { return RequestUtils.toAbsolutePath(getHttpServletRequest().getRequestURL().toString(), relativePagePath); }
From source file:com.aipo.mobycket.wicket.protocol.http.WebApplication.java
License:Apache License
@Override protected WebResponse newWebResponse(HttpServletResponse servletResponse) { return new WebResponse(servletResponse) { @Override/*from w ww.j a v a 2 s . com*/ public void sendRedirect(String url) throws IOException { if (url.startsWith("http")) { getHttpServletResponse().sendRedirect(url); return; } HttpServletRequest httpServletRequest = ((WebRequest) RequestCycle.get().getRequest()) .getHttpServletRequest(); String reqUrl = httpServletRequest.getRequestURI(); String absUrl = RequestUtils.toAbsolutePath(reqUrl, url); getHttpServletResponse().sendRedirect(getRequestBaseUrl() + absUrl); } }; }
From source file:com.pushinginertia.wicket.core.util.ComponentUtils.java
License:Open Source License
/** * Constructs the full URL to redirect to for a given target page and its parameters, with the option to override * the host name.// w w w.j a v a2s . com * @param component component the call is being made from (used to obtain the container request) * @param hostName host name to use in the constructed URL * @param targetPage target page * @param pageParameters parameters for the target page (may be null) * @return full URL * @see org.apache.wicket.request.UrlRenderer#renderFullUrl(org.apache.wicket.request.Url) */ public static String constructRedirectUrl(final Component component, final String hostName, final Class<? extends Page> targetPage, final PageParameters pageParameters) { ValidateAs.notNull(component, "component"); ValidateAs.notNull(targetPage, "targetPage"); final HttpServletRequest req = (HttpServletRequest) component.getRequest().getContainerRequest(); final String relativePath = component.urlFor(targetPage, pageParameters).toString(); final String requestURI = req.getRequestURI(); String absolutePath; try { absolutePath = RequestUtils.toAbsolutePath(requestURI, relativePath); } catch (final StringIndexOutOfBoundsException e) { // sometimes the wicket method throws an exception when the input is something like: // requestPath="/404", relativePagePath="../../../page-name" // strip all leading occurrences of "../" from the relativePath final StringBuilder sb = new StringBuilder(relativePath); while (sb.indexOf("../") == 0) { sb.delete(0, 3); } absolutePath = sb.toString(); } catch (final RuntimeException e) { // this call can throw StringIndexOutOfBoundsException: String index out of range: -1 // it seems to be a wicket bug but I need to log the input to figure out how to reproduce it LOG.error("Error constructing absolute path for inputs requestPath=[" + requestURI + "], relativePagePath=[" + relativePath + "]", e); throw e; } return constructUrl(component, hostName, absolutePath); }
From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java
License:Open Source License
@Override protected WebResponse newWebResponse(HttpServletResponse servletResponse) { // over ride this so that redirects are not relative but absolute // Websphere doesn't work correctly with relative urls. return (getRequestCycleSettings().getBufferResponse() ? new BufferedWebResponse(servletResponse) { private String reqUrl = null; @Override// w ww. j a v a 2s.co m public CharSequence encodeURL(CharSequence url) { if (reqUrl == null) reqUrl = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest().getRequestURI(); return super.encodeURL(url); } @Override protected void sendRedirect(String url) throws IOException { if (reqUrl != null && url.indexOf("://") == -1) //$NON-NLS-1$ { String absUrl = RequestUtils.toAbsolutePath(reqUrl, url); getHttpServletResponse().sendRedirect(absUrl); } else { super.sendRedirect(url); } } } : new WebResponse(servletResponse) { @Override protected void sendRedirect(String url) throws IOException { String reqUrl = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest() .getRequestURI(); String absUrl = RequestUtils.toAbsolutePath(reqUrl, url); getHttpServletResponse().sendRedirect(absUrl); } }); }
From source file:com.userweave.components.MailMessageProviderImpl.java
License:Open Source License
private final static String toAbsolutePath(final String relativePagePath) { HttpServletRequest req = (HttpServletRequest) (RequestCycle.get().getRequest()).getContainerRequest(); return RequestUtils.toAbsolutePath(req.getRequestURL().toString(), relativePagePath); }
From source file:de.alpharogroup.wicket.base.util.WicketComponentExtensions.java
License:Apache License
/** * Helper method for the migration from wicket-version 1.5.x to 6.x. * * @param relativePagePath//from w ww . ja va2s . c o m * the relative page path * @return the string */ public static String toAbsolutePath(final String relativePagePath) { final HttpServletRequest req = (HttpServletRequest) ((WebRequest) RequestCycle.get().getRequest()) .getContainerRequest(); return RequestUtils.toAbsolutePath(req.getRequestURL().toString(), relativePagePath); }
From source file:de.elatexam.editor.preview.PreviewComplexLink.java
License:Open Source License
/** * Create return link to this very page instance. Clear TaskModelViewDelegate on return. * * @return/* w ww. j av a 2s . c o m*/ */ private String getReturnLink() { String rel = (String) urlFor(new RenderPageRequestHandler(new PageProvider(getPage())) { @Override public void respond(IRequestCycle requestCycle) { // remove preview task TaskModelViewDelegate.removeSession(Session.get().getId()); super.respond(requestCycle); } }); final HttpServletRequest req = ((ServletWebRequest) getRequest()).getContainerRequest(); return RequestUtils.toAbsolutePath(req.getRequestURL().toString(), rel); }
From source file:fiftyfive.wicket.shiro.markup.LogoutLink.java
License:Apache License
/** * If a destination page was specified in the constructor, determine the absolute URI for * that page and add it to this link as the {@code "to"} parameter. This instructs the * {@link LogoutPage} to redirect to that URI upon logout. *//* ww w. ja v a 2 s . co m*/ @Override protected void onInitialize() { super.onInitialize(); Class<? extends Page> dest = this.destinationPage; if (dest != null) { getPageParameters().set("to", RequestUtils.toAbsolutePath(getRequest().getClientUrl().toString(), urlFor(dest, this.destinationParams).toString())); } }
From source file:guru.mmp.application.web.template.components.BackendMainNavigation.java
License:Apache License
private void renderNavigationGroup(String requestURI, NavigationGroup navigationGroup, int depth, StringBuilder buffer) {/*from ww w.ja v a 2 s.c om*/ if (depth == 0) { buffer.append("<ul class=\"sidebar-menu\">"); } else { buffer.append("<ul class=\"treeview-menu\">"); } List<NavigationItem> navigationItems = navigationGroup.getItems(); // Determine the selected navigation item for the current page in this navigation group NavigationItem selectedNavigationItemForCurrentPage = null; for (NavigationItem navigationItem : navigationItems) { if (navigationItem.isPageInNavigationHierarchy(getPage())) { selectedNavigationItemForCurrentPage = navigationItem; break; } } // Draw each of the navigation items for (NavigationItem navigationItem : navigationItems) { // If the navigation item is a navigation group if (navigationItem instanceof NavigationGroup) { NavigationGroup subNavigationGroup = (NavigationGroup) navigationItem; if (navigationItem == selectedNavigationItemForCurrentPage) { buffer.append("<li class=\"treeview active\">"); } else { buffer.append("<li class=\"treeview\">"); } buffer.append("<a href=\"#\">"); if (subNavigationGroup.getIconClass() != null) { buffer.append("<i class=\"").append(subNavigationGroup.getIconClass()).append("\"></i>"); } buffer.append("<span>").append(subNavigationGroup.getName()).append("</span>"); buffer.append("<span class=\"pull-right-container\">"); buffer.append("<i class=\"fa fa-angle-left pull-right\"></i></span></a>"); renderNavigationGroup(requestURI, subNavigationGroup, depth + 1, buffer); buffer.append("</li>"); } // If the navigation item is a navigation link else if (navigationItem instanceof NavigationLink) { NavigationLink navigationLink = (NavigationLink) navigationItem; String url = urlFor(navigationLink.getPageClass(), navigationLink.getPageParameters()).toString(); if (navigationItem == selectedNavigationItemForCurrentPage) { buffer.append("<li class=\"active\">"); } else { buffer.append("<li>"); } buffer.append("<a href=\""); if (url.startsWith("/")) { buffer.append(url).append("\">"); } else { buffer.append(RequestUtils.toAbsolutePath(requestURI, url)).append("\">"); } if (navigationItem.getIconClass() != null) { buffer.append("<i class=\"").append(navigationItem.getIconClass()).append("\"></i>"); } buffer.append("<span>").append(navigationItem.getName()).append("</span></a></li>"); } } if (depth != 0) { buffer.append("</ul>"); } }
From source file:jp.xet.uncommons.wicket.utils.WicketUtil.java
License:Apache License
/** * URL?URL???/* ww w . j av a 2 s . com*/ * * @param url URL * @return URL * @throws IllegalStateException ??? {@link RequestCycle} ????????? * @since 1.0 */ public static String toAbsoluteUrl(String url) { Url parsed = Url.parse(url); if (parsed.isAbsolute()) { return url; } HttpServletRequest req = getHttpServletRequest(); if (req == null) { throw new IllegalStateException(); } return RequestUtils.toAbsolutePath(req.getRequestURL().toString(), url); }