1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.container.state.impl; |
18 |
|
|
19 |
|
import java.io.Serializable; |
20 |
|
import java.util.HashMap; |
21 |
|
import java.util.Iterator; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import javax.portlet.PortletMode; |
25 |
|
import javax.portlet.WindowState; |
26 |
|
|
27 |
|
import org.apache.jetspeed.Jetspeed; |
28 |
|
import org.apache.jetspeed.cache.ContentCacheKey; |
29 |
|
import org.apache.jetspeed.cache.JetspeedContentCache; |
30 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
31 |
|
import org.apache.jetspeed.om.page.Page; |
32 |
|
import org.apache.jetspeed.request.RequestContext; |
33 |
|
import org.apache.pluto.om.window.PortletWindow; |
34 |
|
|
35 |
|
public class PortletWindowSessionNavigationalStates implements Serializable |
36 |
|
{ |
37 |
|
private static final class PageState implements Serializable |
38 |
|
{ |
39 |
|
public Map windowStates = new HashMap(); |
40 |
|
public String maximizedWindowId; |
41 |
|
} |
42 |
|
|
43 |
|
private final boolean storeParameters; |
44 |
0 |
private Map pageStates = new HashMap(); |
45 |
|
|
46 |
|
public PortletWindowSessionNavigationalStates(boolean storeParameters) |
47 |
0 |
{ |
48 |
0 |
this.storeParameters = storeParameters; |
49 |
0 |
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
public void changeAllPortletsToViewModeAndNormalWindowState(RequestContext context, Page page, PortletWindowRequestNavigationalStates requestStates, JetspeedContentCache cache, JetspeedContentCache decorationCache) |
57 |
|
{ |
58 |
0 |
final PortletMode viewMode = PortletMode.VIEW; |
59 |
0 |
final WindowState normalWindowState = WindowState.NORMAL; |
60 |
|
|
61 |
0 |
PageState pageState = (PageState)pageStates.get(page.getId()); |
62 |
0 |
if ( pageState == null ) |
63 |
|
{ |
64 |
0 |
pageState = new PageState(); |
65 |
0 |
pageStates.put(page.getId(), pageState); |
66 |
|
} |
67 |
|
|
68 |
0 |
PortletWindowRequestNavigationalState requestState = null; |
69 |
0 |
PortletWindowBaseNavigationalState sessionState = null; |
70 |
|
|
71 |
|
|
72 |
0 |
if (null != pageState.maximizedWindowId) |
73 |
|
{ |
74 |
0 |
pageState.windowStates.remove(pageState.maximizedWindowId); |
75 |
0 |
removeFromCache(context, pageState.maximizedWindowId, cache); |
76 |
0 |
removeFromCache(context, pageState.maximizedWindowId, decorationCache); |
77 |
0 |
pageState.maximizedWindowId = null; |
78 |
|
} |
79 |
|
|
80 |
0 |
Iterator iter = requestStates.getWindowIdIterator(); |
81 |
0 |
iter = pageState.windowStates.keySet().iterator(); |
82 |
|
String windowId; |
83 |
0 |
while ( iter.hasNext() ) |
84 |
|
{ |
85 |
0 |
windowId = (String)iter.next(); |
86 |
0 |
requestState = requestStates.getPortletWindowNavigationalState(windowId); |
87 |
0 |
if ( requestState == null ) |
88 |
|
{ |
89 |
0 |
requestState = new PortletWindowRequestNavigationalState(windowId); |
90 |
|
} |
91 |
|
|
92 |
0 |
requestState.setPortletMode(viewMode); |
93 |
0 |
requestState.setWindowState(normalWindowState); |
94 |
|
|
95 |
0 |
sessionState = (PortletWindowBaseNavigationalState)pageState.windowStates.get(requestState.getWindowId()); |
96 |
0 |
if ( sessionState == null ) |
97 |
|
{ |
98 |
0 |
if ( storeParameters ) |
99 |
|
{ |
100 |
0 |
sessionState = new PortletWindowExtendedNavigationalState(); |
101 |
|
} |
102 |
|
else |
103 |
|
{ |
104 |
0 |
sessionState = new PortletWindowBaseNavigationalState(); |
105 |
|
} |
106 |
0 |
pageState.windowStates.put(requestState.getWindowId(),sessionState); |
107 |
|
} |
108 |
|
|
109 |
0 |
boolean changed = syncStates(false, requestState,(PortletWindowBaseNavigationalState)pageState.windowStates.get(windowId)); |
110 |
0 |
if (changed) |
111 |
|
{ |
112 |
0 |
removeFromCache(context, requestState.getWindowId(), cache); |
113 |
0 |
removeFromCache(context, page.getId(), decorationCache); |
114 |
0 |
if (storeParameters) |
115 |
|
{ |
116 |
0 |
((PortletWindowExtendedNavigationalState)sessionState).resetDecoratorActionEncodings(); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
0 |
} |
121 |
0 |
} |
122 |
|
|
123 |
|
public void sync(RequestContext context, Page page, PortletWindowRequestNavigationalStates requestStates, JetspeedContentCache cache, JetspeedContentCache decorationCache) |
124 |
|
{ |
125 |
0 |
PageState pageState = (PageState)pageStates.get(page.getId()); |
126 |
0 |
if ( pageState == null ) |
127 |
|
{ |
128 |
0 |
pageState = new PageState(); |
129 |
0 |
pageStates.put(page.getId(), pageState); |
130 |
|
} |
131 |
|
|
132 |
0 |
PortletWindowRequestNavigationalState requestState = null; |
133 |
0 |
PortletWindowBaseNavigationalState sessionState = null; |
134 |
|
|
135 |
|
|
136 |
0 |
if ( pageState.maximizedWindowId != null ) |
137 |
|
{ |
138 |
0 |
String requestMaximizedWindowId = null; |
139 |
|
|
140 |
0 |
if ( requestStates.getMaximizedWindow() != null ) |
141 |
|
{ |
142 |
0 |
requestMaximizedWindowId = requestStates.getMaximizedWindow().getId().toString(); |
143 |
|
} |
144 |
|
|
145 |
0 |
if ( requestMaximizedWindowId == null ) |
146 |
|
{ |
147 |
|
|
148 |
0 |
requestState = requestStates.getPortletWindowNavigationalState(pageState.maximizedWindowId); |
149 |
0 |
if ( requestState != null ) |
150 |
|
{ |
151 |
0 |
if (requestState.getWindowState() != null) |
152 |
|
{ |
153 |
0 |
pageState.maximizedWindowId = null; |
154 |
|
|
155 |
|
} |
156 |
|
} |
157 |
|
else |
158 |
|
{ |
159 |
|
|
160 |
|
|
161 |
0 |
PortletWindowAccessor accessor = |
162 |
0 |
(PortletWindowAccessor)Jetspeed.getComponentManager().getComponent(PortletWindowAccessor.class); |
163 |
0 |
PortletWindow maximizedWindow = accessor.getPortletWindow(pageState.maximizedWindowId); |
164 |
0 |
if ( maximizedWindow == null ) |
165 |
|
{ |
166 |
|
|
167 |
0 |
pageState.windowStates.remove(pageState.maximizedWindowId); |
168 |
0 |
pageState.maximizedWindowId = null; |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
0 |
requestStates.setMaximizedWindow(maximizedWindow); |
173 |
|
} |
174 |
0 |
} |
175 |
|
} |
176 |
0 |
else if ( !requestMaximizedWindowId.equals( pageState.maximizedWindowId )) |
177 |
|
{ |
178 |
|
|
179 |
|
|
180 |
0 |
requestState = requestStates.getPortletWindowNavigationalState(pageState.maximizedWindowId); |
181 |
0 |
sessionState = (PortletWindowBaseNavigationalState)pageState.windowStates.get(pageState.maximizedWindowId); |
182 |
0 |
if ( requestState == null || requestState.getWindowState() == class="keyword">null ) |
183 |
|
{ |
184 |
|
|
185 |
0 |
sessionState.setWindowState(null); |
186 |
|
} |
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
0 |
if ( requestStates.getMaximizedWindow() != null ) |
191 |
|
{ |
192 |
|
|
193 |
0 |
pageState.maximizedWindowId = requestStates.getMaximizedWindow().getId().toString(); |
194 |
|
} |
195 |
|
|
196 |
0 |
Iterator iter = requestStates.getWindowIdIterator(); |
197 |
0 |
String actionWindowId = requestStates.getActionWindow() != null ? requestStates.getActionWindow().getId().toString() : class="keyword">null; |
198 |
0 |
boolean actionRequestState = false; |
199 |
|
|
200 |
0 |
while ( iter.hasNext() ) |
201 |
|
{ |
202 |
0 |
requestState = requestStates.getPortletWindowNavigationalState((String)iter.next()); |
203 |
0 |
sessionState = (PortletWindowBaseNavigationalState)pageState.windowStates.get(requestState.getWindowId()); |
204 |
0 |
if ( sessionState == null ) |
205 |
|
{ |
206 |
0 |
if ( storeParameters ) |
207 |
|
{ |
208 |
0 |
sessionState = new PortletWindowExtendedNavigationalState(); |
209 |
|
} |
210 |
|
else |
211 |
|
{ |
212 |
0 |
sessionState = new PortletWindowBaseNavigationalState(); |
213 |
|
} |
214 |
0 |
pageState.windowStates.put(requestState.getWindowId(),sessionState); |
215 |
|
} |
216 |
|
|
217 |
0 |
actionRequestState = actionWindowId != null && actionWindowId.equals(requestState.getWindowId()); |
218 |
0 |
boolean changed = syncStates(actionRequestState, requestState, sessionState); |
219 |
0 |
if (changed) |
220 |
|
{ |
221 |
0 |
removeFromCache(context, requestState.getWindowId(), cache); |
222 |
0 |
removeFromCache(context, page.getId(), decorationCache); |
223 |
0 |
if (storeParameters) |
224 |
|
{ |
225 |
0 |
((PortletWindowExtendedNavigationalState)sessionState).resetDecoratorActionEncodings(); |
226 |
|
} |
227 |
|
} |
228 |
0 |
} |
229 |
|
|
230 |
|
|
231 |
0 |
iter = pageState.windowStates.keySet().iterator(); |
232 |
|
String windowId; |
233 |
0 |
while ( iter.hasNext() ) |
234 |
|
{ |
235 |
0 |
windowId = (String)iter.next(); |
236 |
0 |
requestState = requestStates.getPortletWindowNavigationalState(windowId); |
237 |
0 |
if ( requestState == null ) |
238 |
|
{ |
239 |
0 |
requestState = new PortletWindowRequestNavigationalState(windowId); |
240 |
0 |
boolean changed = syncStates(false, requestState,(PortletWindowBaseNavigationalState)pageState.windowStates.get(windowId)); |
241 |
0 |
requestStates.addPortletWindowNavigationalState(windowId, requestState); |
242 |
0 |
if (changed) |
243 |
|
{ |
244 |
0 |
removeFromCache(context, requestState.getWindowId(), cache); |
245 |
0 |
removeFromCache(context, page.getId(), decorationCache); |
246 |
0 |
if (storeParameters) |
247 |
|
{ |
248 |
0 |
((PortletWindowExtendedNavigationalState)sessionState).resetDecoratorActionEncodings(); |
249 |
|
} |
250 |
|
} |
251 |
0 |
} |
252 |
|
} |
253 |
0 |
} |
254 |
|
|
255 |
|
private boolean modeChanged(PortletMode req, PortletMode ses) |
256 |
|
{ |
257 |
0 |
if (req == null) |
258 |
|
{ |
259 |
|
|
260 |
|
|
261 |
0 |
return false; |
262 |
|
} |
263 |
|
else |
264 |
|
{ |
265 |
0 |
if (ses == null) |
266 |
|
{ |
267 |
0 |
if (req.equals(PortletMode.VIEW)) |
268 |
0 |
return false; |
269 |
0 |
return true; |
270 |
|
} |
271 |
|
} |
272 |
0 |
return !req.equals(ses); |
273 |
|
} |
274 |
|
|
275 |
|
private boolean stateChanged(WindowState req, WindowState ses) |
276 |
|
{ |
277 |
0 |
if (req == null) |
278 |
|
{ |
279 |
|
|
280 |
|
|
281 |
0 |
return false; |
282 |
|
} |
283 |
|
else |
284 |
|
{ |
285 |
0 |
if (ses == null) |
286 |
|
{ |
287 |
0 |
if (req.equals(WindowState.NORMAL)) |
288 |
0 |
return false; |
289 |
0 |
return true; |
290 |
|
} |
291 |
|
} |
292 |
0 |
return !req.equals(ses); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
private boolean syncStates(class="keyword">boolean actionRequestState, PortletWindowRequestNavigationalState requestState, PortletWindowBaseNavigationalState sessionState) |
297 |
|
{ |
298 |
0 |
boolean changed = false; |
299 |
|
|
300 |
0 |
if (modeChanged(requestState.getPortletMode(), sessionState.getPortletMode()) |
301 |
|
|| stateChanged(requestState.getWindowState(), sessionState.getWindowState())) |
302 |
0 |
changed = true; |
303 |
|
|
304 |
0 |
if ( requestState.getPortletMode() != null ) |
305 |
|
{ |
306 |
0 |
if ( requestState.getPortletMode().equals(PortletMode.VIEW) ) |
307 |
|
{ |
308 |
0 |
sessionState.setPortletMode(null); |
309 |
|
} |
310 |
|
else |
311 |
|
{ |
312 |
0 |
sessionState.setPortletMode(requestState.getPortletMode()); |
313 |
|
} |
314 |
|
} |
315 |
0 |
else if ( sessionState.getPortletMode() == null ) |
316 |
|
{ |
317 |
0 |
requestState.setPortletMode(PortletMode.VIEW); |
318 |
|
} |
319 |
|
else |
320 |
|
{ |
321 |
0 |
requestState.setPortletMode(sessionState.getPortletMode()); |
322 |
|
} |
323 |
|
|
324 |
0 |
if ( requestState.getWindowState() != null ) |
325 |
|
{ |
326 |
0 |
if ( requestState.getWindowState().equals(WindowState.NORMAL) ) |
327 |
|
{ |
328 |
0 |
sessionState.setWindowState(null); |
329 |
|
} |
330 |
|
else |
331 |
|
{ |
332 |
0 |
sessionState.setWindowState(requestState.getWindowState()); |
333 |
|
} |
334 |
|
} |
335 |
0 |
else if ( sessionState.getWindowState() == null ) |
336 |
|
{ |
337 |
0 |
requestState.setWindowState(WindowState.NORMAL); |
338 |
|
} |
339 |
|
else |
340 |
|
{ |
341 |
0 |
requestState.setWindowState(sessionState.getWindowState()); |
342 |
|
} |
343 |
|
|
344 |
0 |
if (storeParameters) |
345 |
|
{ |
346 |
0 |
PortletWindowExtendedNavigationalState extendedSessionState = (PortletWindowExtendedNavigationalState)sessionState; |
347 |
0 |
if ( requestState.getParametersMap() != null ) |
348 |
|
{ |
349 |
0 |
if ( actionRequestState ) |
350 |
|
{ |
351 |
|
|
352 |
0 |
extendedSessionState.setParametersMap(null); |
353 |
|
} |
354 |
|
else |
355 |
|
{ |
356 |
0 |
if (changedParameters(requestState.getParametersMap(), extendedSessionState.getParametersMap())) |
357 |
|
{ |
358 |
0 |
changed = true; |
359 |
|
} |
360 |
0 |
extendedSessionState.setParametersMap(new HashMap(requestState.getParametersMap())); |
361 |
|
} |
362 |
|
} |
363 |
0 |
else if ( requestState.isClearParameters() ) |
364 |
|
{ |
365 |
0 |
extendedSessionState.setParametersMap(null); |
366 |
0 |
requestState.setClearParameters(false); |
367 |
|
|
368 |
|
} |
369 |
0 |
else if ( extendedSessionState.getParametersMap() != null ) |
370 |
|
{ |
371 |
0 |
requestState.setParametersMap(new HashMap(extendedSessionState.getParametersMap())); |
372 |
|
} |
373 |
|
} |
374 |
0 |
return changed; |
375 |
|
} |
376 |
|
|
377 |
|
protected boolean changedParameters(Map requestMap, Map sessionMap) |
378 |
|
{ |
379 |
0 |
if (sessionMap == null || requestMap == class="keyword">null) |
380 |
0 |
return true; |
381 |
0 |
if (requestMap.size() != sessionMap.size()) |
382 |
0 |
return true; |
383 |
0 |
Iterator ri = requestMap.entrySet().iterator(); |
384 |
0 |
Iterator si = sessionMap.entrySet().iterator(); |
385 |
0 |
while (ri.hasNext() && si.hasNext()) |
386 |
|
{ |
387 |
0 |
Map.Entry r = (Map.Entry)ri.next(); |
388 |
0 |
Map.Entry s = (Map.Entry)si.next(); |
389 |
0 |
if (!r.getKey().equals(s.getKey())) |
390 |
0 |
return true; |
391 |
0 |
String[] rvals = (String[])r.getValue(); |
392 |
0 |
String[] svals = (String[])s.getValue(); |
393 |
0 |
for (int ix = 0; ix < rvals.length; ix++) |
394 |
|
{ |
395 |
0 |
if (!rvals[ix].equals(svals[ix])) |
396 |
0 |
return true; |
397 |
|
} |
398 |
0 |
} |
399 |
0 |
return false; |
400 |
|
} |
401 |
|
|
402 |
|
protected void removeFromCache(RequestContext context, String id, JetspeedContentCache cache) |
403 |
|
{ |
404 |
0 |
if (cache == null) |
405 |
0 |
return; |
406 |
0 |
ContentCacheKey cacheKey = cache.createCacheKey(context, id); |
407 |
0 |
if (cache.isKeyInCache(cacheKey)) |
408 |
|
{ |
409 |
0 |
cache.remove(cacheKey); |
410 |
|
} |
411 |
0 |
cache.invalidate(context); |
412 |
0 |
} |
413 |
|
|
414 |
|
protected Map getWindowStates(Page page) |
415 |
|
{ |
416 |
0 |
PageState pageState = (PageState)pageStates.get(page.getId()); |
417 |
0 |
return pageState != null ? pageState.windowStates : class="keyword">null; |
418 |
|
} |
419 |
|
} |