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.url.impl;
1819import java.io.IOException;
2021import org.apache.jetspeed.container.state.NavigationalState;
22import org.apache.jetspeed.container.url.PortalURL;
23import org.apache.jetspeed.desktop.JetspeedDesktop;
24import org.apache.jetspeed.pipeline.PipelineException;
25import org.apache.jetspeed.pipeline.valve.AbstractValve;
26import org.apache.jetspeed.pipeline.valve.ValveContext;
27import org.apache.jetspeed.request.RequestContext;
2829/***30 * This Valve will clean encoded navstate from the browser url by sending a client side redirect31 * 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 */54publicclassCleanPathInfoEncodedNavStateFromPortalURLValveextendsAbstractValve55 {
56publicvoid invoke(RequestContext request, ValveContext context) throws PipelineException
57 {
58 NavigationalState state = request.getPortalURL().getNavigationalState();
59 PortalURL portalURL = request.getPortalURL();
6061 Boolean desktopEnabled = (Boolean) request.getAttribute(JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE);
6263if (request.getRequest().getMethod().equals("GET") && portalURL.hasEncodedNavState()
64 && portalURL.isPathInfoEncodingNavState() && state.isNavigationalParameterStateFull()
65 && state.isRenderParameterStateFull() && state.getPortletWindowOfAction() == null66 && state.getPortletWindowOfResource() == null67 && (desktopEnabled == null || desktopEnabled.booleanValue() == false))
68 {
69try70 {
71 StringBuffer location = new StringBuffer(request.getPortalURL().getBasePath());
72 String str = request.getPortalURL().getPath();
73if (str != null)
74 {
75 location.append(str);
76 }
77 str = request.getRequest().getQueryString();
78if (str != null && str.length() > 0)
79 {
80 location.append('?').append(request.getRequest().getQueryString());
81 }
82 request.getResponse().sendRedirect(request.getResponse().encodeRedirectURL(location.toString()));
83 }
84catch (IOException e)
85 {
86thrownew PipelineException(e);
87 }
88 }
89// Pass control to the next Valve in the Pipeline90 context.invokeNext(request);
91 }
92 }