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 java.io.IOException;
20 import java.util.Map;
21
22 import javax.portlet.PortletMode;
23 import javax.portlet.WindowState;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.pluto.PortletContainer;
28 import org.apache.pluto.PortletContainerImpl;
29 import org.apache.pluto.core.InternalActionResponse;
30 import org.apache.pluto.om.window.PortletWindow;
31 import org.apache.pluto.services.information.DynamicInformationProvider;
32 import org.apache.pluto.services.information.InformationProviderAccess;
33 import org.apache.pluto.services.information.PortletURLProvider;
34
35 import org.apache.jetspeed.desktop.JetspeedDesktop;
36
37 /***
38 * Desktop Portlet Container implementation. This implementation
39 * redirects only if the query paramater encoder=desktop is NOT specified.
40 * When the encoder=desktop parameter is specified, the 'redirect' URL
41 * is returned in the response body for use by desktop javascript code.
42 *
43 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
44 * @version $Id: $
45 */
46 public class DesktopPortletContainerImpl extends PortletContainerImpl implements PortletContainer
47 {
48 private String desktopPipelinePath = null;
49 private String desktopActionPipelinePath = null;
50 private String desktopRenderPipelinePath = null;
51
52 public DesktopPortletContainerImpl( String desktopPipelinePath, String desktopActionPipelinePath, String desktopRenderPipelinePath )
53 {
54 if ( desktopPipelinePath == null || desktopPipelinePath.length() == 0 )
55 desktopPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_PIPELINE_PATH;
56 if ( desktopPipelinePath.charAt( 0 ) != '/' )
57 desktopPipelinePath = "/" + desktopPipelinePath;
58 if ( desktopPipelinePath.charAt( desktopPipelinePath.length() -1 ) != '/' )
59 desktopPipelinePath = desktopPipelinePath + "/";
60
61 if ( desktopActionPipelinePath == null || desktopActionPipelinePath.length() == 0 )
62 desktopActionPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_ACTION_PIPELINE_PATH;
63 if ( desktopActionPipelinePath.charAt( 0 ) != '/' )
64 desktopActionPipelinePath = "/" + desktopActionPipelinePath;
65 if ( desktopActionPipelinePath.charAt( desktopActionPipelinePath.length() -1 ) != '/' )
66 desktopActionPipelinePath = desktopActionPipelinePath + "/";
67
68 if ( desktopRenderPipelinePath == null || desktopRenderPipelinePath.length() == 0 )
69 desktopRenderPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_RENDER_PIPELINE_PATH;
70 if ( desktopRenderPipelinePath.charAt( 0 ) != '/' )
71 desktopRenderPipelinePath = "/" + desktopRenderPipelinePath;
72 if ( desktopRenderPipelinePath.charAt( desktopRenderPipelinePath.length() -1 ) != '/' )
73 desktopRenderPipelinePath = desktopRenderPipelinePath + "/";
74
75 this.desktopPipelinePath = desktopPipelinePath;
76 this.desktopActionPipelinePath = desktopActionPipelinePath;
77 this.desktopRenderPipelinePath = desktopRenderPipelinePath;
78 }
79
80 /***
81 * This redirect does not redirect, instead returns the redirect URL in the response
82 */
83 protected void redirect(String location, PortletWindow portletWindow,
84 HttpServletRequest servletRequest,
85 HttpServletResponse servletResponse,
86 InternalActionResponse _actionResponse) throws IOException
87 {
88 String encoding = servletRequest.getParameter( JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER );
89 boolean requestHasDesktopEncoding = false;
90 boolean requestIsDesktopAjax = false;
91 if ( encoding != null && encoding.equals( JetspeedDesktop.DESKTOP_ENCODER_REQUEST_PARAMETER_VALUE ) )
92 {
93 requestHasDesktopEncoding = true;
94 requestIsDesktopAjax = true;
95 String ajaxOverride = servletRequest.getParameter( JetspeedDesktop.DESKTOP_AJAX_REQUEST_PARAMETER );
96 if ( ajaxOverride != null && ajaxOverride.equals( "false" ) )
97 {
98 requestIsDesktopAjax = false;
99 }
100 }
101
102 if (location == null && _actionResponse != null)
103 {
104 DynamicInformationProvider provider = InformationProviderAccess
105 .getDynamicProvider(servletRequest);
106
107
108
109 PortletMode portletMode = provider.getPortletMode(portletWindow);
110 WindowState windowState = provider.getWindowState(portletWindow);
111
112
113
114
115 if (_actionResponse.getChangedPortletMode() != null)
116 {
117 portletMode = _actionResponse.getChangedPortletMode();
118 InformationProviderAccess.getDynamicProvider(servletRequest)
119 .getPortletActionProvider(portletWindow)
120 .changePortletMode(portletMode);
121 }
122
123 if (_actionResponse.getChangedWindowState() != null)
124 {
125 windowState = _actionResponse.getChangedWindowState();
126 InformationProviderAccess.getDynamicProvider(servletRequest)
127 .getPortletActionProvider(portletWindow)
128 .changePortletWindowState(windowState);
129 }
130
131 Map renderParameter = _actionResponse.getRenderParameters();
132
133 PortletURLProvider redirectURL = provider
134 .getPortletURLProvider(portletWindow);
135
136 if (provider.getPortletMode(portletWindow) != null)
137 {
138 redirectURL.setPortletMode(portletMode);
139 }
140 if (provider.getWindowState(portletWindow) != null)
141 {
142 redirectURL.setWindowState(windowState);
143 }
144 if (servletRequest.isSecure())
145 {
146 redirectURL.setSecure();
147 }
148
149 if ( requestHasDesktopEncoding && ! requestIsDesktopAjax )
150 {
151 renderParameter.put( JetspeedDesktop.DESKTOP_REQUEST_NOT_AJAX_PARAMETER, Boolean.TRUE );
152 }
153
154 redirectURL.clearParameters();
155 redirectURL.setParameters(renderParameter);
156
157 location = servletResponse
158 .encodeRedirectURL(redirectURL.toString());
159 }
160
161 javax.servlet.http.HttpServletResponse redirectResponse = servletResponse;
162 while (redirectResponse instanceof javax.servlet.http.HttpServletResponseWrapper)
163 {
164 redirectResponse = (javax.servlet.http.HttpServletResponse) ((javax.servlet.http.HttpServletResponseWrapper) redirectResponse)
165 .getResponse();
166 }
167
168 if ( requestIsDesktopAjax )
169 {
170 location = location.replaceAll( this.desktopActionPipelinePath, this.desktopRenderPipelinePath );
171 redirectResponse.getWriter().print( location );
172 }
173 else
174 {
175 location = location.replaceAll( this.desktopActionPipelinePath, this.desktopPipelinePath );
176 location = location.replaceAll( this.desktopRenderPipelinePath, this.desktopPipelinePath);
177 redirectResponse.sendRedirect(location);
178 }
179
180
181 }
182
183 }