View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.container.state.impl;
18  
19  import java.util.Map;
20  
21  import javax.portlet.WindowState;
22  import javax.servlet.http.HttpSession;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.jetspeed.JetspeedActions;
27  import org.apache.jetspeed.cache.JetspeedContentCache;
28  import org.apache.jetspeed.container.state.NavigationalState;
29  import org.apache.jetspeed.om.page.ContentPage;
30  import org.apache.jetspeed.om.page.Page;
31  import org.apache.jetspeed.request.RequestContext;
32  
33  /***
34   * SessionNavigationalState, stores nav parameters in the session, not on URL
35   *
36   * <p>
37   * Added the ability to reset portlet mode and window states to VIEW and NORMAL in the case
38   * of page navigation. JS2-806
39   * </p>
40   *
41   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
42   * @version $Id: SessionNavigationalState.java 593807 2007-11-10 19:22:03Z taylor $
43   */
44  public class SessionNavigationalState extends AbstractNavigationalState
45  {   
46      protected final Log log = LogFactory.getLog(getClass());    
47      private Map currentPageWindowStates;
48      private boolean clearPortletsModeAndWindowStateEnabled = false;
49      
50      public SessionNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache)
51      {
52          super(codec, cache);
53      }
54      
55      public SessionNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache, JetspeedContentCache decorationCache)
56      {
57          super(codec, cache, decorationCache);
58      }    
59  
60      public synchronized void sync(RequestContext context)
61      {
62          PortletWindowRequestNavigationalStates requestStates = getPortletWindowRequestNavigationalStates();
63          
64          // for Resource (PortletURL) requests, session state is never synchronized
65          boolean transientNavState = requestStates.getResourceWindow() != null;
66          
67          String clearCacheWindowId = null;
68          
69          if (!transientNavState)
70          {
71              // Check if a maximized window is set in the request.
72              // This can mean a window with state MAXIMIZED *or* SOLO.
73              // With a SOLO state, also skip all synchroniziations!
74              String requestMaximizedWindowId = null;
75              
76              if ( requestStates.getMaximizedWindow() != null )
77              {
78                  requestMaximizedWindowId = requestStates.getMaximizedWindow().getId().toString();
79                  WindowState state = requestStates.getPortletWindowNavigationalState(requestMaximizedWindowId).getWindowState();
80                  transientNavState = JetspeedActions.SOLO_STATE.equals(state);
81                  clearCacheWindowId = requestMaximizedWindowId;
82              }
83              
84          }
85          if (transientNavState)
86          {
87              // no navState synchronizations
88              
89              if (clearCacheWindowId != null)
90              {
91                  HttpSession session = context.getRequest().getSession();
92                  if ( session != null )
93                  {
94                      PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
95                      if ( sessionStates != null )
96                      {
97                          sessionStates.removeFromCache(context, clearCacheWindowId, cache);
98                          ContentPage page = context.getPage();
99                          sessionStates.removeFromCache(context, page.getId(), decorationCache);                        
100                     }
101                 }
102             }
103         }
104         else
105         {
106             HttpSession session = context.getRequest().getSession();
107             if ( session != null )
108             {
109                 PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
110                 if ( sessionStates == null )
111                 {
112                     sessionStates = new PortletWindowSessionNavigationalStates(isRenderParameterStateFull());
113                     session.setAttribute(NavigationalState.NAVSTATE_SESSION_KEY, sessionStates);
114                 }
115                 Page page = context.getPage();
116                 // JS2-806
117                 if (isClearPortletsModeAndWindowStateEnabled())
118                 {
119                     sessionStates.changeAllPortletsToViewModeAndNormalWindowState(context, page, requestStates, cache, decorationCache);
120                 }
121                 else
122                 {
123                     sessionStates.sync(context, (Page) context.getPage(), requestStates, cache, decorationCache);
124                 }
125                 if (isNavigationalParameterStateFull() && isRenderParameterStateFull())
126                 {
127                     currentPageWindowStates = sessionStates.getWindowStates(page);
128                 }
129             }
130         }
131     }
132     
133     public Map getCurrentPageWindowStates()
134     {
135         return currentPageWindowStates;
136     }
137     
138     public boolean isNavigationalParameterStateFull()
139     {
140         return true;
141     }
142 
143     public boolean isRenderParameterStateFull()
144     {
145         return false;
146     }
147 
148     protected void setClearPortletsModeAndWindowStateEnabled(
149             boolean clearPortletsModeAndWindowStateEnabled)
150     {
151         this.clearPortletsModeAndWindowStateEnabled = clearPortletsModeAndWindowStateEnabled;
152     }
153 
154     protected boolean isClearPortletsModeAndWindowStateEnabled()
155     {
156         return clearPortletsModeAndWindowStateEnabled;
157     }
158 }