KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > servlet > multipart > MultipartHttpServletRequest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.servlet.multipart;
17
18 import java.io.BufferedReader JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.UnsupportedEncodingException JavaDoc;
21 import java.security.Principal JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import javax.servlet.RequestDispatcher JavaDoc;
29 import javax.servlet.ServletInputStream JavaDoc;
30 import javax.servlet.http.Cookie JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpSession JavaDoc;
33
34 /**
35  * Servlet request wrapper for multipart parser.
36  *
37  * @author <a HREF="mailto:j.tervoorde@home.nl">Jeroen ter Voorde</a>
38  * @author Stefano Mazzocchi
39  * @version CVS $Id: MultipartHttpServletRequest.java 179049 2005-05-30 12:21:17Z sylvain $
40  */

41 public class MultipartHttpServletRequest implements HttpServletRequest JavaDoc {
42
43     /** The wrapped request */
44     private HttpServletRequest JavaDoc request = null;
45
46     /** The submitted parts */
47     private Hashtable JavaDoc values = null;
48
49     /**
50      * Create this wrapper around the given request and including the given
51      * parts.
52      */

53     public MultipartHttpServletRequest(HttpServletRequest JavaDoc request, Hashtable JavaDoc values) {
54         this.request = request;
55         this.values = values;
56     }
57
58     /**
59      * Cleanup eventually uploaded parts that were saved on disk
60      */

61     public void cleanup() throws IOException JavaDoc {
62         Enumeration JavaDoc e = getParameterNames();
63         while (e.hasMoreElements()) {
64             Object JavaDoc o = get( (String JavaDoc)e.nextElement() );
65             if (o instanceof Part) {
66                 Part part = (Part)o;
67                 if (part.disposeWithRequest()) {
68                     part.dispose();
69                 }
70             }
71         }
72     }
73
74     /**
75      * Method get
76      *
77      * @param name
78      *
79      */

80     public Object JavaDoc get(String JavaDoc name) {
81         Object JavaDoc result = null;
82
83         if (values != null) {
84             result = values.get(name);
85
86             if (result instanceof Vector JavaDoc) {
87                 if (((Vector JavaDoc) result).size() == 1) {
88                     return ((Vector JavaDoc) result).elementAt(0);
89                 } else {
90                     return result;
91                 }
92             }
93         } else {
94             String JavaDoc[] array = request.getParameterValues(name);
95             Vector JavaDoc vec = new Vector JavaDoc();
96
97             if (array != null) {
98                 for (int i = 0; i < array.length; i++) {
99                     vec.addElement(array[i]);
100                 }
101
102                 if (vec.size() == 1) {
103                     result = vec.elementAt(0);
104                 } else {
105                     result = vec;
106                 }
107             }
108         }
109
110         return result;
111     }
112
113     /**
114      * Method getParameterNames
115      *
116      */

117     public Enumeration JavaDoc getParameterNames() {
118         if (values != null) {
119             return values.keys();
120         } else {
121             return request.getParameterNames();
122         }
123     }
124
125     /**
126      * Method getParameter
127      *
128      * @param name
129      *
130      */

131     public String JavaDoc getParameter(String JavaDoc name) {
132         if (values != null) {
133             Object JavaDoc value = get(name);
134             String JavaDoc result = null;
135     
136             if (value != null) {
137                 if (value instanceof Vector JavaDoc) {
138                     value = ((Vector JavaDoc) value).elementAt(0);
139                 }
140     
141                 result = value.toString();
142             }
143             return result;
144         } else {
145             return this.request.getParameter(name);
146         }
147     }
148
149     /**
150      * Method getParameterValues
151      *
152      * @param name
153      *
154      */

155     public String JavaDoc[] getParameterValues(String JavaDoc name) {
156         if (values != null) {
157             Object JavaDoc value = get(name);
158
159             if (value != null) {
160                 if (value instanceof Vector JavaDoc) {
161                     String JavaDoc[] results = new String JavaDoc[((Vector JavaDoc)value).size()];
162                     for (int i=0;i<((Vector JavaDoc)value).size();i++) {
163                         results[i] = ((Vector JavaDoc)value).elementAt(i).toString();
164                     }
165                     return results;
166
167                 } else {
168                     return new String JavaDoc[]{value.toString()};
169                 }
170             }
171
172             return null;
173         } else {
174             return request.getParameterValues(name);
175         }
176     }
177
178     /**
179      * Method getAttribute
180      *
181      * @param name
182      *
183      */

184     public Object JavaDoc getAttribute(String JavaDoc name) {
185         return request.getAttribute(name);
186     }
187
188     /**
189      * Method getAttributeNames
190      *
191      */

192     public Enumeration JavaDoc getAttributeNames() {
193         return request.getAttributeNames();
194     }
195
196     /**
197      * Method getCharacterEncoding
198      *
199      */

200     public String JavaDoc getCharacterEncoding() {
201         return request.getCharacterEncoding();
202     }
203
204     /**
205      * Method getContentLength
206      *
207      */

208     public int getContentLength() {
209         return request.getContentLength();
210     }
211
212     /**
213      * Method getContentType
214      *
215      */

216     public String JavaDoc getContentType() {
217         return request.getContentType();
218     }
219
220     /**
221      * Method getInputStream
222      *
223      *
224      * @throws IOException
225      */

226     public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc {
227         return request.getInputStream();
228     }
229
230     /**
231      * Method getProtocol
232      *
233      */

234     public String JavaDoc getProtocol() {
235         return request.getProtocol();
236     }
237
238     /**
239      * Method getScheme
240      *
241      */

242     public String JavaDoc getScheme() {
243         return request.getScheme();
244     }
245
246     /**
247      * Method getServerName
248      *
249      */

250     public String JavaDoc getServerName() {
251         return request.getServerName();
252     }
253
254     /**
255      * Method getServerPort
256      *
257      */

258     public int getServerPort() {
259         return request.getServerPort();
260     }
261
262     /**
263      * Method getReader
264      *
265      *
266      * @throws IOException
267      */

268     public BufferedReader JavaDoc getReader() throws IOException JavaDoc {
269         return request.getReader();
270     }
271
272     /**
273      * Method getRemoteAddr
274      *
275      */

276     public String JavaDoc getRemoteAddr() {
277         return request.getRemoteAddr();
278     }
279
280     /**
281      * Method getRemoteHost
282      *
283      */

284     public String JavaDoc getRemoteHost() {
285         return request.getRemoteHost();
286     }
287
288     /**
289      * Method setAttribute
290      *
291      * @param name
292      * @param o
293      */

294     public void setAttribute(String JavaDoc name, Object JavaDoc o) {
295         request.setAttribute(name, o);
296     }
297
298     /**
299      * Method removeAttribute
300      *
301      * @param name
302      */

303     public void removeAttribute(String JavaDoc name) {
304         request.removeAttribute(name);
305     }
306
307     /**
308      * Method getLocale
309      *
310      */

311     public Locale JavaDoc getLocale() {
312         return request.getLocale();
313     }
314
315     /**
316      * Method getLocales
317      *
318      */

319     public Enumeration JavaDoc getLocales() {
320         return request.getLocales();
321     }
322
323     /**
324      * Method isSecure
325      *
326      */

327     public boolean isSecure() {
328         return request.isSecure();
329     }
330
331     /**
332      * Method getRequestDispatcher
333      *
334      * @param path
335      *
336      */

337     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc path) {
338         return request.getRequestDispatcher(path);
339     }
340
341     /**
342      * Method getRealPath
343      *
344      * @param path
345      *
346      */

