01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.url.impl;
18:
19: import java.io.IOException;
20:
21: import org.apache.jetspeed.container.state.NavigationalState;
22: import org.apache.jetspeed.container.url.PortalURL;
23: import org.apache.jetspeed.desktop.JetspeedDesktop;
24: import org.apache.jetspeed.pipeline.PipelineException;
25: import org.apache.jetspeed.pipeline.valve.AbstractValve;
26: import org.apache.jetspeed.pipeline.valve.ValveContext;
27: import org.apache.jetspeed.request.RequestContext;
28:
29: /**
30: * This Valve will clean encoded navstate from the browser url by sending a client side redirect
31: * to the same url with the navstate removed.
32: * <p>
33: * This Valve will only do this:
34: * <ul>
35: * <li>on a GET Render request (not for Resource or Action requests)</li>
36: * <li>the request is not served by the Desktop</li>
37: * <li>the navstate is encoded as PathInfo</li>
38: * <li>all the navstate is maintained in the session (portlet mode, window state and render parameters)</li>
39: * </ul>
40: * </p>
41: * <p>
42: * This valve needs to be added to the portal pipeline *after* the ContainerValve to ensure navstate is properly synchronized with the session.
43: * </p>
44: * <p>
45: * Caveats:<br/>
46: * <ul>
47: * <li>bookmarking browser url will no longer retain nav state, but with SessionFullNavigationState this wasn't really reliable anyway.</li>
48: * <li>back button history is no longer maintained by browsers for GET render urls, somewhat similar to Ajax based requests (e.g. Desktop)</li>
49: * </ul>
50: * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
51: * @version $Id: CleanPathInfoEncodedNavStateFromPortalURLValve.java 605989 2007-12-20 18:26:54Z ate $
52: *
53: */
54: public class CleanPathInfoEncodedNavStateFromPortalURLValve extends
55: AbstractValve {
56: public void invoke(RequestContext request, ValveContext context)
57: throws PipelineException {
58: NavigationalState state = request.getPortalURL()
59: .getNavigationalState();
60: PortalURL portalURL = request.getPortalURL();
61:
62: Boolean desktopEnabled = (Boolean) request
63: .getAttribute(JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE);
64:
65: if (request.getRequest().getMethod().equals("GET")
66: && portalURL.hasEncodedNavState()
67: && portalURL.isPathInfoEncodingNavState()
68: && state.isNavigationalParameterStateFull()
69: && state.isRenderParameterStateFull()
70: && state.getPortletWindowOfAction() == null
71: && state.getPortletWindowOfResource() == null
72: && (desktopEnabled == null || desktopEnabled
73: .booleanValue() == false)) {
74: try {
75: StringBuffer location = new StringBuffer(request
76: .getPortalURL().getBasePath());
77: String str = request.getPortalURL().getPath();
78: if (str != null) {
79: location.append(str);
80: }
81: str = request.getRequest().getQueryString();
82: if (str != null && str.length() > 0) {
83: location.append('?').append(
84: request.getRequest().getQueryString());
85: }
86: request.getResponse().sendRedirect(
87: request.getResponse().encodeRedirectURL(
88: location.toString()));
89: } catch (IOException e) {
90: throw new PipelineException(e);
91: }
92: }
93: // Pass control to the next Valve in the Pipeline
94: context.invokeNext(request);
95: }
96: }
|