MutableNavigationalState state = (MutableNavigationalState)request.getPortalURL().getNavigationalState();
if (state != null)
{
boolean redirect = false;
Page page = request.getPage();
PortletWindow window = state.getPortletWindowOfResource();
if (window != null && page.getFragmentById(window.getId().toString()) == null)
{
// target window doesn't exists anymore or the target page is not accessible (anymore)
request.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
window = state.getPortletWindowOfAction();
if (window != null && page.getFragmentById(window.getId().toString()) == null)
{
// target window doesn't exists anymore or the target page is not accessible (anymore)
// remove any navigational state for the window
state.removeState(window);
// as this is an action request which cannot be handled, perform a direct redirect after sync state (for the other windows)
redirect = true;
}
window = state.getMaximizedWindow();
if (window != null && page.getFragmentById(window.getId().toString()) == null)
{
// target window doesn't exists anymore or the target page is not accessible (anymore)
// remove any navigational state for the window
state.removeState(window);
}
state.sync(request);
if (redirect)
{
// target page doesn't contain (anymore) the targeted windowOfAction
// this can also occur when a session is expired and the target page isn't accessible for the anonymous user
// Redirect the user back to the target page (with possibly retaining the other windows navigational state).
request.getResponse().sendRedirect(request.getPortalURL().getPortalURL());
return;
}
PortletWindow actionWindow = state.getPortletWindowOfAction();
if (null == actionWindow)
{
// set to null to denote that no action was requested
request.setActionWindow(null);
}