KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > impl > DispatchedHttpServletRequest


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.impl;
10
11 import java.io.BufferedReader JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.UnsupportedEncodingException JavaDoc;
14 import java.security.Principal JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.Locale JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import javax.portlet.RenderRequest;
20 import javax.servlet.RequestDispatcher JavaDoc;
21 import javax.servlet.ServletInputStream JavaDoc;
22 import javax.servlet.http.Cookie JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpSession JavaDoc;
25
26 import org.jboss.portal.server.PortalRequest;
27
28 /**
29  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
30  * @version $Revision: 1.2 $
31  */

32 public class DispatchedHttpServletRequest implements HttpServletRequest JavaDoc
33 {
34
35    private PortalRequest preq;
36    private RenderRequest rreq;
37    private HttpServletRequest JavaDoc hreq;
38
39    private final String JavaDoc servletPath;
40    private final String JavaDoc pathInfo;
41    private final String JavaDoc queryString;
42    private final String JavaDoc requestURI;
43
44    public DispatchedHttpServletRequest(
45          PortalRequest preq,
46          RenderRequest rreq,
47          HttpServletRequest JavaDoc hreq,
48          String JavaDoc path)
49    {
50       this.preq = preq;
51       this.rreq = rreq;
52       this.hreq = hreq;
53       if (path != null)
54       {
55          int endOfServletPath = path.indexOf('/', 1);
56          if (endOfServletPath == -1)
57          {
58             endOfServletPath = path.indexOf('?', 1);
59             if (endOfServletPath == -1)
60             {
61                this.servletPath = path;
62                this.pathInfo = "";
63                this.queryString = "";
64             }
65             else
66             {
67                this.servletPath = path.substring(0, endOfServletPath);
68                this.pathInfo = "";
69                this.queryString = path.substring(endOfServletPath + 1);
70             }
71          }
72          else
73          {
74             this.servletPath = path.substring(0, endOfServletPath);
75             int endOfPathInfo = path.indexOf('?', endOfServletPath + 1);
76             if (endOfPathInfo == -1)
77             {
78                this.pathInfo = path.substring(endOfServletPath);
79                this.queryString = "";
80             }
81             else
82             {
83                this.pathInfo = path.substring(endOfServletPath, endOfPathInfo);
84                this.queryString = path.substring(endOfPathInfo + 1);
85             }
86          }
87          this.requestURI = getContextPath() + servletPath + pathInfo;
88       }
89       else
90       {
91          servletPath = null;
92          pathInfo = null;
93          queryString = null;
94          requestURI = null;
95       }
96    }
97
98    // Must return null
99

100    public String JavaDoc getProtocol()
101    {
102       return null;
103    }
104
105    public String JavaDoc getRemoteAddr()
106    {
107       return null;
108    }
109
110    public String JavaDoc getRemoteHost()
111    {
112       return null;
113    }
114
115    public String JavaDoc getRealPath(String JavaDoc s)
116    {
117       return null;
118    }
119
120    public StringBuffer JavaDoc getRequestURL()
121    {
122       return null;
123    }
124
125    // Must return the path and query string information used to obtain the PortletRequestDispatcher object
126

127    public String JavaDoc getPathInfo()
128    {
129       return pathInfo;
130    }
131
132    public String JavaDoc getQueryString()
133    {
134       return queryString;
135    }
136
137    public String JavaDoc getServletPath()
138    {
139       return servletPath;
140    }
141
142    public String JavaDoc getRequestURI()
143    {
144       return requestURI;
145    }
146
147    public String JavaDoc getPathTranslated()
148    {
149       return "PathTranslated"; // todo
150
}
151
152    // Must be equivalent to the method of the PortletRequest
153

154    public String JavaDoc getScheme()
155    {
156       return rreq.getScheme();
157    }
158
159    public String JavaDoc getServerName()
160    {
161       return rreq.getServerName();
162    }
163
164    public int getServerPort()
165    {
166       return rreq.getServerPort();
167    }
168
169    public Object JavaDoc getAttribute(String JavaDoc s)
170    {
171       return rreq.getAttribute(s);
172    }
173
174    public Enumeration JavaDoc getAttributeNames()
175    {
176       return rreq.getAttributeNames();
177    }
178
179    public void setAttribute(String JavaDoc s, Object JavaDoc o)
180    {
181       rreq.setAttribute(s, o);
182    }
183
184    public void removeAttribute(String JavaDoc s)
185    {
186       rreq.removeAttribute(s);
187    }
188
189    public Locale JavaDoc getLocale()
190    {
191       return rreq.getLocale();
192    }
193
194    public Enumeration JavaDoc getLocales()
195    {
196       return rreq.getLocales();
197    }
198
199    public boolean isSecure()
200    {
201       return rreq.isSecure();
202    }
203
204    public String JavaDoc getAuthType()
205    {
206       return rreq.getAuthType();
207    }
208
209    public String JavaDoc getContextPath()
210    {
211       return rreq.getContextPath();
212    }
213
214    public String JavaDoc getRemoteUser()
215    {
216       return rreq.getRemoteUser();
217    }
218
219    public Principal JavaDoc getUserPrincipal()
220    {
221       return rreq.getUserPrincipal();
222    }
223
224    public String JavaDoc getRequestedSessionId()
225    {
226       return rreq.getRequestedSessionId();
227    }
228
229    public boolean isRequestedSessionIdValid()
230    {
231       return rreq.isRequestedSessionIdValid();
232    }
233
234    // Must be equivalent to the method of the PortletRequest with the provision defined in PLT.16.1.1
235

236    public String JavaDoc getParameter(String JavaDoc s)
237    {
238       return rreq.getParameter(s);
239    }
240
241    public Enumeration JavaDoc getParameterNames()
242    {
243       return rreq.getParameterNames();
244    }
245
246    public String JavaDoc[] getParameterValues(String JavaDoc s)
247    {
248       return rreq.getParameterValues(s);
249    }
250
251    public Map JavaDoc getParameterMap()
252    {
253       return rreq.getParameterMap();
254    }
255
256    // Do not operate and return null or zero
257

258    public String JavaDoc getCharacterEncoding()
259    {
260       return null;
261    }
262
263    public void setCharacterEncoding(String JavaDoc s) throws UnsupportedEncodingException JavaDoc
264    {
265    }
266
267    public int getContentLength()
268    {
269       return 0;
270    }
271
272    public String JavaDoc getContentType()
273    {
274       return null;
275    }
276
277    public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc
278    {
279       return null;
280    }
281
282    public BufferedReader JavaDoc getReader() throws IOException JavaDoc
283    {
284       return null;
285    }
286
287    // Must be based on properties provided by the getProperties method of the PortletRequest interface
288

289    public String JavaDoc getHeader(String JavaDoc s)
290    {
291       return null;
292    }
293
294    public Enumeration JavaDoc getHeaders(String JavaDoc s)
295    {
296       return null;
297    }
298
299    public Enumeration JavaDoc getHeaderNames()
300    {
301       return null;
302    }
303
304    public Cookie JavaDoc[] getCookies()
305    {
306       return new Cookie JavaDoc[0];
307    }
308
309    public long getDateHeader(String JavaDoc s)
310    {
311       return 0;
312    }
313
314    public int getIntHeader(String JavaDoc s)
315    {
316       return 0;
317    }
318
319    // Must provide the functionnalities provided by the servlet specification 2.3
320

321    public String JavaDoc getMethod()
322    {
323       // The getMethod method of the HttpServletRequest must always return "GET"
324
return "GET";
325    }
326
327    public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s)
328    {
329       return preq.getRequestDispatcher(s);
330    }
331
332    public boolean isUserInRole(String JavaDoc s)
333    {
334       return false;
335    }
336
337    public HttpSession JavaDoc getSession(boolean b)
338    {
339       return hreq.getSession(b);
340    }
341
342    public HttpSession JavaDoc getSession()
343    {
344       return hreq.getSession();
345    }
346
347    public boolean isRequestedSessionIdFromCookie()
348    {
349       return false;
350    }
351
352    public boolean isRequestedSessionIdFromURL()
353    {
354       return false;
355    }
356
357    public boolean isRequestedSessionIdFromUrl()
358    {
359       return false;
360    }
361
362    // Belongs to servlet 2.4 - not specified how it should behave yet
363

364    public int getRemotePort()
365    {
366       throw new UnsupportedOperationException JavaDoc("Not specified by spec");
367    }
368
369    public String JavaDoc getLocalName()
370    {
371       throw new UnsupportedOperationException JavaDoc("Not specified by spec");
372    }
373
374    public String JavaDoc getLocalAddr()
375    {
376       throw new UnsupportedOperationException JavaDoc("Not specified by spec");
377    }
378
379    public int getLocalPort()
380    {
381       throw new UnsupportedOperationException JavaDoc("Not specified by spec");
382    }
383 }
384
Popular Tags