1 16 package org.apache.cocoon.servlet.multipart; 17 18 import java.io.BufferedReader ; 19 import java.io.IOException ; 20 import java.io.UnsupportedEncodingException ; 21 import java.security.Principal ; 22 import java.util.Enumeration ; 23 import java.util.Hashtable ; 24 import java.util.Locale ; 25 import java.util.Map ; 26 import java.util.Vector ; 27 28 import javax.servlet.RequestDispatcher ; 29 import javax.servlet.ServletInputStream ; 30 import javax.servlet.http.Cookie ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpSession ; 33 34 41 public class MultipartHttpServletRequest implements HttpServletRequest { 42 43 44 private HttpServletRequest request = null; 45 46 47 private Hashtable values = null; 48 49 53 public MultipartHttpServletRequest(HttpServletRequest request, Hashtable values) { 54 this.request = request; 55 this.values = values; 56 } 57 58 61 public void cleanup() throws IOException { 62 Enumeration e = getParameterNames(); 63 while (e.hasMoreElements()) { 64 Object o = get( (String )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 80 public Object get(String name) { 81 Object result = null; 82 83 if (values != null) { 84 result = values.get(name); 85 86 if (result instanceof Vector ) { 87 if (((Vector ) result).size() == 1) { 88 return ((Vector ) result).elementAt(0); 89 } else { 90 return result; 91 } 92 } 93 } else { 94 String [] array = request.getParameterValues(name); 95 Vector vec = new Vector (); 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 117 public Enumeration getParameterNames() { 118 if (values != null) { 119 return values.keys(); 120 } else { 121 return request.getParameterNames(); 122 } 123 } 124 125 131 public String getParameter(String name) { 132 if (values != null) { 133 Object value = get(name); 134 String result = null; 135 136 if (value != null) { 137 if (value instanceof Vector ) { 138 value = ((Vector ) 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 155 public String [] getParameterValues(String name) { 156 if (values != null) { 157 Object value = get(name); 158 159 if (value != null) { 160 if (value instanceof Vector ) { 161 String [] results = new String [((Vector )value).size()]; 162 for (int i=0;i<((Vector )value).size();i++) { 163 results[i] = ((Vector )value).elementAt(i).toString(); 164 } 165 return results; 166 167 } else { 168 return new String []{value.toString()}; 169 } 170 } 171 172 return null; 173 } else { 174 return request.getParameterValues(name); 175 } 176 } 177 178 184 public Object getAttribute(String name) { 185 return request.getAttribute(name); 186 } 187 188 192 public Enumeration getAttributeNames() { 193 return request.getAttributeNames(); 194 } 195 196 200 public String getCharacterEncoding() { 201 return request.getCharacterEncoding(); 202 } 203 204 208 public int getContentLength() { 209 return request.getContentLength(); 210 } 211 212 216 public String getContentType() { 217 return request.getContentType(); 218 } 219 220 226 public ServletInputStream getInputStream() throws IOException { 227 return request.getInputStream(); 228 } 229 230 234 public String getProtocol() { 235 return request.getProtocol(); 236 } 237 238 242 public String getScheme() { 243 return request.getScheme(); 244 } 245 246 250 public String getServerName() { 251 return request.getServerName(); 252 } 253 254 258 public int getServerPort() { 259 return request.getServerPort(); 260 } 261 262 268 public BufferedReader getReader() throws IOException { 269 return request.getReader(); 270 } 271 272 276 public String getRemoteAddr() { 277 return request.getRemoteAddr(); 278 } 279 280 284 public String getRemoteHost() { 285 return request.getRemoteHost(); 286 } 287 288 294 public void setAttribute(String name, Object o) { 295 request.setAttribute(name, o); 296 } 297 298 303 public void removeAttribute(String name) { 304 request.removeAttribute(name); 305 } 306 307 311 public Locale getLocale() { 312 return request.getLocale(); 313 } 314 315 319 public Enumeration getLocales() { 320 return request.getLocales(); 321 } 322 323 327 public boolean isSecure() { 328 return request.isSecure(); 329 } 330 331 337 public RequestDispatcher getRequestDispatcher(String path) { 338 return request.getRequestDispatcher(path); 339 } 340 341 347 public String getRealPath(String path) { 348 return request.getRealPath(path); 349 } 350 351 355 public String getAuthType() { 356 return request.getAuthType(); 357 } 358 359 363 public Cookie [] getCookies() { 364 return request.getCookies(); 365 } 366 367 373 public long getDateHeader(String name) { 374 return request.getDateHeader(name); 375 } 376 377 383 public String getHeader(String name) { 384 return request.getHeader(name); 385 } 386 387 393 public Enumeration getHeaders(String name) { 394 return request.getHeaders(name); 395 } 396 397 401 public Enumeration getHeaderNames() { 402 return request.getHeaderNames(); 403 } 404 405 411 public int getIntHeader(String name) { 412 return request.getIntHeader(name); 413 } 414 415 419 public String getMethod() { 420 return request.getMethod(); 421 } 422 423 427 public String getPathInfo() { 428 return request.getPathInfo(); 429 } 430 431 435 public String getPathTranslated() { 436 return request.getPathTranslated(); 437 } 438 439 443 public String getContextPath() { 444 return request.getContextPath(); 445 } 446 447 451 public String getQueryString() { 452 return request.getQueryString(); 453 } 454 455 459 public String getRemoteUser() { 460 return request.getRemoteUser(); 461 } 462 463 469 public boolean isUserInRole(String role) { 470 return request.isUserInRole(role); 471 } 472 473 477 public Principal getUserPrincipal() { 478 return request.getUserPrincipal(); 479 } 480 481 485 public String getRequestedSessionId() { 486 return request.getRequestedSessionId(); 487 } 488 489 493 public String getRequestURI() { 494 return request.getRequestURI(); 495 } 496 497 501 public String getServletPath() { 502 return request.getServletPath(); 503 } 504 505 511 public HttpSession getSession(boolean create) { 512 return request.getSession(create); 513 } 514 515 519 public HttpSession getSession() { 520 return request.getSession(); 521 } 522 523 527 public boolean isRequestedSessionIdValid() { 528 return request.isRequestedSessionIdValid(); 529 } 530 531 535 public boolean isRequestedSessionIdFromCookie() { 536 return request.isRequestedSessionIdFromCookie(); 537 } 538 539 543 public boolean isRequestedSessionIdFromURL() { 544 return request.isRequestedSessionIdFromURL(); 545 } 546 547 551 public boolean isRequestedSessionIdFromUrl() { 552 return request.isRequestedSessionIdFromURL(); 553 } 554 555 558 public StringBuffer getRequestURL() { 559 return null; 561 } 562 563 566 public Map getParameterMap() { 567 return null; 569 } 570 571 574 public void setCharacterEncoding(String arg0) 575 throws UnsupportedEncodingException { 576 578 } 579 580 } 581 | Popular Tags |