KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > web > fileupload > servlet > ServletFileUpload


1 /*
2  * Copyright 2001-2005 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.myvietnam.mvncore.web.fileupload.servlet;
17
18 import java.util.List JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import net.myvietnam.mvncore.web.fileupload.FileItemFactory;
21 import net.myvietnam.mvncore.web.fileupload.FileUpload;
22 import net.myvietnam.mvncore.web.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,v 1.2 2006/02/12 04:43:11 minhnn Exp $
46  */

47 public class ServletFileUpload extends FileUpload {
48
49     // ---------------------------------------------------------- Class methods
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     //NOTE: This method cannot be enabled until the one in FileUploadBase is
62
// removed, since it is not possible to override a static method.
63
//public static final boolean isMultipartContent(
64
// HttpServletRequest request) {
65
// if (!"post".equals(request.getMethod().toLowerCase())) {
66
// return false;
67
// }
68
// return FileUploadBase.isMultipartContent(
69
// new ServletRequestContext(request));
70
//}
71

72
73     // ----------------------------------------------------------- Constructors
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     // --------------------------------------------------------- Public methods
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 JavaDoc /* FileItem */ parseRequest(HttpServletRequest JavaDoc request)
115             throws FileUploadException {
116         return parseRequest(new ServletRequestContext(request));
117     }
118 }
119
Popular Tags