347     public String JavaDoc getRealPath(String JavaDoc path) {
348         return request.getRealPath(path);
349     }
350
351     /**
352      * Method getAuthType
353      *
354      */

355     public String JavaDoc getAuthType() {
356         return request.getAuthType();
357     }
358
359     /**
360      * Method getCookies
361      *
362      */

363     public Cookie JavaDoc[] getCookies() {
364         return request.getCookies();
365     }
366
367     /**
368      * Method getDateHeader
369      *
370      * @param name
371      *
372      */

373     public long getDateHeader(String JavaDoc name) {
374         return request.getDateHeader(name);
375     }
376
377     /**
378      * Method getHeader
379      *
380      * @param name
381      *
382      */

383     public String JavaDoc getHeader(String JavaDoc name) {
384         return request.getHeader(name);
385     }
386
387     /**
388      * Method getHeaders
389      *
390      * @param name
391      *
392      */

393     public Enumeration JavaDoc getHeaders(String JavaDoc name) {
394         return request.getHeaders(name);
395     }
396
397     /**
398      * Method getHeaderNames
399      *
400      */

401     public Enumeration JavaDoc getHeaderNames() {
402         return request.getHeaderNames();
403     }
404
405     /**
406      * Method getIntHeader
407      *
408      * @param name
409      *
410      */

