1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.container.url.impl; |
18 |
|
|
19 |
|
import java.io.UnsupportedEncodingException; |
20 |
|
import java.util.Map; |
21 |
|
import java.util.StringTokenizer; |
22 |
|
|
23 |
|
import javax.portlet.PortletMode; |
24 |
|
import javax.portlet.WindowState; |
25 |
|
import javax.servlet.http.HttpServletRequest; |
26 |
|
|
27 |
|
import org.apache.jetspeed.PortalContext; |
28 |
|
import org.apache.jetspeed.PortalReservedParameters; |
29 |
|
import org.apache.jetspeed.container.state.NavigationalState; |
30 |
|
import org.apache.jetspeed.container.url.BasePortalURL; |
31 |
|
import org.apache.jetspeed.desktop.JetspeedDesktop; |
32 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
33 |
|
import org.apache.pluto.om.window.PortletWindow; |
34 |
|
import org.apache.pluto.om.entity.PortletEntity; |
35 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public class DesktopEncodingPortalURL extends AbstractPortalURL |
48 |
|
{ |
49 |
0 |
private String baseActionPath = null; |
50 |
0 |
private String baseRenderPath = null; |
51 |
|
|
52 |
0 |
private String desktopActionPipelinePath = null; |
53 |
0 |
private String desktopRenderPipelinePath = null; |
54 |
|
|
55 |
|
|
56 |
|
public DesktopEncodingPortalURL(NavigationalState navState, PortalContext portalContext, String desktopRenderPipelinePath, String desktopActionPipelinePath) |
57 |
|
{ |
58 |
0 |
super(navState, portalContext); |
59 |
0 |
initializePipelinePaths( desktopRenderPipelinePath, desktopActionPipelinePath ); |
60 |
0 |
} |
61 |
|
|
62 |
|
public DesktopEncodingPortalURL(NavigationalState navState, PortalContext portalContext, String desktopRenderPipelinePath, String desktopActionPipelinePath, BasePortalURL base) |
63 |
|
{ |
64 |
0 |
super(navState, portalContext, base); |
65 |
0 |
initializePipelinePaths( desktopRenderPipelinePath, desktopActionPipelinePath ); |
66 |
0 |
} |
67 |
|
|
68 |
|
public DesktopEncodingPortalURL(String characterEncoding, NavigationalState navState, PortalContext portalContext) |
69 |
|
{ |
70 |
0 |
super(characterEncoding, navState, portalContext); |
71 |
0 |
initializePipelinePaths( null, class="keyword">null ); |
72 |
0 |
} |
73 |
|
|
74 |
|
public DesktopEncodingPortalURL(HttpServletRequest request, String characterEncoding, NavigationalState navState, PortalContext portalContext) |
75 |
|
{ |
76 |
0 |
super(request, characterEncoding, navState, portalContext); |
77 |
0 |
initializePipelinePaths( null, class="keyword">null ); |
78 |
0 |
} |
79 |
|
|
80 |
|
private void initializePipelinePaths( String desktopRenderPipelinePath, String desktopActionPipelinePath ) |
81 |
|
{ |
82 |
0 |
if ( desktopActionPipelinePath == null || desktopActionPipelinePath.length() == 0 ) |
83 |
0 |
desktopActionPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_ACTION_PIPELINE_PATH; |
84 |
0 |
if ( desktopActionPipelinePath.charAt( 0 ) != '/' ) |
85 |
0 |
desktopActionPipelinePath = "/" + desktopActionPipelinePath; |
86 |
0 |
if ( desktopActionPipelinePath.length() > 1 && desktopActionPipelinePath.charAt( desktopActionPipelinePath.length() -1 ) == '/' ) |
87 |
0 |
desktopActionPipelinePath = desktopActionPipelinePath.substring( 0, desktopActionPipelinePath.length() -1 ); |
88 |
|
|
89 |
0 |
if ( desktopRenderPipelinePath == null || desktopRenderPipelinePath.length() == 0 ) |
90 |
0 |
desktopRenderPipelinePath = JetspeedDesktop.DEFAULT_DESKTOP_RENDER_PIPELINE_PATH; |
91 |
0 |
if ( desktopRenderPipelinePath.charAt( 0 ) != '/' ) |
92 |
0 |
desktopRenderPipelinePath = "/" + desktopRenderPipelinePath; |
93 |
0 |
if ( desktopRenderPipelinePath.length() > 1 && desktopRenderPipelinePath.charAt( desktopRenderPipelinePath.length() -1 ) == '/' ) |
94 |
0 |
desktopRenderPipelinePath = desktopRenderPipelinePath.substring( 0, desktopRenderPipelinePath.length() -1 ); |
95 |
|
|
96 |
0 |
this.desktopRenderPipelinePath = desktopRenderPipelinePath; |
97 |
0 |
this.desktopActionPipelinePath = desktopActionPipelinePath; |
98 |
0 |
} |
99 |
|
|
100 |
|
protected void decodeBasePath(HttpServletRequest request) |
101 |
|
{ |
102 |
0 |
super.decodeBasePath(request); |
103 |
0 |
if ( this.baseActionPath == null ) |
104 |
|
{ |
105 |
0 |
this.baseActionPath = contextPath + class="keyword">this.desktopActionPipelinePath; |
106 |
0 |
this.baseRenderPath = contextPath + class="keyword">this.desktopRenderPipelinePath; |
107 |
|
} |
108 |
0 |
} |
109 |
|
|
110 |
|
protected void decodePathAndNavigationalState(HttpServletRequest request) |
111 |
|
{ |
112 |
0 |
String path = null; |
113 |
0 |
String encodedNavState = null; |
114 |
|
|
115 |
0 |
String pathInfo = request.getPathInfo(); |
116 |
0 |
if (pathInfo != null) |
117 |
|
{ |
118 |
0 |
StringTokenizer tokenizer = new StringTokenizer(request.getPathInfo(),"/"); |
119 |
0 |
StringBuffer buffer = new StringBuffer(); |
120 |
|
String token; |
121 |
0 |
boolean foundNavState = false; |
122 |
0 |
String navStatePrefix = getNavigationalStateParameterName() +":"; |
123 |
0 |
while (tokenizer.hasMoreTokens()) |
124 |
|
{ |
125 |
0 |
token = tokenizer.nextToken(); |
126 |
0 |
if (!foundNavState && token.startsWith(navStatePrefix)) |
127 |
|
{ |
128 |
0 |
foundNavState = true; |
129 |
0 |
if ( token.length() > navStatePrefix.length() ) |
130 |
|
{ |
131 |
0 |
encodedNavState = token.substring(navStatePrefix.length()); |
132 |
|
} |
133 |
|
} |
134 |
|
else |
135 |
|
{ |
136 |
0 |
buffer.append("/"); |
137 |
0 |
buffer.append(token); |
138 |
|
} |
139 |
|
} |
140 |
0 |
if ( buffer.length() > 0 ) |
141 |
|
{ |
142 |
0 |
path = buffer.toString(); |
143 |
|
} |
144 |
|
else |
145 |
|
{ |
146 |
0 |
path = "/"; |
147 |
|
} |
148 |
|
} |
149 |
0 |
setPath(path); |
150 |
0 |
setEncodedNavigationalState(encodedNavState); |
151 |
0 |
} |
152 |
|
|
153 |
|
protected String createPortletURL(String encodedNavState, boolean secure) |
154 |
|
{ |
155 |
0 |
return createPortletURL(encodedNavState, secure, null, false); |
156 |
|
} |
157 |
|
|
158 |
|
protected String createPortletURL(String encodedNavState, boolean secure, PortletWindow window, class="keyword">boolean action) |
159 |
|
{ |
160 |
0 |
return createPortletURL(encodedNavState, secure, window, action, false, false); |
161 |
|
} |
162 |
|
|
163 |
|
protected String createPortletURL(String encodedNavState, boolean secure, PortletWindow window, class="keyword">boolean action, class="keyword">boolean resource, class="keyword">boolean desktopRequestNotAjax) |
164 |
|
{ |
165 |
0 |
StringBuffer buffer = new StringBuffer(""); |
166 |
0 |
buffer.append(getBaseURL(secure)); |
167 |
0 |
if (action) |
168 |
|
{ |
169 |
0 |
buffer.append(this.baseActionPath); |
170 |
|
} |
171 |
|
else |
172 |
|
{ |
173 |
0 |
buffer.append(this.baseRenderPath); |
174 |
|
} |
175 |
0 |
if ( encodedNavState != null ) |
176 |
|
{ |
177 |
0 |
buffer.append("/"); |
178 |
0 |
buffer.append(getNavigationalStateParameterName()); |
179 |
0 |
buffer.append(":"); |
180 |
0 |
buffer.append(encodedNavState); |
181 |
|
} |
182 |
0 |
if ( getPath() != null ) |
183 |
|
{ |
184 |
0 |
buffer.append(getPath()); |
185 |
|
} |
186 |
|
|
187 |
0 |
if ( !resource ) |
188 |
|
{ |
189 |
0 |
if ( ! desktopRequestNotAjax ) |
190 |
|
{ |
191 |
0 |
PortletEntity pe = window.getPortletEntity(); |
192 |
0 |
buffer.append( "?entity=" ).append( pe.getId() ); |
193 |
|
|
194 |
0 |
PortletDefinition portlet = pe.getPortletDefinition(); |
195 |
0 |
MutablePortletApplication app = (MutablePortletApplication)portlet.getPortletApplicationDefinition(); |
196 |
0 |
String uniqueName = app.getName() + "::" + portlet.getName(); |
197 |
0 |
buffer.append( "&portlet=" ).append( uniqueName ); |
198 |
0 |
} |
199 |
|
} |
200 |
|
else |
201 |
|
{ |
202 |
0 |
buffer.append("?encoder=desktop"); |
203 |
|
} |
204 |
|
|
205 |
0 |
return buffer.toString(); |
206 |
|
} |
207 |
|
|
208 |
|
public String createPortletURL(PortletWindow window, Map parameters, PortletMode mode, WindowState state, boolean action, class="keyword">boolean secure) |
209 |
|
{ |
210 |
|
try |
211 |
|
{ |
212 |
0 |
boolean resource = !action && parameters.containsKey(PortalReservedParameters.PORTLET_RESOURCE_URL_REQUEST_PARAMETER); |
213 |
0 |
boolean desktopRequestNotAjax = false; |
214 |
0 |
if ( parameters.containsKey(JetspeedDesktop.DESKTOP_REQUEST_NOT_AJAX_PARAMETER) ) |
215 |
|
{ |
216 |
0 |
desktopRequestNotAjax = true; |
217 |
0 |
parameters.remove(JetspeedDesktop.DESKTOP_REQUEST_NOT_AJAX_PARAMETER); |
218 |
|
} |
219 |
0 |
return createPortletURL(this.getNavigationalState().encode(window,parameters,mode,state,action), secure, window, action, resource, desktopRequestNotAjax); |
220 |
|
} |
221 |
0 |
catch (UnsupportedEncodingException e) |
222 |
|
{ |
223 |
|
|
224 |
0 |
e.printStackTrace(); |
225 |
|
|
226 |
0 |
return null; |
227 |
|
} |
228 |
|
} |
229 |
|
} |