1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.jetspeed.om.page.Page;
22 import org.apache.jetspeed.pipeline.PipelineException;
23 import org.apache.jetspeed.pipeline.valve.AbstractValve;
24 import org.apache.jetspeed.pipeline.valve.ValveContext;
25 import org.apache.jetspeed.request.RequestContext;
26
27
28 /***
29 * <p>
30 * Valve basically mantains the page navigation history by maintaining a previous page id in the session.
31 * Required by JS2-806
32 * </p>
33 *
34 * @author <a href="mailto:kmoh.raj@gmail.com">Mohan Kannapareddy</a>
35 * @version $Id$
36 */
37 public class PageHistoryValve extends AbstractValve
38 {
39 protected final Log log = LogFactory.getLog(getClass());
40
41
42 public static final String REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY = "clearPortletsModeAndWindowState";
43
44 private final String SESSION_PREVIOUS_PAGEID_KEY = "PreviousPageId";
45 private boolean valveDisabled = false;
46
47
48
49
50 public void invoke(RequestContext request, ValveContext context) throws PipelineException
51 {
52 if (valveDisabled)
53 {
54 if (log.isDebugEnabled())
55 {
56 log.debug(toString() + " is DISABLED");
57 }
58 }
59 else
60 {
61 try
62 {
63
64 request.getRequest().getSession(true);
65
66 Page page = request.getPage();
67 String curPageId = page.getId();
68
69 String prevPageId = (String) request.getSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY);
70 if (prevPageId == null)
71 {
72
73 request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId);
74 if (log.isDebugEnabled())
75 {
76 log.debug("No previous page Id found in session, setting it for the first time");
77 }
78 }
79 else
80 {
81
82 if (prevPageId.equalsIgnoreCase(curPageId))
83 {
84 if (log.isDebugEnabled())
85 {
86 log.debug("Previous page id is same as current page id, not clearing page state");
87 }
88 }
89 else
90 {
91 if (log.isDebugEnabled())
92 {
93 log.debug("Page Change encountered Current Page:" + curPageId + " Prev Page:" + prevPageId);
94 }
95
96 request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId);
97
98 request.setAttribute(REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY, Boolean.TRUE);
99 }
100 }
101 }
102 catch (Exception e)
103 {
104 throw new PipelineException(e);
105 }
106 }
107
108 context.invokeNext(request);
109
110 }
111
112 public String toString()
113 {
114 return "PageHistoryValve";
115 }
116
117 public void setValveDisabled(boolean valveDisabled)
118 {
119 this.valveDisabled = valveDisabled;
120 }
121
122 public boolean isValveDisabled()
123 {
124 return valveDisabled;
125 }
126
127 }