%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.container.PageHistoryValve |
|
|
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; |
|
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 | 0 | public class PageHistoryValve extends AbstractValve |
38 | { |
|
39 | 0 | protected final Log log = LogFactory.getLog(getClass()); |
40 | ||
41 | // SessionFullExtendedNavigationalState object needs this. |
|
42 | public static final String REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY = "clearPortletsModeAndWindowState"; |
|
43 | ||
44 | 0 | private final String SESSION_PREVIOUS_PAGEID_KEY = "PreviousPageId"; |
45 | 0 | private boolean valveDisabled = false; |
46 | ||
47 | /* (non-Javadoc) |
|
48 | * @see org.apache.jetspeed.pipeline.valve.AbstractValve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext) |
|
49 | */ |
|
50 | public void invoke(RequestContext request, ValveContext context) throws PipelineException |
|
51 | { |
|
52 | 0 | if (valveDisabled) |
53 | { |
|
54 | 0 | if (log.isDebugEnabled()) |
55 | { |
|
56 | 0 | log.debug(toString() + " is DISABLED"); |
57 | } |
|
58 | } |
|
59 | else |
|
60 | { //OK, the valve is enabled check and see if are a inter-page nav. |
|
61 | try |
|
62 | { |
|
63 | // create a session if not already created, necessary for Tomcat 5 |
|
64 | 0 | request.getRequest().getSession(true); |
65 | ||
66 | 0 | Page page = request.getPage(); |
67 | 0 | String curPageId = page.getId(); |
68 | ||
69 | 0 | String prevPageId = (String) request.getSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY); |
70 | 0 | if (prevPageId == null) |
71 | { |
|
72 | //First time, lets set it |
|
73 | 0 | request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId); |
74 | 0 | if (log.isDebugEnabled()) |
75 | { |
|
76 | 0 | log.debug("No previous page Id found in session, setting it for the first time"); |
77 | } |
|
78 | } |
|
79 | else |
|
80 | { |
|
81 | ||
82 | 0 | if (prevPageId.equalsIgnoreCase(curPageId)) |
83 | { |
|
84 | 0 | if (log.isDebugEnabled()) |
85 | { |
|
86 | 0 | log.debug("Previous page id is same as current page id, not clearing page state"); |
87 | } |
|
88 | } |
|
89 | else |
|
90 | { |
|
91 | 0 | if (log.isDebugEnabled()) |
92 | { |
|
93 | 0 | log.debug("Page Change encountered Current Page:" + curPageId + " Prev Page:" + prevPageId); |
94 | } |
|
95 | // Make sure we set the prevPageId in session |
|
96 | 0 | request.setSessionAttribute(SESSION_PREVIOUS_PAGEID_KEY, curPageId); |
97 | // inform NavigationalState object we want to clear all Modes |
|
98 | 0 | request.setAttribute(REQUEST_CLEAR_PORTLETS_MODE_AND_WINDOWSTATE_KEY, Boolean.TRUE); |
99 | } |
|
100 | } |
|
101 | } |
|
102 | 0 | catch (Exception e) |
103 | { |
|
104 | 0 | throw new PipelineException(e); |
105 | 0 | } |
106 | } |
|
107 | // Pass control to the next Valve in the Pipeline |
|
108 | 0 | context.invokeNext(request); |
109 | ||
110 | 0 | } |
111 | ||
112 | public String toString() |
|
113 | { |
|
114 | 0 | return "PageHistoryValve"; |
115 | } |
|
116 | ||
117 | public void setValveDisabled(boolean valveDisabled) |
|
118 | { |
|
119 | 0 | this.valveDisabled = valveDisabled; |
120 | 0 | } |
121 | ||
122 | public boolean isValveDisabled() |
|
123 | { |
|
124 | 0 | return valveDisabled; |
125 | } |
|
126 | ||
127 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |