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.jetspeed.JetspeedActions;
25  import org.apache.jetspeed.cache.JetspeedContentCache;
26  import org.apache.jetspeed.container.state.NavigationalState;
27  import org.apache.jetspeed.om.page.ContentPage;
28  import org.apache.jetspeed.om.page.Page;
29  import org.apache.jetspeed.request.RequestContext;
30  
31  /***
32   * SessionNavigationalState, stores nav parameters in the session, not on URL
33   *
34   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
35   * @version $Id: SessionNavigationalState.java 553340 2007-07-04 22:00:09Z taylor $
36   */
37  public class SessionNavigationalState extends AbstractNavigationalState
38  {   
39      private Map currentPageWindowStates;
40      
41      public SessionNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache)
42      {
43          super(codec, cache);
44      }
45      
46      public SessionNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache, JetspeedContentCache decorationCache)
47      {
48          super(codec, cache, decorationCache);
49      }    
50  
51      public synchronized void sync(RequestContext context)
52      {
53          PortletWindowRequestNavigationalStates requestStates = getPortletWindowRequestNavigationalStates();
54          
55          // for Resource (PortletURL) requests, session state is never synchronized
56          boolean transientNavState = requestStates.getResourceWindow() != null;
57          
58          String clearCacheWindowId = null;
59          
60          if (!transientNavState)
61          {
62              // Check if a maximized window is set in the request.
63              // This can mean a window with state MAXIMIZED *or* SOLO.
64              // With a SOLO state, also skip all synchroniziations!
65              String requestMaximizedWindowId = null;
66              
67              if ( requestStates.getMaximizedWindow() != null )
68              {
69                  requestMaximizedWindowId = requestStates.getMaximizedWindow().getId().toString();
70                  WindowState state = requestStates.getPortletWindowNavigationalState(requestMaximizedWindowId).getWindowState();
71                  transientNavState = JetspeedActions.SOLO_STATE.equals(state);
72                  clearCacheWindowId = requestMaximizedWindowId;
73              }
74              
75          }
76          if (transientNavState)
77          {
78              // no navState synchronizations
79              
80              if (clearCacheWindowId != null)
81              {
82                  HttpSession session = context.getRequest().getSession();
83                  if ( session != null )
84                  {
85                      PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
86                      if ( sessionStates != null )
87                      {
88                          sessionStates.removeFromCache(context, clearCacheWindowId, cache);
89                          ContentPage page = context.getPage();
90                          sessionStates.removeFromCache(context, page.getId(), decorationCache);                        
91                      }
92                  }
93              }
94          }
95          else
96          {
97              HttpSession session = context.getRequest().getSession();
98              if ( session != null )
99              {
100                 PortletWindowSessionNavigationalStates sessionStates = (PortletWindowSessionNavigationalStates)session.getAttribute(NavigationalState.NAVSTATE_SESSION_KEY);
101                 if ( sessionStates == null )
102                 {
103                     sessionStates = new PortletWindowSessionNavigationalStates(isRenderParameterStateFull());
104                     session.setAttribute(NavigationalState.NAVSTATE_SESSION_KEY, sessionStates);
105                 }
106                 Page page = context.getPage();
107                 sessionStates.sync(context, (Page) context.getPage(), requestStates, cache, decorationCache);
108                 if (isNavigationalParameterStateFull() && isRenderParameterStateFull())
109                 {
110                     currentPageWindowStates = sessionStates.getWindowStates(page);
111                 }
112             }
113         }
114     }
115     
116     public Map getCurrentPageWindowStates()
117     {
118         return currentPageWindowStates;
119     }
120     
121     public boolean isNavigationalParameterStateFull()
122     {
123         return true;
124     }
125 
126     public boolean isRenderParameterStateFull()
127     {
128         return false;
129     }
130 }