411     public int getIntHeader(String JavaDoc name) {
412         return request.getIntHeader(name);
413     }
414
415     /**
416      * Method getMethod
417      *
418      */

419     public String JavaDoc getMethod() {
420         return request.getMethod();
421     }
422
423     /**
424      * Method getPathInfo
425      *
426      */

427     public String JavaDoc getPathInfo() {
428         return request.getPathInfo();
429     }
430
431     /**
432      * Method getPathTranslated
433      *
434      */

435     public String JavaDoc getPathTranslated() {
436         return request.getPathTranslated();
437     }
438
439     /**
440      * Method getContextPath
441      *
442      */

443     public String JavaDoc getContextPath() {
444         return request.getContextPath();
445     }
446
447     /**
448      * Method getQueryString
449      *
450      */

451     public String JavaDoc getQueryString() {
452         return request.getQueryString();
453     }
454
455     /**
456      * Method getRemoteUser
457      *
458      */

459     public String JavaDoc getRemoteUser() {
460         return request.getRemoteUser();
461     }
462
463     /**
464      * Method isUserInRole
465      *
466      * @param role
467      *
468      */

469     public boolean isUserInRole(String JavaDoc role) {
470         return request.isUserInRole(role);
471     }
472
473     /**
474      * Method getUserPrincipal
475      *
476      */

477     public Principal JavaDoc getUserPrincipal() {
478         return request.getUserPrincipal();
479     }
480
481     /**
482      * Method getRequestedSessionId
483      *
484      */

485     public String JavaDoc getRequestedSessionId() {
486         return request.getRequestedSessionId();
487     }
488
489     /**
490      * Method getRequestURI
491      *
492      */

493     public String JavaDoc getRequestURI() {
494         return request.getRequestURI();
495     }
496
497     /**
498      * Method getServletPath
499      *
500      */

501     public String JavaDoc getServletPath() {
502         return request.getServletPath();
503     }
504
505     /**
506      * Method getSession
507      *
508      * @param create
509      *
510      */

511     public HttpSession JavaDoc getSession(boolean create) {
512         return request.getSession(create);
513     }
514
515     /**
516      * Method getSession
517      *
518      */

519     public HttpSession JavaDoc getSession() {
520         return request.getSession();
521     }
522
523     /**
524      * Method isRequestedSessionIdValid
525      *
526      */

527     public boolean isRequestedSessionIdValid() {
528         return request.isRequestedSessionIdValid();
529     }
530
531     /**
532      * Method isRequestedSessionIdFromCookie
533      *
534      */

535     public boolean isRequestedSessionIdFromCookie() {
536         return request.isRequestedSessionIdFromCookie();
537     }
538
539     /**
540      * Method isRequestedSessionIdFromURL
541      *
542      */

543     public boolean isRequestedSessionIdFromURL() {
544         return request.isRequestedSessionIdFromURL();
545     }
546
547     /**
548      * Method isRequestedSessionIdFromUrl
549      * @deprecated use {@link #isRequestedSessionIdFromURL()} instead
550      */

551     public boolean isRequestedSessionIdFromUrl() {
552         return request.isRequestedSessionIdFromURL();
553     }
554
555     /* (non-Javadoc)
556      * @see javax.servlet.http.HttpServletRequest#getRequestURL()
557      */

558     public StringBuffer JavaDoc getRequestURL() {
559         // TODO Auto-generated method stub
560
return null;
561     }
562
563     /* (non-Javadoc)
564      * @see javax.servlet.ServletRequest#getParameterMap()
565      */

566     public Map JavaDoc getParameterMap() {
567         // TODO Auto-generated method stub
568
return null;
569     }
570
571     /* (non-Javadoc)
572      * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
573      */

574     public void setCharacterEncoding(String JavaDoc arg0)
575         throws UnsupportedEncodingException JavaDoc {
576         // TODO Auto-generated method stub
577

578     }
579
580 }
581
Popular Tags