final IRequestTarget requestTarget)
{
// First check to see whether the target is mounted
CharSequence url = pathForTarget(requestTarget);
RequestContext requestContext = RequestContext.get();
boolean portletRequest = requestContext.isPortletRequest();
boolean sharedResourceURL = false;
if (url != null && !portletRequest)
{
// Do nothing - we've found the URL and it's mounted.
}
else if (requestTarget instanceof IBookmarkablePageRequestTarget)
{
url = requestContext.encodeRenderURL(url == null ? encode(requestCycle,
(IBookmarkablePageRequestTarget)requestTarget) : url);
}
else if (requestTarget instanceof ISharedResourceRequestTarget)
{
url = requestContext.encodeSharedResourceURL(url == null ? encode(requestCycle,
(ISharedResourceRequestTarget)requestTarget) : url);
sharedResourceURL = true;
}
else if (requestTarget instanceof PageIdRequestTarget)
{
url = encode(requestCycle, (PageIdRequestTarget)requestTarget);
}
else if (requestTarget instanceof IListenerInterfaceRequestTarget)
{
if (url == null)
{
url = encode(requestCycle, (IListenerInterfaceRequestTarget)requestTarget);
}
if (portletRequest)
{
IListenerInterfaceRequestTarget iliRequestTarget = (IListenerInterfaceRequestTarget)requestTarget;
RequestListenerInterface rli = iliRequestTarget.getRequestListenerInterface();
if (IResourceListener.class.isAssignableFrom(rli.getMethod().getDeclaringClass()) ||
IBehaviorListener.class.isAssignableFrom(rli.getMethod().getDeclaringClass()))
{
url = requestContext.encodeResourceURL(url);
}
else if (IRedirectListener.class.isAssignableFrom(rli.getMethod()
.getDeclaringClass()))
{
if (((WebRequestCycle)requestCycle).getWebRequest().isAjax())
{
// TODO: Probably not all Ajax based redirects need to break out of
// ResourceURL encoding
// Need to find out and/or provide some kind of extension how to indicate
// this
url = ((PortletRequestContext)requestContext).encodeRenderURL(url, true);
}
else
{
url = requestContext.encodeRenderURL(url);
}
}
else
{
PortletRequestContext prc = (PortletRequestContext)requestContext;