001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container.state.impl;
018:
019: import java.util.Map;
020:
021: import javax.portlet.WindowState;
022: import javax.servlet.http.HttpSession;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.apache.jetspeed.JetspeedActions;
027: import org.apache.jetspeed.cache.JetspeedContentCache;
028: import org.apache.jetspeed.container.state.NavigationalState;
029: import org.apache.jetspeed.om.page.ContentPage;
030: import org.apache.jetspeed.om.page.Page;
031: import org.apache.jetspeed.request.RequestContext;
032:
033: /**
034: * SessionNavigationalState, stores nav parameters in the session, not on URL
035: *
036: * <p>
037: * Added the ability to reset portlet mode and window states to VIEW and NORMAL in the case
038: * of page navigation. JS2-806
039: * </p>
040: *
041: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
042: * @version $Id: SessionNavigationalState.java 593807 2007-11-10 19:22:03Z taylor $
043: */
044: public class SessionNavigationalState extends AbstractNavigationalState {
045: protected final Log log = LogFactory.getLog(getClass());
046: private Map currentPageWindowStates;
047: private boolean clearPortletsModeAndWindowStateEnabled = false;
048:
049: public SessionNavigationalState(NavigationalStateCodec codec,
050: JetspeedContentCache cache) {
051: super (codec, cache);
052: }
053:
054: public SessionNavigationalState(NavigationalStateCodec codec,
055: JetspeedContentCache cache,
056: JetspeedContentCache decorationCache) {
057: super (codec, cache, decorationCache);
058: }
059:
060: public synchronized void sync(RequestContext context) {
061: PortletWindowRequestNavigationalStates requestStates = getPortletWindowRequestNavigationalStates();
062:
063: // for Resource (PortletURL) requests, session state is never synchronized
064: boolean transientNavState = requestStates.getResourceWindow() != null;
065:
066: String clearCacheWindowId = null;
067:
068: if (!transientNavState) {
069: // Check if a maximized window is set in the request.
070: // This can mean a window with state MAXIMIZED *or* SOLO.
071: // With a SOLO state, also skip all synchroniziations!
072: String requestMaximizedWindowId = null;
073:
074: if (requestStates.getMaximizedWindow() != null) {
075: requestMaximizedWindowId = requestStates
076: .getMaximizedWindow().getId().toString();
077: WindowState state = requestStates
078: .getPortletWindowNavigationalState(
079: requestMaximizedWindowId)
080: .getWindowState();
081: transientNavState = JetspeedActions.SOLO_STATE
082: .equals(state);
083: clearCacheWindowId = requestMaximizedWindowId;
084: }
085:
086: }
087: if (transientNavState) {
088: // no navState synchronizations
089:
090: if (clearCacheWindowId != null) {
091: HttpSession session = context.getRequest().getSession();
092: if (session != null) {
093: PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates) session
094: .getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
095: if (sessionStates != null) {
096: sessionStates.removeFromCache(context,
097: clearCacheWindowId, cache);
098: ContentPage page = context.getPage();
099: sessionStates.removeFromCache(context, page
100: .getId(), decorationCache);
101: }
102: }
103: }
104: } else {
105: HttpSession session = context.getRequest().getSession();
106: if (session != null) {
107: PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates) session
108: .getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
109: if (sessionStates == null) {
110: sessionStates = new PortletWindowSessionNavigationalStates(
111: isRenderParameterStateFull());
112: session.setAttribute(
113: NavigationalState.NAVSTATE_SESSION_KEY,
114: sessionStates);
115: }
116: Page page = context.getPage();
117: // JS2-806
118: if (isClearPortletsModeAndWindowStateEnabled()) {
119: sessionStates
120: .changeAllPortletsToViewModeAndNormalWindowState(
121: context, page, requestStates,
122: cache, decorationCache);
123: } else {
124: sessionStates.sync(context, (Page) context
125: .getPage(), requestStates, cache,
126: decorationCache);
127: }
128: if (isNavigationalParameterStateFull()
129: && isRenderParameterStateFull()) {
130: currentPageWindowStates = sessionStates
131: .getWindowStates(page);
132: }
133: }
134: }
135: }
136:
137: public Map getCurrentPageWindowStates() {
138: return currentPageWindowStates;
139: }
140:
141: public boolean isNavigationalParameterStateFull() {
142: return true;
143: }
144:
145: public boolean isRenderParameterStateFull() {
146: return false;
147: }
148:
149: protected void setClearPortletsModeAndWindowStateEnabled(
150: boolean clearPortletsModeAndWindowStateEnabled) {
151: this .clearPortletsModeAndWindowStateEnabled = clearPortletsModeAndWindowStateEnabled;
152: }
153:
154: protected boolean isClearPortletsModeAndWindowStateEnabled() {
155: return clearPortletsModeAndWindowStateEnabled;
156: }
157: }
|