KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > oreilly > servlet > MultipartRequest


1 // Copyright (C) 1998-2001 by Jason Hunter <jhunter_AT_acm_DOT_org>.
2
// All rights reserved. Use of this class is limited.
3
// Please see the LICENSE for more information.
4

5 package com.oreilly.servlet;
6
7 import java.io.*;
8 import java.util.*;
9 import javax.servlet.*;
10 import javax.servlet.http.*;
11
12 import java.util.Enumeration JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import java.security.Principal JavaDoc;
16
17 import com.oreilly.servlet.multipart.MultipartParser;
18 import com.oreilly.servlet.multipart.Part;
19 import com.oreilly.servlet.multipart.FilePart;
20 import com.oreilly.servlet.multipart.ParamPart;
21 import com.oreilly.servlet.multipart.FileRenamePolicy;
22
23 /**
24  * A utility class to handle <code>multipart/form-data</code> requests,
25  * the kind of requests that support file uploads. This class emulates the
26  * interface of <code>HttpServletRequest</code>, making it familiar to use.
27  * It uses a "push" model where any incoming files are read and saved directly
28  * to disk in the constructor. If you wish to have more flexibility, e.g.
29  * write the files to a database, use the "pull" model
30  * <code>MultipartParser</code> instead.
31  * <p>
32  * This class can receive arbitrarily large files (up to an artificial limit
33  * you can set), and fairly efficiently too.
34  * It cannot handle nested data (multipart content within multipart content).
35  * It <b>can</b> now with the latest release handle internationalized content
36  * (such as non Latin-1 filenames).
37  * <p>
38  * To avoid collisions and have fine control over file placement, there's a
39  * constructor variety that takes a pluggable FileRenamePolicy implementation.
40  * A particular policy can choose to rename or change the location of the file
41  * before it's written.
42  * <p>
43  * See the included upload.war for an example of how to use this class.
44  * <p>
45  * The full file upload specification is contained in experimental RFC 1867,
46  * available at <a HREF="http://www.ietf.org/rfc/rfc1867.txt">
47  * http://www.ietf.org/rfc/rfc1867.txt</a>.
48  *
49  * @see MultipartParser
50  *
51  * @author Jason Hunter
52  * @author Geoff Soutter
53  * @version 1.11, 2002/11/01, combine query string params in param list<br>
54  * @version 1.10, 2002/05/27, added access to the original file names<br>
55  * @version 1.9, 2002/04/30, added support for file renaming, thanks to
56  * Changshin Lee<br>
57  * @version 1.8, 2002/04/30, added support for internationalization, thanks to
58  * Changshin Lee<br>
59  * @version 1.7, 2001/02/07, made fields protected to increase user flexibility<br>
60  * @version 1.6, 2000/07/21, redid internals to use MultipartParser,
61  * thanks to Geoff Soutter<br>
62  * @version 1.5, 2000/02/04, added auto MacBinary decoding for IE on Mac<br>
63  * @version 1.4, 2000/01/05, added getParameterValues(),
64  * WebSphere 2.x getContentType() workaround,
65  * stopped writing empty "unknown" file<br>
66  * @version 1.3, 1999/12/28, IE4 on Win98 lastIndexOf("boundary=")
67  * workaround<br>
68  * @version 1.2, 1999/12/20, IE4 on Mac readNextPart() workaround<br>
69  * @version 1.1, 1999/01/15, JSDK readLine() bug workaround<br>
70  * @version 1.0, 1998/09/18<br>
71  */

