requestStates.setMaximizedWindow(context.getPortletWindow(requestState.getWindowId()));
}
}
else
{
PortletWindow maximizedWindow = context.resolvePortletWindow(pageState.maximizedWindowId);
if (maximizedWindow == null || !maximizedWindow.isValid())
{
// gone: remove sessionState
pageState.windowStates.remove(pageState.maximizedWindowId);
pageState.maximizedWindowId = null;
}
else
{
requestStates.setMaximizedWindow(maximizedWindow);
}
}
}
else if ( !requestMaximizedWindowId.equals( pageState.maximizedWindowId ))
{
// When can a non-maximized window request maximized state while another already has it?
// Maybe from a decoration portlet which always needs to be viewable?
requestState = requestStates.getPortletWindowNavigationalState(pageState.maximizedWindowId);
sessionState = pageState.windowStates.get(pageState.maximizedWindowId);
if ( requestState == null || requestState.getWindowState() == null )
{
// need to clear it ourselves first
sessionState.setWindowState(null);
}
}
}
if ( requestStates.getMaximizedWindow() != null )
{
// store the new MAXIMIZED window
pageState.maximizedWindowId = requestStates.getMaximizedWindow().getId().toString();
}
// now synchronize requestStates and sessionStates
Iterator<String> iter = requestStates.getWindowIdIterator();
String actionWindowId = requestStates.getActionWindow() != null ? requestStates.getActionWindow().getWindowId() : null;
boolean actionRequestState = false;
while ( iter.hasNext() )
{
requestState = requestStates.getPortletWindowNavigationalState(iter.next());
sessionState = pageState.windowStates.get(requestState.getWindowId());
if ( sessionState == null )
{
if ( storeParameters )
{
sessionState = new PortletWindowExtendedNavigationalState();
}
else
{
sessionState = new PortletWindowBaseNavigationalState();
}
sessionState.setActionScopedRequestAttributes(requestState.isActionScopedRequestAttributes());
pageState.windowStates.put(requestState.getWindowId(),sessionState);
}
actionRequestState = actionWindowId != null && actionWindowId.equals(requestState.getWindowId());
boolean changed = syncStates(actionRequestState, requestStates, requestState, sessionState);
if (changed)
{
removeFromCache(context, requestState.getWindowId(), cache);
removeFromCache(context, page.getId(), decorationCache);
if (storeParameters)
{
((PortletWindowExtendedNavigationalState)sessionState).resetDecoratorActionEncodings();
}
}
}
// now copy missing requestStates from the pageState
synchronized(pageState.windowStates)
{
iter = pageState.windowStates.keySet().iterator();
String windowId;
while ( iter.hasNext() )
{
windowId = iter.next();
requestState = requestStates.getPortletWindowNavigationalState(windowId);
if ( requestState == null )
{
PortletWindow window = context.resolvePortletWindow(windowId);
if (window != null)
{
requestState = new PortletWindowRequestNavigationalState(windowId);
requestState.setPortletDefinition(window.getPortletDefinition());
sessionState = pageState.windowStates.get(windowId);
requestState.setActionScopedRequestAttributes(sessionState.isActionScopedRequestAttributes());
requestStates.addPortletWindowNavigationalState(windowId, requestState);
boolean changed = syncStates(false, requestStates, requestState, sessionState);
if (changed)