return relativePathPrefixToWicketHandler;
}
boolean portletRequest = RequestContext.get().isPortletRequest();
PrependingStringBuffer prepender = new PrependingStringBuffer();
// For AJAX requests, we need to make the URLs relative to the
// original page.
if (!portletRequest && isAjax())
{
for (int i = 0; i < getRequestParameters().getUrlDepth(); i++)
{
prepender.prepend("../");
}
return relativePathPrefixToWicketHandler = prepender.toString();
}
String relativeUrl = getPath();
/*
* We might be serving an error page.
*
* In this case, the request will appear to be for something like "/ErrorPage", whereas the
* URL in the user's browser will actually be something like
* "/foo/page/where/the/error/actually/happened".
*
* We need to generate links and resource URLs relative to the URL in the browser window,
* not the internal request for the error page.
*
* This original URL is available from request attributes, so we look in there and use that
* for the relative path if it's available.
*/
HttpServletRequest httpRequest = getHttpServletRequest();
// This is in the Servlet 2.3 spec giving us the URI of the resource
// that caused the error. Unfortunately, this includes the context path.
String errorUrl = (String)httpRequest.getAttribute("javax.servlet.error.request_uri");
// This gives us a context-relative path for RequestDispatcher.forward
// stuff, with a leading slash.
String forwardUrl = (String)httpRequest.getAttribute("javax.servlet.forward.servlet_path");
if (forwardUrl != null && forwardUrl.length() > 0)
{
// If this is an error page, this will be /mount or /?wicket:foo
relativeUrl = forwardUrl.substring(1);
}
else if (errorUrl != null)
{
// Strip off context path from front of URI.
errorUrl = errorUrl.substring(httpRequest.getContextPath().length());
String servletPath = httpRequest.getServletPath();
if (!errorUrl.startsWith(servletPath))
{
prepender.prepend(servletPath.substring(1) + "/");
}
for (int i = servletPath.length() + 1; i < errorUrl.length(); i++)
{
if (errorUrl.charAt(i) == '?')
{
break;
}
if (errorUrl.charAt(i) == '/')
{
prepender.prepend("../");
}
}
return relativePathPrefixToWicketHandler = prepender.toString();
}
else if (wicketRedirectUrl != null)
{
relativeUrl = wicketRedirectUrl;
}
int lastPathPos = -1;
if (depthRelativeToWicketHandler == -1)
{
int depth = 0;
int ajaxUrlDepth = isAjax() ? getRequestParameters().getUrlDepth() : -1;
for (int i = 0; i < relativeUrl.length(); i++)
{
if (relativeUrl.charAt(i) == '?')
{
break;
}
if (relativeUrl.charAt(i) == '/')
{
depth++;
lastPathPos = i;
if (depth == ajaxUrlDepth)
{
return relativeUrl.substring(0, lastPathPos + 1);
}
}
}
depthRelativeToWicketHandler = depth;
}
if (portletRequest)
{
prepender.prepend("/");
prepender.prepend(getHttpServletRequest().getServletPath());
prepender.prepend(getHttpServletRequest().getContextPath());
}
else
{
for (int i = 0; i < depthRelativeToWicketHandler; i++)
{
prepender.prepend("../");
}
}
return relativePathPrefixToWicketHandler = prepender.toString();
}