001: /*
002: * de.jwic.web.UploadHttpServletRequest
003: * $Id: UploadHttpServletRequest.java,v 1.1 2006/01/16 08:31:13 lordsam Exp $
004: */
005: package de.jwic.web;
006:
007: import java.io.BufferedReader;
008: import java.io.IOException;
009: import java.io.UnsupportedEncodingException;
010: import java.security.Principal;
011: import java.util.Enumeration;
012: import java.util.Iterator;
013: import java.util.Locale;
014: import java.util.Map;
015:
016: import javax.servlet.RequestDispatcher;
017: import javax.servlet.ServletInputStream;
018: import javax.servlet.http.Cookie;
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpSession;
021:
022: /**
023: * The UploadHttpServletRequest replaces the normal HttpServletRequest after data
024: * has been send and processed in multipart format. The getParameter() method will
025: * then return data that has been read from the stream.
026: *
027: * @author Florian Lippisch
028: * @version $Revision: 1.1 $
029: */
030: public class UploadHttpServletRequest implements HttpServletRequest {
031:
032: private HttpServletRequest parentRequest = null;
033: private Map paramMap = null;
034:
035: /**
036: * Wrapper to return an Enumeration instead of an Iterator.
037: *
038: * @author Florian Lippisch
039: * @version $Revision: 1.1 $
040: */
041: private class Iterator2Enumerator implements Enumeration {
042: private Iterator it;
043:
044: public Iterator2Enumerator(Iterator iterator) {
045: it = iterator;
046: }
047:
048: public boolean hasMoreElements() {
049: return it.hasNext();
050: }
051:
052: public Object nextElement() {
053: return it.next();
054: }
055: }
056:
057: /**
058: * Constructor.
059: * @param parent
060: */
061: public UploadHttpServletRequest(HttpServletRequest parent,
062: Map parameterMap) {
063: parentRequest = parent;
064: paramMap = parameterMap;
065: }
066:
067: /* (non-Javadoc)
068: * @see javax.servlet.http.HttpServletRequest#getAuthType()
069: */
070: public String getAuthType() {
071: return parentRequest.getAuthType();
072: }
073:
074: /* (non-Javadoc)
075: * @see javax.servlet.http.HttpServletRequest#getCookies()
076: */
077: public Cookie[] getCookies() {
078: return parentRequest.getCookies();
079: }
080:
081: /* (non-Javadoc)
082: * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
083: */
084: public long getDateHeader(String arg0) {
085: return parentRequest.getDateHeader(arg0);
086: }
087:
088: /* (non-Javadoc)
089: * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
090: */
091: public String getHeader(String arg0) {
092: return parentRequest.getHeader(arg0);
093: }
094:
095: /* (non-Javadoc)
096: * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
097: */
098: public Enumeration getHeaders(String arg0) {
099: return parentRequest.getHeaders(arg0);
100: }
101:
102: /* (non-Javadoc)
103: * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
104: */
105: public Enumeration getHeaderNames() {
106: return parentRequest.getHeaderNames();
107: }
108:
109: /* (non-Javadoc)
110: * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
111: */
112: public int getIntHeader(String arg0) {
113: return parentRequest.getIntHeader(arg0);
114: }
115:
116: /* (non-Javadoc)
117: * @see javax.servlet.http.HttpServletRequest#getMethod()
118: */
119: public String getMethod() {
120: return parentRequest.getMethod();
121: }
122:
123: /* (non-Javadoc)
124: * @see javax.servlet.http.HttpServletRequest#getPathInfo()
125: */
126: public String getPathInfo() {
127: return parentRequest.getPathInfo();
128: }
129:
130: /* (non-Javadoc)
131: * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
132: */
133: public String getPathTranslated() {
134: return parentRequest.getPathTranslated();
135: }
136:
137: /* (non-Javadoc)
138: * @see javax.servlet.http.HttpServletRequest#getContextPath()
139: */
140: public String getContextPath() {
141: return parentRequest.getContextPath();
142: }
143:
144: /* (non-Javadoc)
145: * @see javax.servlet.http.HttpServletRequest#getQueryString()
146: */
147: public String getQueryString() {
148: return parentRequest.getQueryString();
149: }
150:
151: /* (non-Javadoc)
152: * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
153: */
154: public String getRemoteUser() {
155: return parentRequest.getRemoteUser();
156: }
157:
158: /* (non-Javadoc)
159: * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
160: */
161: public boolean isUserInRole(String arg0) {
162: return parentRequest.isUserInRole(arg0);
163: }
164:
165: /* (non-Javadoc)
166: * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
167: */
168: public Principal getUserPrincipal() {
169: return parentRequest.getUserPrincipal();
170: }
171:
172: /* (non-Javadoc)
173: * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
174: */
175: public String getRequestedSessionId() {
176: return parentRequest.getRequestedSessionId();
177: }
178:
179: /* (non-Javadoc)
180: * @see javax.servlet.http.HttpServletRequest#getRequestURI()
181: */
182: public String getRequestURI() {
183: return parentRequest.getRequestURI();
184: }
185:
186: /* (non-Javadoc)
187: * @see javax.servlet.http.HttpServletRequest#getRequestURL()
188: */
189: public StringBuffer getRequestURL() {
190: return parentRequest.getRequestURL();
191: }
192:
193: /* (non-Javadoc)
194: * @see javax.servlet.http.HttpServletRequest#getServletPath()
195: */
196: public String getServletPath() {
197: return parentRequest.getServletPath();
198: }
199:
200: /* (non-Javadoc)
201: * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
202: */
203: public HttpSession getSession(boolean arg0) {
204: return parentRequest.getSession(arg0);
205: }
206:
207: /* (non-Javadoc)
208: * @see javax.servlet.http.HttpServletRequest#getSession()
209: */
210: public HttpSession getSession() {
211: return parentRequest.getSession();
212: }
213:
214: /* (non-Javadoc)
215: * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
216: */
217: public boolean isRequestedSessionIdValid() {
218: return parentRequest.isRequestedSessionIdValid();
219: }
220:
221: /* (non-Javadoc)
222: * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
223: */
224: public boolean isRequestedSessionIdFromCookie() {
225: return parentRequest.isRequestedSessionIdFromCookie();
226: }
227:
228: /* (non-Javadoc)
229: * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
230: */
231: public boolean isRequestedSessionIdFromURL() {
232: return parentRequest.isRequestedSessionIdFromURL();
233: }
234:
235: /**
236: * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
237: * @deprecated
238: */
239: public boolean isRequestedSessionIdFromUrl() {
240: return parentRequest.isRequestedSessionIdFromUrl();
241: }
242:
243: /* (non-Javadoc)
244: * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
245: */
246: public Object getAttribute(String arg0) {
247: return parentRequest.getAttribute(arg0);
248: }
249:
250: /* (non-Javadoc)
251: * @see javax.servlet.ServletRequest#getAttributeNames()
252: */
253: public Enumeration getAttributeNames() {
254: return parentRequest.getAttributeNames();
255: }
256:
257: /* (non-Javadoc)
258: * @see javax.servlet.ServletRequest#getCharacterEncoding()
259: */
260: public String getCharacterEncoding() {
261: return parentRequest.getCharacterEncoding();
262: }
263:
264: /* (non-Javadoc)
265: * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
266: */
267: public void setCharacterEncoding(String arg0)
268: throws UnsupportedEncodingException {
269: parentRequest.setCharacterEncoding(arg0);
270:
271: }
272:
273: /* (non-Javadoc)
274: * @see javax.servlet.ServletRequest#getContentLength()
275: */
276: public int getContentLength() {
277: return parentRequest.getContentLength();
278: }
279:
280: /* (non-Javadoc)
281: * @see javax.servlet.ServletRequest#getContentType()
282: */
283: public String getContentType() {
284: return parentRequest.getContentType();
285: }
286:
287: /* (non-Javadoc)
288: * @see javax.servlet.ServletRequest#getInputStream()
289: */
290: public ServletInputStream getInputStream() throws IOException {
291: return parentRequest.getInputStream();
292: }
293:
294: /* (non-Javadoc)
295: * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
296: */
297: public String getParameter(String arg0) {
298: return (String) paramMap.get(arg0);
299: }
300:
301: /* (non-Javadoc)
302: * @see javax.servlet.ServletRequest#getParameterNames()
303: */
304: public Enumeration getParameterNames() {
305: return new Iterator2Enumerator(paramMap.keySet().iterator());
306: }
307:
308: /* (non-Javadoc)
309: * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
310: */
311: public String[] getParameterValues(String key) {
312: if (paramMap.containsKey(key)) {
313: return new String[] { (String) paramMap.get(key) };
314: }
315: return new String[0];
316: }
317:
318: /* (non-Javadoc)
319: * @see javax.servlet.ServletRequest#getParameterMap()
320: */
321: public Map getParameterMap() {
322: return paramMap;
323: }
324:
325: /* (non-Javadoc)
326: * @see javax.servlet.ServletRequest#getProtocol()
327: */
328: public String getProtocol() {
329: return parentRequest.getProtocol();
330: }
331:
332: /* (non-Javadoc)
333: * @see javax.servlet.ServletRequest#getScheme()
334: */
335: public String getScheme() {
336: return parentRequest.getScheme();
337: }
338:
339: /* (non-Javadoc)
340: * @see javax.servlet.ServletRequest#getServerName()
341: */
342: public String getServerName() {
343: return parentRequest.getServerName();
344: }
345:
346: /* (non-Javadoc)
347: * @see javax.servlet.ServletRequest#getServerPort()
348: */
349: public int getServerPort() {
350: return parentRequest.getServerPort();
351: }
352:
353: /* (non-Javadoc)
354: * @see javax.servlet.ServletRequest#getReader()
355: */
356: public BufferedReader getReader() throws IOException {
357: return parentRequest.getReader();
358: }
359:
360: /* (non-Javadoc)
361: * @see javax.servlet.ServletRequest#getRemoteAddr()
362: */
363: public String getRemoteAddr() {
364: return parentRequest.getRemoteAddr();
365: }
366:
367: /* (non-Javadoc)
368: * @see javax.servlet.ServletRequest#getRemoteHost()
369: */
370: public String getRemoteHost() {
371: return parentRequest.getRemoteHost();
372: }
373:
374: /* (non-Javadoc)
375: * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
376: */
377: public void setAttribute(String arg0, Object arg1) {
378: parentRequest.setAttribute(arg0, arg1);
379: }
380:
381: /* (non-Javadoc)
382: * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
383: */
384: public void removeAttribute(String arg0) {
385: parentRequest.removeAttribute(arg0);
386: }
387:
388: /* (non-Javadoc)
389: * @see javax.servlet.ServletRequest#getLocale()
390: */
391: public Locale getLocale() {
392: return parentRequest.getLocale();
393: }
394:
395: /* (non-Javadoc)
396: * @see javax.servlet.ServletRequest#getLocales()
397: */
398: public Enumeration getLocales() {
399: return parentRequest.getLocales();
400: }
401:
402: /* (non-Javadoc)
403: * @see javax.servlet.ServletRequest#isSecure()
404: */
405: public boolean isSecure() {
406: return parentRequest.isSecure();
407: }
408:
409: /* (non-Javadoc)
410: * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
411: */
412: public RequestDispatcher getRequestDispatcher(String arg0) {
413: return parentRequest.getRequestDispatcher(arg0);
414: }
415:
416: /** (non-Javadoc)
417: * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
418: * @deprecated
419: */
420: public String getRealPath(String arg0) {
421: return parentRequest.getRealPath(arg0);
422: }
423:
424: /* (non-Javadoc)
425: * @see javax.servlet.ServletRequest#getRemotePort()
426: */
427: public int getRemotePort() {
428: return parentRequest.getRemotePort();
429: }
430:
431: /* (non-Javadoc)
432: * @see javax.servlet.ServletRequest#getLocalName()
433: */
434: public String getLocalName() {
435: return parentRequest.getLocalName();
436: }
437:
438: /* (non-Javadoc)
439: * @see javax.servlet.ServletRequest#getLocalAddr()
440: */
441: public String getLocalAddr() {
442: return parentRequest.getLocalAddr();
443: }
444:
445: /* (non-Javadoc)
446: * @see javax.servlet.ServletRequest#getLocalPort()
447: */
448: public int getLocalPort() {
449: return parentRequest.getLocalPort();
450: }
451:
452: }
|