KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > util > legacy > commons > fileupload > servlet > ServletFileUpload


1 /*
2  * Copyright 2001-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 net.jforum.util.legacy.commons.fileupload.servlet;
17
18 import java.util.List JavaDoc;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21
22 import net.jforum.util.legacy.commons.fileupload.FileItemFactory;
23 import net.jforum.util.legacy.commons.fileupload.FileUpload;
24 import net.jforum.util.legacy.commons.fileupload.FileUploadException;
25
26 /**
27  * <p>High level API for processing file uploads.</p>
28  *
29  * <p>This class handles multiple files per single HTML widget, sent using
30  * <code>multipart/mixed</code> encoding type, as specified by
31  * <a HREF="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
32  * #parseRequest(HttpServletRequest)} to acquire a list of {@link
33  * org.apache.commons.fileupload.FileItem}s associated with a given HTML
34  * widget.</p>
35  *
36  * <p>How the data for individual parts is stored is determined by the factory
37  * used to create them; a given part may be in memory, on disk, or somewhere
38  * else.</p>
39  *
40  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
41  * @author <a HREF="mailto:dlr@collab.net">Daniel Rall</a>
42  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
43  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
44  * @author <a HREF="mailto:martinc@apache.org">Martin Cooper</a>
45  * @author Sean C. Sullivan
46  *
47  * @version $Id: ServletFileUpload.java,v 1.3 2005/07/26 03:06:05 rafaelsteil Exp $
48  */

49 public class ServletFileUpload extends FileUpload {
50
51     // ---------------------------------------------------------- Class methods
52

53
54     /**
55      * Utility method that determines whether the request contains multipart
56      * content.
57      *
58      * @param req The servlet request to be evaluated. Must be non-null.
59      *
60      * @return <code>true</code> if the request is multipart;
61      * <code>false</code> otherwise.
62      */

63     //NOTE: This method cannot be enabled until the one in FileUploadBase is
64
// removed, since it is not possible to override a static method.
65
//public static final boolean isMultipartContent(
66
// HttpServletRequest request) {
67
// if (!"post".equals(request.getMethod().toLowerCase())) {
68
// return false;
69
// }
70
// return FileUploadBase.isMultipartContent(
71
// new ServletRequestContext(request));
72
//}
73

74
75     // ----------------------------------------------------------- Constructors
76

77
78     /**
79      * Constructs an uninitialised instance of this class. A factory must be
80      * configured, using <code>setFileItemFactory()</code>, before attempting
81      * to parse requests.
82      *
83      * @see #FileUpload(FileItemFactory)
84      */

85     public ServletFileUpload() {
86         super();
87     }
88
89
90     /**
91      * Constructs an instance of this class which uses the supplied factory to
92      * create <code>FileItem</code> instances.
93      *
94      * @see #FileUpload()
95      */

96     public ServletFileUpload(FileItemFactory fileItemFactory) {
97         super(fileItemFactory);
98     }
99
100
101     // --------------------------------------------------------- Public methods
102

103
104     /**
105      * Processes an <a HREF="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
106      * compliant <code>multipart/form-data</code> stream.
107      *
108      * @param request The servlet request to be parsed.
109      *
110      * @return A list of <code>FileItem</code> instances parsed from the
111      * request, in the order that they were transmitted.
112      *
113      * @exception FileUploadException if there are problems reading/parsing
114      * the request or storing files.
115      */

116     public List JavaDoc /* FileItem */ parseRequest(HttpServletRequest JavaDoc request)
117             throws FileUploadException {
118         return parseRequest(new ServletRequestContext(request));
119     }
120 }
121
Popular Tags