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.InputStream; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.Enumeration; |
22 |
|
import java.util.Iterator; |
23 |
|
|
24 |
|
import javax.servlet.ServletContext; |
25 |
|
import javax.servlet.RequestDispatcher; |
26 |
|
|
27 |
|
import javax.portlet.PortletContext; |
28 |
|
import javax.portlet.PortletRequestDispatcher; |
29 |
|
|
30 |
|
import org.apache.jetspeed.dispatcher.JetspeedRequestDispatcher; |
31 |
|
import org.apache.jetspeed.om.common.JetspeedServiceReference; |
32 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
33 |
|
import org.apache.jetspeed.services.JetspeedPortletServices; |
34 |
|
import org.apache.jetspeed.services.PortletServices; |
35 |
|
import org.apache.pluto.om.portlet.PortletApplicationDefinition; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public class JetspeedPortletContext implements PortletContext, InternalPortletContext |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public static final String LOCAL_PA_ROOT = "/WEB-INF/apps"; |
51 |
|
|
52 |
|
private ServletContext servletContext; |
53 |
|
private MutablePortletApplication application; |
54 |
|
|
55 |
|
public JetspeedPortletContext(ServletContext servletContext, PortletApplicationDefinition application) |
56 |
0 |
{ |
57 |
0 |
this.servletContext = servletContext; |
58 |
0 |
this.application = (MutablePortletApplication)application; |
59 |
0 |
} |
60 |
|
|
61 |
|
public int getMajorVersion() |
62 |
|
{ |
63 |
0 |
return ContainerInfo.getMajorSpecificationVersion(); |
64 |
|
} |
65 |
|
|
66 |
|
public int getMinorVersion() |
67 |
|
{ |
68 |
0 |
return ContainerInfo.getMinorSpecificationVersion(); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public java.util.Set getResourcePaths(String path) |
74 |
|
{ |
75 |
0 |
return servletContext.getResourcePaths(path); |
76 |
|
} |
77 |
|
|
78 |
|
public javax.portlet.PortletRequestDispatcher getRequestDispatcher(String path) |
79 |
|
{ |
80 |
0 |
String localizedPath = localizePath(path, this.application); |
81 |
0 |
RequestDispatcher rd = null; |
82 |
|
|
83 |
|
try |
84 |
|
{ |
85 |
0 |
rd = servletContext.getRequestDispatcher(localizedPath); |
86 |
|
} |
87 |
0 |
catch (Exception e) |
88 |
|
{ |
89 |
|
|
90 |
0 |
} |
91 |
|
|
92 |
|
|
93 |
0 |
if ( rd != null ) |
94 |
|
{ |
95 |
0 |
return new JetspeedRequestDispatcher(rd); |
96 |
|
} |
97 |
0 |
return null; |
98 |
|
} |
99 |
|
|
100 |
|
public PortletRequestDispatcher getNamedDispatcher(String name) |
101 |
|
{ |
102 |
|
|
103 |
|
|
104 |
0 |
RequestDispatcher rd = null; |
105 |
|
|
106 |
|
try |
107 |
|
{ |
108 |
0 |
rd = servletContext.getNamedDispatcher(name); |
109 |
|
} |
110 |
0 |
catch (Exception e) |
111 |
|
{ |
112 |
|
|
113 |
0 |
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
0 |
if ( rd != null ) |
118 |
|
{ |
119 |
0 |
return new JetspeedRequestDispatcher(rd); |
120 |
|
} |
121 |
0 |
return null; |
122 |
|
} |
123 |
|
|
124 |
|
public String getMimeType(String file) |
125 |
|
{ |
126 |
0 |
return servletContext.getMimeType(file); |
127 |
|
} |
128 |
|
|
129 |
|
public InputStream getResourceAsStream(String path) |
130 |
|
{ |
131 |
0 |
return servletContext.getResourceAsStream(localizePath(path, this.application)); |
132 |
|
} |
133 |
|
|
134 |
|
public java.lang.Object getAttribute(java.lang.String name) |
135 |
|
{ |
136 |
0 |
if ( name == null ) |
137 |
|
{ |
138 |
0 |
throw new IllegalArgumentException("Required parameter name is null"); |
139 |
|
} |
140 |
|
|
141 |
0 |
if (name.startsWith("cps:")) |
142 |
|
{ |
143 |
0 |
String serviceName = name.substring("cps:".length()); |
144 |
|
|
145 |
|
|
146 |
0 |
Collection validServices = application.getJetspeedServices(); |
147 |
0 |
if (null == validServices) |
148 |
|
{ |
149 |
0 |
return null; |
150 |
|
} |
151 |
0 |
boolean found = false; |
152 |
0 |
Iterator iterator = validServices.iterator(); |
153 |
0 |
while (iterator.hasNext()) |
154 |
|
{ |
155 |
0 |
JetspeedServiceReference validService = (JetspeedServiceReference)iterator.next(); |
156 |
0 |
if (validService.getName().equals(serviceName)) |
157 |
|
{ |
158 |
0 |
found = true; |
159 |
0 |
break; |
160 |
|
} |
161 |
0 |
} |
162 |
|
|
163 |
0 |
if (!found) |
164 |
|
{ |
165 |
0 |
return null; |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
0 |
PortletServices services = JetspeedPortletServices.getSingleton(); |
170 |
0 |
return services.getService(serviceName); |
171 |
|
} |
172 |
0 |
return servletContext.getAttribute(name); |
173 |
|
} |
174 |
|
|
175 |
|
public void log(java.lang.String msg) |
176 |
|
{ |
177 |
|
|
178 |
0 |
servletContext.log(msg); |
179 |
0 |
} |
180 |
|
|
181 |
|
public void log(java.lang.String message, java.lang.Throwable throwable) |
182 |
|
{ |
183 |
|
|
184 |
0 |
servletContext.log(message, throwable); |
185 |
0 |
} |
186 |
|
|
187 |
|
public String getRealPath(String path) |
188 |
|
{ |
189 |
0 |
return servletContext.getRealPath(localizePath(path, this.application)); |
190 |
|
} |
191 |
|
|
192 |
|
public java.net.URL getResource(String path) throws java.net.MalformedURLException |
193 |
|
{ |
194 |
0 |
return servletContext.getResource(localizePath(path, this.application)); |
195 |
|
} |
196 |
|
|
197 |
|
public Enumeration getAttributeNames() |
198 |
|
{ |
199 |
0 |
return servletContext.getAttributeNames(); |
200 |
|
} |
201 |
|
|
202 |
|
public java.lang.String getInitParameter(java.lang.String name) |
203 |
|
{ |
204 |
0 |
if ( name == null ) |
205 |
|
{ |
206 |
0 |
throw new IllegalArgumentException("Required parameter name is null"); |
207 |
|
} |
208 |
0 |
return servletContext.getInitParameter(name); |
209 |
|
} |
210 |
|
|
211 |
|
public java.util.Enumeration getInitParameterNames() |
212 |
|
{ |
213 |
0 |
return servletContext.getInitParameterNames(); |
214 |
|
} |
215 |
|
|
216 |
|
public void removeAttribute(java.lang.String name) |
217 |
|
{ |
218 |
0 |
if (name == null) |
219 |
|
{ |
220 |
0 |
throw new IllegalArgumentException("Attribute name == null"); |
221 |
|
} |
222 |
|
|
223 |
0 |
servletContext.removeAttribute(name); |
224 |
0 |
} |
225 |
|
|
226 |
|
public void setAttribute(java.lang.String name, java.lang.Object object) |
227 |
|
{ |
228 |
0 |
if (name == null) |
229 |
|
{ |
230 |
0 |
throw new IllegalArgumentException("Attribute name == null"); |
231 |
|
} |
232 |
0 |
servletContext.setAttribute(name, object); |
233 |
0 |
} |
234 |
|
|
235 |
|
public String getServerInfo() |
236 |
|
{ |
237 |
0 |
return ContainerInfo.getServerInfo(); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
public ServletContext getServletContext() |
243 |
|
{ |
244 |
0 |
return this.servletContext; |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
public PortletApplicationDefinition getApplication() |
251 |
|
{ |
252 |
0 |
return this.application; |
253 |
|
} |
254 |
|
|
255 |
|
public String getPortletContextName() |
256 |
|
{ |
257 |
0 |
return servletContext.getServletContextName(); |
258 |
|
} |
259 |
|
|
260 |
|
private String localizePath(String path, MutablePortletApplication app) |
261 |
|
{ |
262 |
0 |
if (path == null) |
263 |
|
{ |
264 |
0 |
return "/"; |
265 |
|
} |
266 |
0 |
return path; |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
} |
285 |
|
} |