1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.fileupload.servlet;
17
18 import java.util.List;
19 import javax.servlet.http.HttpServletRequest;
20 import org.apache.commons.fileupload.FileItemFactory;
21 import org.apache.commons.fileupload.FileUpload;
22 import org.apache.commons.fileupload.FileUploadException;
23
24 /***
25 * <p>High level API for processing file uploads.</p>
26 *
27 * <p>This class handles multiple files per single HTML widget, sent using
28 * <code>multipart/mixed</code> encoding type, as specified by
29 * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
30 * #parseRequest(HttpServletRequest)} to acquire a list of {@link
31 * org.apache.commons.fileupload.FileItem}s associated with a given HTML
32 * widget.</p>
33 *
34 * <p>How the data for individual parts is stored is determined by the factory
35 * used to create them; a given part may be in memory, on disk, or somewhere
36 * else.</p>
37 *
38 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
39 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
40 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
41 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
42 * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
43 * @author Sean C. Sullivan
44 *
45 * @version $Id: ServletFileUpload.java 350090 2005-12-01 00:56:20Z martinc $
46 */
47 public class ServletFileUpload extends FileUpload {
48
49
50
51
52 /***
53 * Utility method that determines whether the request contains multipart
54 * content.
55 *
56 * @param req The servlet request to be evaluated. Must be non-null.
57 *
58 * @return <code>true</code> if the request is multipart;
59 * <code>false</code> otherwise.
60 */
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 /***
77 * Constructs an uninitialised instance of this class. A factory must be
78 * configured, using <code>setFileItemFactory()</code>, before attempting
79 * to parse requests.
80 *
81 * @see FileUpload#FileUpload(FileItemFactory)
82 */
83 public ServletFileUpload() {
84 super();
85 }
86
87
88 /***
89 * Constructs an instance of this class which uses the supplied factory to
90 * create <code>FileItem</code> instances.
91 *
92 * @see FileUpload#FileUpload()
93 */
94 public ServletFileUpload(FileItemFactory fileItemFactory) {
95 super(fileItemFactory);
96 }
97
98
99
100
101
102 /***
103 * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
104 * compliant <code>multipart/form-data</code> stream.
105 *
106 * @param request The servlet request to be parsed.
107 *
108 * @return A list of <code>FileItem</code> instances parsed from the
109 * request, in the order that they were transmitted.
110 *
111 * @throws FileUploadException if there are problems reading/parsing
112 * the request or storing files.
113 */
114 public List
115 throws FileUploadException {
116 return parseRequest(new ServletRequestContext(request));
117 }
118 }