1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.container;
1819import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogFactory;
21import org.apache.jetspeed.om.page.Page;
22import org.apache.jetspeed.pipeline.PipelineException;
23import org.apache.jetspeed.pipeline.valve.AbstractValve;
24import org.apache.jetspeed.pipeline.valve.ValveContext;
25import org.apache.jetspeed.request.RequestContext;
262728/***29 * <p>30 * Valve basically mantains the page navigation history by maintaining a previous page id in the session.31 * Required by JS2-80632 * </p>33 * 34 * @author <a href="mailto:kmoh.raj@gmail.com">Mohan Kannapareddy</a>35 * @version $Id$36 */37publicclassPageHistoryValveextendsAbstractValve38 {
39protectedfinal Log log = LogFactory.getLog(getClass());
4041// SessionFullExtendedNavigationalState object needs this.42publicstaticfinal String REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY = "clearPortletsModeAndWindowState";
4344privatefinal String SESSION_PREVIOUS_PAGEID_KEY = "PreviousPageId";
45privateboolean valveDisabled = false;
4647/* (non-Javadoc)48 * @see org.apache.jetspeed.pipeline.valve.AbstractValve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)49 */50publicvoid invoke(RequestContext request, ValveContext context) throws PipelineException
51 {
52if (valveDisabled)
53 {
54if (log.isDebugEnabled())
55 {
56 log.debug(toString() + " is DISABLED");
57 }
58 }
59else60 { //OK, the valve is enabled check and see if are a inter-page nav.61try62 {
63// create a session if not already created, necessary for Tomcat 564 request.getRequest().getSession(true);
6566 Page page = request.getPage();
67 String curPageId = page.getId();
6869 String prevPageId = (String) request.getSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY);
70if (prevPageId == null)
71 {
72//First time, lets set it73 request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId);
74if (log.isDebugEnabled())
75 {
76 log.debug("No previous page Id found in session, setting it for the first time");
77 }
78 }
79else80 {
8182if (prevPageId.equalsIgnoreCase(curPageId))
83 {
84if (log.isDebugEnabled())
85 {
86 log.debug("Previous page id is same as current page id, not clearing page state");
87 }
88 }
89else90 {
91if (log.isDebugEnabled())
92 {
93 log.debug("Page Change encountered Current Page:" + curPageId + " Prev Page:" + prevPageId);
94 }
95// Make sure we set the prevPageId in session96 request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId);
97// inform NavigationalState object we want to clear all Modes98 request.setAttribute(REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY, Boolean.TRUE);
99 }
100 }
101 }
102catch (Exception e)
103 {
104thrownew PipelineException(e);
105 }
106 }
107// Pass control to the next Valve in the Pipeline108 context.invokeNext(request);
109110 }
111112public String toString()
113 {
114return"PageHistoryValve";
115 }
116117publicvoid setValveDisabled(boolean valveDisabled)
118 {
119this.valveDisabled = valveDisabled;
120 }
121122publicboolean isValveDisabled()
123 {
124return valveDisabled;
125 }
126127 }