72 public class MultipartRequest implements HttpServletRequest {
73
74   private static final int DEFAULT_MAX_POST_SIZE = 1024 * 1024; // 1 Meg
75

76   protected Hashtable parameters = new Hashtable(); // name - Vector of values
77
protected Hashtable files = new Hashtable(); // name - UploadedFile
78
protected Cookie[] cookies;
79   protected Locale requestlocale;
80   protected String JavaDoc sessionid;
81   protected String JavaDoc encoding;
82   protected String JavaDoc servletpath;
83   protected String JavaDoc requesturi;
84   protected String JavaDoc remoteuser;
85   protected String JavaDoc querystr;
86   protected String JavaDoc ctxpath;
87   protected String JavaDoc trnpath;
88   protected String JavaDoc pathinfo;
89   protected String JavaDoc formmethod;
90   protected String JavaDoc contenttype;
91   protected int contentlength;
92   protected StringBuffer JavaDoc requesturl;
93   protected String JavaDoc savedir;
94   protected boolean bRequestedSessionIdFromURL;
95   protected boolean bRequestedSessionIdFromCookie;
96   protected boolean bRequestedSessionIdValid;
97
98   /**
99    * Constructs a new MultipartRequest to handle the specified request,
100    * saving any uploaded files to the given directory, and limiting the
101    * upload size to 1 Megabyte. If the content is too large, an
102    * IOException is thrown. This constructor actually parses the
103    * <tt>multipart/form-data</tt> and throws an IOException if there's any
104    * problem reading or parsing the request.
105    *
106    * @param request the servlet request.
107    * @param saveDirectory the directory in which to save any uploaded files.
108    * @exception IOException if the uploaded content is larger than 1 Megabyte
109    * or there's a problem reading or parsing the request.
110    */

111   public MultipartRequest(HttpServletRequest request,
112                           String JavaDoc saveDirectory) throws IOException {
113     this(request, saveDirectory, DEFAULT_MAX_POST_SIZE);
114   }
115
116   /**
117    * Constructs a new MultipartRequest to handle the specified request,
118    * saving any uploaded files to the given directory, and limiting the
119    * upload size to the specified length. If the content is too large, an
120    * IOException is thrown. This constructor actually parses the
121    * <tt>multipart/form-data</tt> and throws an IOException if there's any
122    * problem reading or parsing the request.
123    *
124    * @param request the servlet request.
125    * @param saveDirectory the directory in which to save any uploaded files.
126    * @param maxPostSize the maximum size of the POST content.
127    * @exception IOException if the uploaded content is larger than
128    * <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
129    */

130   public MultipartRequest(HttpServletRequest request,
131                           String JavaDoc saveDirectory,
132                           int maxPostSize) throws IOException {
133     this(request, saveDirectory, maxPostSize, null, null);
134   }
135
136   /**
137    * Constructs a new MultipartRequest to handle the specified request,
138    * saving any uploaded files to the given directory, and limiting the
139    * upload size to the specified length. If the content is too large, an
140    * IOException is thrown. This constructor actually parses the
141    * <tt>multipart/form-data</tt> and throws an IOException if there's any
142    * problem reading or parsing the request.
143    *
144    * @param request the servlet request.
145    * @param saveDirectory the directory in which to save any uploaded files.
146    * @param encoding the encoding of the response, such as ISO-8859-1
147    * @exception IOException if the uploaded content is larger than
148    * 1 Megabyte or there's a problem reading or parsing the request.
149    */

150   public MultipartRequest(HttpServletRequest request,
151                           String JavaDoc saveDirectory,
152                           String JavaDoc encoding) throws IOException {
153     this(request, saveDirectory, DEFAULT_MAX_POST_SIZE, encoding, null);
154   }
155
156   /**
157    * Constructs a new MultipartRequest to handle the specified request,
158    * saving any uploaded files to the given directory, and limiting the
159    * upload size to the specified length. If the content is too large, an
160    * IOException is thrown. This constructor actually parses the
161    * <tt>multipart/form-data</tt> and throws an IOException if there's any
162    * problem reading or parsing the request.
163    *
164    * @param request the servlet request.
165    * @param saveDirectory the directory in which to save any uploaded files.
166    * @param maxPostSize the maximum size of the POST content.
167    * @param encoding the encoding of the response, such as ISO-8859-1
168    * @exception IOException if the uploaded content is larger than
169    * <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
170    */

171   public MultipartRequest(HttpServletRequest request,
172                           String JavaDoc saveDirectory,
173                           int maxPostSize,
174                           FileRenamePolicy policy) throws IOException {
175     this(request, saveDirectory, maxPostSize, null, policy);
176   }
177
178   /**
179    * Constructs a new MultipartRequest to handle the specified request,
180    * saving any uploaded files to the given directory, and limiting the
181    * upload size to the specified length. If the content is too large, an
182    * IOException is thrown. This constructor actually parses the
183    * <tt>multipart/form-data</tt> and throws an IOException if there's any
184    * problem reading or parsing the request.
185    *
186    * @param request the servlet request.
187    * @param saveDirectory the directory in which to save any uploaded files.
188    * @param maxPostSize the maximum size of the POST content.
189    * @param encoding the encoding of the response, such as ISO-8859-1
190    * @exception IOException if the uploaded content is larger than
191    * <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
192    */

193   public MultipartRequest(HttpServletRequest request,
194                           String JavaDoc saveDirectory,
195                           int maxPostSize,
196                           String JavaDoc encoding) throws IOException {
197     this(request, saveDirectory, maxPostSize, encoding, null);
198   }
199
200   /**
201    * Constructs a new MultipartRequest to handle the specified request,
202    * saving any uploaded files to the given directory, and limiting the
203    * upload size to the specified length. If the content is too large, an
204    * IOException is thrown. This constructor actually parses the
205    * <tt>multipart/form-data</tt> and throws an IOException if there's any
206    * problem reading or parsing the request.
207    *
208    * To avoid file collisions, this constructor takes an implementation of the
209    * FileRenamePolicy interface to allow a pluggable rename policy.
210    *
211    * @param request the servlet request.
212    * @param saveDirectory the directory in which to save any uploaded files.
213    * @param maxPostSize the maximum size of the POST content.
214    * @param encoding the encoding of the response, such as ISO-8859-1
215    * @param policy a pluggable file rename policy
216    * @exception IOException if the uploaded content is larger than
217    * <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
218    */

219   public MultipartRequest(HttpServletRequest request,
220                           String JavaDoc saveDirectory,
221                           int maxPostSize,
222                           String JavaDoc encoding,
223                           FileRenamePolicy policy) throws IOException {
224     // Sanity check values
225
if (request == null)
226       throw new IllegalArgumentException JavaDoc("request cannot be null");
227     if (saveDirectory == null)
228       throw new IllegalArgumentException JavaDoc("saveDirectory cannot be null");
229     if (maxPostSize <= 0) {
230       throw new IllegalArgumentException JavaDoc("maxPostSize must be positive");
231     }
232
233     requestlocale = request.getLocale();
234     encoding = request.getCharacterEncoding();
235     sessionid = request.getRequestedSessionId();
236     requesturl = request.getRequestURL();
237     requesturi = request.getRequestURI();
238     remoteuser = request.getRemoteUser();
239     querystr = request.getQueryString();
240     ctxpath = request.getContextPath();
241     trnpath = request.getPathTranslated();
242     pathinfo = request.getPathInfo();
243     servletpath = request.getServletPath();
244     formmethod = request.getMethod();
245     cookies = request.getCookies();
246
247     // Save the dir
248
File dir = new File(saveDirectory);
249
250     // Check saveDirectory is truly a directory
251
if (!dir.isDirectory())
252       throw new IllegalArgumentException JavaDoc("Not a directory: " + saveDirectory);
253
254     // Check saveDirectory is writable
255
if (!dir.canWrite())
256       throw new IllegalArgumentException JavaDoc("Not writable: " + saveDirectory);
257
258     savedir = saveDirectory;
259
260     // Parse the incoming multipart, storing files in the dir provided,
261
// and populate the meta objects which describe what we found
262
MultipartParser parser = new MultipartParser(request, maxPostSize, true, true, encoding);
263
264     // Some people like to fetch query string parameters from
265
// MultipartRequest, so here we make that possible. Thanks to
266
// Ben Johnson, ben.johnson@merrillcorp.com, for the idea.
267
if (request.getQueryString() != null) {
268       // Let HttpUtils create a name->String[] structure
269
Hashtable queryParameters =
270         HttpUtils.parseQueryString(request.getQueryString());
271       // For our own use, name it a name->Vector structure
272
Enumeration JavaDoc queryParameterNames = queryParameters.keys();
273       while (queryParameterNames.hasMoreElements()) {
274         Object JavaDoc paramName = queryParameterNames.nextElement();
275         String JavaDoc[] values = (String JavaDoc[])queryParameters.get(paramName);
276         Vector newValues = new Vector();
277         for (int i = 0; i < values.length; i++) {
278           newValues.add(values[i]);
279         }
280         parameters.put(paramName, newValues);
281       }
282     }
283
284     Part part;
285     while ((part = parser.readNextPart()) != null) {
286       String JavaDoc name = part.getName();
287       if (part.isParam()) {
288         // It's a parameter part, add it to the vector of values
289
ParamPart paramPart = (ParamPart) part;
290         String JavaDoc value = paramPart.getStringValue();
291         Vector existingValues = (Vector)parameters.get(name);
292         if (existingValues == null) {
293           existingValues = new Vector();
294           parameters.put(name, existingValues);
295         }
296         existingValues.addElement(value);
297       }
298       else if (part.isFile()) {
299         // It's a file part
300
FilePart filePart = (FilePart) part;
301         String JavaDoc fileName = filePart.getFileName();
302         if (fileName != null) {
303           filePart.setRenamePolicy(policy); // null policy is OK
304
// The part actually contained a file
305
filePart.writeTo(dir);
306           files.put(name, new UploadedFile(dir.toString(),
307                                            filePart.getFileName(),
308                                            fileName,
309                                            filePart.getContentType()));
310         }
311         else {
312           // The field did not contain a file
313
files.put(name, new UploadedFile(null, null, null, null));
314         }
315       }
316     }
317     bRequestedSessionIdFromURL = request.isRequestedSessionIdFromURL();
318     bRequestedSessionIdFromCookie = request.isRequestedSessionIdFromCookie();
319     bRequestedSessionIdValid = request.isRequestedSessionIdValid();
320   }
321
322   /**
323    * Constructor with an old signature, kept for backward compatibility.
324    * Without this constructor, a servlet compiled against a previous version
325    * of this class (pre 1.4) would have to be recompiled to link with this
326    * version. This constructor supports the linking via the old signature.
327    * Callers must simply be careful to pass in an HttpServletRequest.
328    *
329    */

330   public MultipartRequest(ServletRequest request,
331                           String JavaDoc saveDirectory) throws IOException {
332     this((HttpServletRequest)request, saveDirectory);
333   }
334
335   /**
336    * Constructor with an old signature, kept for backward compatibility.
337    * Without this constructor, a servlet compiled against a previous version
338    * of this class (pre 1.4) would have to be recompiled to link with this
339    * version. This constructor supports the linking via the old signature.
340    * Callers must simply be careful to pass in an HttpServletRequest.
341    *
342    */

343   public MultipartRequest(ServletRequest request,
344                           String JavaDoc saveDirectory,
345                           int maxPostSize) throws IOException {
346     this((HttpServletRequest)request, saveDirectory, maxPostSize);
347   }
348
349   public Cookie[] getCookies() {
350     return cookies;
351   }
352
353   public Locale getLocale() {
354     return requestlocale;
355   }
356
357   /**
358    * Returns the names of all the parameters as an Enumeration of
359    * Strings. It returns an empty Enumeration if there are no parameters.
360    *
361    * @return the names of all the parameters as an Enumeration of Strings.
362    */

363   public Enumeration JavaDoc getParameterNames() {
364     return parameters.keys();
365   }
366
367   /**
368    * @return number of uploaded files
369    */

370
371   public int getFileCount() {
372     int iCount = 0;
373     Enumeration JavaDoc oFiles = files.keys();
374     Object JavaDoc oFileName;
375
376     while (oFiles.hasMoreElements()) {
377       oFileName = oFiles.nextElement();
378       if (null!=oFileName)
379         if (!oFileName.equals(""))
380           iCount++;
381     } // wend
382
return iCount;
383   } // getFileCount
384

385   /**
386    * Returns the names of all the uploaded files as an Enumeration of
387    * Strings. It returns an empty Enumeration if there are no uploaded
388    * files. Each file name is the name specified by the form, not by
389    * the user.
390    *
391    * @return the names of all the uploaded files as an Enumeration of Strings.
392    */

393   public Enumeration JavaDoc getFileNames() {
394     return files.keys();
395   }
396
397   /**
398    * Returns the value of the named parameter as a String, or null if
399    * the parameter was not sent or was sent without a value. The value
400    * is guaranteed to be in its normal, decoded form. If the parameter
401    * has multiple values, only the last one is returned (for backward
402    * compatibility). For parameters with multiple values, it's possible
403    * the last "value" may be null.
404    *
405    * @param name the parameter name.
406    * @return the parameter value.
407    */

408   public String JavaDoc getParameter(String JavaDoc name) {
409     try {
410       Vector values = (Vector)parameters.get(name);
411       if (values == null || values.size() == 0) {
412         return null;
413       }
414       String JavaDoc value = (String JavaDoc)values.elementAt(values.size() - 1);
415       return value;
416     }
417     catch (Exception JavaDoc e) {
418       return null;
419     }
420   }
421
422   /**
423    * Returns the values of the named parameter as a String array, or null if
424    * the parameter was not sent. The array has one entry for each parameter
425    * field sent. If any field was sent without a value that entry is stored
426    * in the array as a null. The values are guaranteed to be in their
427    * normal, decoded form. A single value is returned as a one-element array.
428    *
429    * @param name the parameter name.
430    * @return the parameter values.
431    */

432   public String JavaDoc[] getParameterValues(String JavaDoc name) {
433     try {
434       Vector values = (Vector)parameters.get(name);
435       if (values == null || values.size() == 0) {
436         return null;
437       }
438       String JavaDoc[] valuesArray = new String JavaDoc[values.size()];
439       values.copyInto(valuesArray);
440       return valuesArray;
441     }
442     catch (Exception JavaDoc e) {
443       return null;
444     }
445   }
446
447   /**
448    * Returns the filesystem name of the specified file, or null if the
449    * file was not included in the upload. A filesystem name is the name
450    * specified by the user. It is also the name under which the file is
451    * actually saved.
452    *
453    * @param name the file name.
454    * @return the filesystem name of the file.
455    */

456   public String JavaDoc getFilesystemName(String JavaDoc name) {
457     try {
458       UploadedFile file = (UploadedFile)files.get(name);
459       return file.getFilesystemName(); // may be null
460
}
461     catch (Exception JavaDoc e) {
462       return null;
463     }
464   }
465
466   /**
467    * Returns the original filesystem name of the specified file (before any
468    * renaming policy was applied), or null if the file was not included in
469    * the upload. A filesystem name is the name specified by the user.
470    *
471    * @param name the file name.
472    * @return the original file name of the file.
473    */

474   public String JavaDoc getOriginalFileName(String JavaDoc name) {
475     try {
476       UploadedFile file = (UploadedFile)files.get(name);
477       return file.getOriginalFileName(); // may be null
478
}
479     catch (Exception JavaDoc e) {
480       return null;
481     }
482   }
483
484   public String JavaDoc getCharacterEncoding() {
485     return encoding;
486   }
487
488   /**
489    * Returns the content type of the specified file (as supplied by the
490    * client browser), or null if the file was not included in the upload.
491    *
492    * @param name the file name.
493    * @return the content type of the file.
494    */

495   public String JavaDoc getContentType(String JavaDoc name) {
496     try {
497       UploadedFile file = (UploadedFile)files.get(name);
498       return file.getContentType(); // may be null
499
}
500     catch (Exception JavaDoc e) {
501       return null;
502     }
503   }
504
505   /**
506    * Returns a File object for the specified file saved on the server's
507    * filesystem, or null if the file was not included in the upload.
508    * @param name the file name.
509    * @return a File object for the named file.
510    */

511   public File getFile(String JavaDoc name) {
512     try {
513       UploadedFile file = (UploadedFile)files.get(name);
514       return file.getFile(); // may be null
515
}
516     catch (Exception JavaDoc e) {
517       return null;
518     }
519   }
520
521   /**
522    * Returns a File object for the specified uploaded file
523    * @param number int [0..getFileCount()-1]
524    * @return File
525    */

526   public File getFile(int number) {
527     UploadedFile file = null;
528     Enumeration JavaDoc fileenum = files.elements();
529     try {
530       for (int f=0; f<getFileCount(); f++)
531         file = (UploadedFile) fileenum.nextElement();
532       return file.getFile(); // may be null
533
}
534     catch (Exception JavaDoc e) {
535       return null;
536     }
537   } // getFile
538

539   public String JavaDoc getContentType() {
540     return contenttype;
541   }
542
543   public int getContentLength() {
544     return contentlength;
545   }
546
547   /**
548    * <p>Returns the part of this request's URL that calls the servlet.</p>
549    * Returns the part of this request's URL that calls the servlet.
550    * This includes either the servlet name or a path to the servlet,
551    * but does not include any extra path information or a query string.
552    * Same as the value of the CGI variable SCRIPT_NAME.
553    * @return String containing the name or path of the servlet being called,
554    * as specified in the request URL, decoded.
555    */

556   public String JavaDoc getServletPath() {
557     return servletpath;
558   }
559
560   public String JavaDoc getContextPath() {
561     return ctxpath;
562   }
563
564   public String JavaDoc getPathInfo() {
565     return pathinfo;
566   }
567
568   public String JavaDoc getPathTranslated() {
569     return trnpath;
570   }
571
572   public String JavaDoc getMethod() {
573     return formmethod;
574   }
575
576   public String JavaDoc getRemoteUser() {
577     return remoteuser;
578   }
579
580   public String JavaDoc getRequestURI() {
581     return requesturi;
582   }
583
584   public StringBuffer JavaDoc getRequestURL() {
585     return requesturl;
586   }
587
588   public String JavaDoc getRequestedSessionId() {
589     return sessionid;
590   }
591
592   public String JavaDoc getQueryString() {
593     return querystr;
594   }
595
596   public boolean isRequestedSessionIdFromURL() {
597     return bRequestedSessionIdFromURL;
598   }
599
600   public boolean isRequestedSessionIdFromUrl() {
601     return bRequestedSessionIdFromURL;
602   }
603
604   public boolean isRequestedSessionIdFromCookie() {
605     return bRequestedSessionIdFromCookie;
606   }
607
608   public boolean isRequestedSessionIdValid() {
609     return bRequestedSessionIdValid;
610   }
611
612   public Enumeration JavaDoc getAttributeNames() {
613     throw new RuntimeException JavaDoc("HttpServletRequest.getAttributeNames() method not implemented for MultipartRequest");
614   }
615
616   public Object JavaDoc getAttribute(String JavaDoc sAttrName) {
617     throw new RuntimeException JavaDoc("HttpServletRequest.getAttribute() method not implemented for MultipartRequest");
618   }
619
620   public void setAttribute(String JavaDoc sAttrName, Object JavaDoc sAttrVal) {
621     throw new RuntimeException JavaDoc("HttpServletRequest.setAttribute() method not implemented for MultipartRequest");
622   }
623
624   public void removeAttribute(String JavaDoc sAttrName) {
625     throw new RuntimeException JavaDoc("HttpServletRequest.removeAttribute() method not implemented for MultipartRequest");
626   }
627
628   public Enumeration JavaDoc getLocales() {
629     throw new RuntimeException JavaDoc("HttpServletRequest.getLocales() method not implemented for MultipartRequest");
630   }
631
632   public boolean isSecure() {
633     throw new RuntimeException JavaDoc("HttpServletRequest.isSecure() method not implemented for MultipartRequest");
634   }
635
636   public String JavaDoc getAuthType() {
637     throw new RuntimeException JavaDoc("HttpServletRequest.getAuthType() method not implemented for MultipartRequest");
638   }
639
640   public int getLocalPort() {
641     throw new RuntimeException JavaDoc("HttpServletRequest.getLocalPort() method not implemented for MultipartRequest");
642   }
643
644   public String JavaDoc getProtocol() {
645     throw new RuntimeException JavaDoc("HttpServletRequest.getProtocol() method not implemented for MultipartRequest");
646   }
647
648   public Map JavaDoc getParameterMap() {
649     throw new RuntimeException JavaDoc("HttpServletRequest.getParameterMap() method not implemented for MultipartRequest");
650   }
651
652   public String JavaDoc getScheme() {
653     throw new RuntimeException JavaDoc("HttpServletRequest.getScheme() method not implemented for MultipartRequest");
654   }
655
656   public String JavaDoc getServerName() {
657     throw new RuntimeException JavaDoc("HttpServletRequest.getServerName() method not implemented for MultipartRequest");
658   }
659
660   public int getServerPort() {
661     throw new RuntimeException JavaDoc("HttpServletRequest.getServerPort() method not implemented for MultipartRequest");
662   }
663
664   public int getRemotePort() {
665     throw new RuntimeException JavaDoc("HttpServletRequest.getRemotePort() method not implemented for MultipartRequest");
666   }
667
668   public String JavaDoc getLocalAddr() {
669     throw new RuntimeException JavaDoc("HttpServletRequest.getLocalAddr() method not implemented for MultipartRequest");
670   }
671
672   public String JavaDoc getLocalName() {
673     throw new RuntimeException JavaDoc("HttpServletRequest.getLocalName() method not implemented for MultipartRequest");
674   }
675
676   public String JavaDoc getRemoteAddr() {
677     throw new RuntimeException JavaDoc("HttpServletRequest.getRemoteAddr() method not implemented for MultipartRequest");
678   }
679
680   public String JavaDoc getRemoteHost() {
681     throw new RuntimeException JavaDoc("HttpServletRequest.getRemoteHost() method not implemented for MultipartRequest");
682   }
683
684   public HttpSession getSession() {
685     throw new RuntimeException JavaDoc("HttpServletRequest.getSession() method not implemented for MultipartRequest");
686   }
687
688   public HttpSession getSession(boolean b) {
689     throw new RuntimeException JavaDoc("HttpServletRequest.getSession() method not implemented for MultipartRequest");
690   }
691
692   public Principal JavaDoc getUserPrincipal() {
693     throw new RuntimeException JavaDoc("HttpServletRequest.getUserPrincipal() method not implemented for MultipartRequest");
694   }
695
696   public String JavaDoc getRealPath(String JavaDoc s) {
697     throw new RuntimeException JavaDoc("HttpServletRequest.getRealPath() method not implemented for MultipartRequest");
698   }
699
700   public RequestDispatcher getRequestDispatcher(String JavaDoc s) {
701     throw new RuntimeException JavaDoc("HttpServletRequest.getRequestDispatcher() method not implemented for MultipartRequest");
702   }
703
704   public boolean isUserInRole(String JavaDoc role) {
705     throw new RuntimeException JavaDoc("HttpServletRequest.isUserInRole() method not implemented for MultipartRequest");
706   }
707
708   public String JavaDoc getHeader(String JavaDoc hname) {
709     throw new RuntimeException JavaDoc("HttpServletRequest.getHeader() method not implemented for MultipartRequest");
710   }
711
712   public Enumeration JavaDoc getHeaders(String JavaDoc hname) {
713     throw new RuntimeException JavaDoc("HttpServletRequest.getHeaders() method not implemented for MultipartRequest");
714   }
715
716   public int getIntHeader(String JavaDoc hname) {
717     throw new RuntimeException JavaDoc("HttpServletRequest.getIntHeader() method not implemented for MultipartRequest");
718   }
719
720   public long getDateHeader(String JavaDoc hname) {
721     throw new RuntimeException JavaDoc("HttpServletRequest.getDateHeader() method not implemented for MultipartRequest");
722   }
723
724   public Enumeration JavaDoc getHeaderNames() {
725     throw new RuntimeException JavaDoc("HttpServletRequest.getHeaderNames() method not implemented for MultipartRequest");
726   }
727
728   public BufferedReader getReader() {
729     throw new RuntimeException JavaDoc("HttpServletRequest.getReader() method not implemented for MultipartRequest");
730   }
731
732   public ServletInputStream getInputStream() {
733     throw new RuntimeException JavaDoc("HttpServletRequest.getInputStream() method not implemented for MultipartRequest");
734   }
735
736   public void setCharacterEncoding(String JavaDoc sEncoding) {
737     throw new RuntimeException JavaDoc("HttpServletRequest.setCharacterEncoding() method not implemented for MultipartRequest");
738   }
739
740 }
741
742
743 // A class to hold information about an uploaded file.
744
//
745
class UploadedFile {
746
747   private String JavaDoc dir;
748   private String JavaDoc filename;
749   private String JavaDoc original;
750   private String JavaDoc type;
751
752   UploadedFile(String JavaDoc dir, String JavaDoc filename, String JavaDoc original, String JavaDoc type) {
753     this.dir = dir;
754     this.filename = filename;
755     this.original = original;
756     this.type = type;
757   }
758
759   public String JavaDoc getContentType() {
760     return type;
761   }
762
763   public String JavaDoc getFilesystemName() {
764     return filename;
765   }
766
767   public String JavaDoc getOriginalFileName() {
768     return original;
769   }
770
771   public File getFile() {
772     if (dir == null || filename == null) {
773       return null;
774     }
775     else {
776       return new File(dir + File.separator + filename);
777     }
778   }
779
780 }
781
782
Popular Tags