KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > util > legacy > commons > fileupload > DiskFileUpload


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;
17
18 import java.io.File JavaDoc;
19 import java.util.List JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 /**
24  * <p>High level API for processing file uploads.</p>
25  *
26  * <p>This class handles multiple files per single HTML widget, sent using
27  * <code>multipart/mixed</code> encoding type, as specified by
28  * <a HREF="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
29  * #parseRequest(HttpServletRequest)} to acquire a list of {@link
30  * org.apache.commons.fileupload.FileItem}s associated with a given HTML
31  * widget.</p>
32  *
33  * <p>Individual parts will be stored in temporary disk storage or in memory,
34  * depending on their size, and will be available as {@link
35  * org.apache.commons.fileupload.FileItem}s.</p>
36  *
37  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
38  * @author <a HREF="mailto:dlr@collab.net">Daniel Rall</a>
39  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
40  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
41  * @author <a HREF="mailto:martinc@apache.org">Martin Cooper</a>
42  * @author Sean C. Sullivan
43  *
44  * @version $Id: DiskFileUpload.java,v 1.4 2005/07/26 04:01:16 diegopires Exp $
45  *
46  * @deprecated Use <code>ServletFileUpload</code> together with
47  * <code>DiskFileItemFactory</code> instead.
48  */

49 public class DiskFileUpload
50     extends FileUploadBase {
51
52     // ----------------------------------------------------------- Data members
53

54
55     /**
56      * The factory to use to create new form items.
57      */

58     private DefaultFileItemFactory fileItemFactory;
59
60
61     // ----------------------------------------------------------- Constructors
62

63
64     /**
65      * Constructs an instance of this class which uses the default factory to
66      * create <code>FileItem</code> instances.
67      *
68      * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
69      *
70      * @deprecated Use <code>FileUpload</code> instead.
71      */

72     public DiskFileUpload() {
73         super();
74         this.fileItemFactory = new DefaultFileItemFactory();
75     }
76
77
78     /**
79      * Constructs an instance of this class which uses the supplied factory to
80      * create <code>FileItem</code> instances.
81      *
82      * @see #DiskFileUpload()
83      *
84      * @deprecated Use <code>FileUpload</code> instead.
85      */

86     public DiskFileUpload(DefaultFileItemFactory fileItemFactory) {
87         super();
88         this.fileItemFactory = fileItemFactory;
89     }
90
91
92     // ----------------------------------------------------- Property accessors
93

94
95     /**
96      * Returns the factory class used when creating file items.
97      *
98      * @return The factory class for new file items.
99      *
100      * @deprecated Use <code>FileUpload</code> instead.
101      */

102     public FileItemFactory getFileItemFactory() {
103         return fileItemFactory;
104     }
105
106
107     /**
108      * Sets the factory class to use when creating file items. The factory must
109      * be an instance of <code>DefaultFileItemFactory</code> or a subclass
110      * thereof, or else a <code>ClassCastException</code> will be thrown.
111      *
112      * @param factory The factory class for new file items.
113      *
114      * @deprecated Use <code>FileUpload</code> instead.
115      */

116     public void setFileItemFactory(FileItemFactory factory) {
117         this.fileItemFactory = (DefaultFileItemFactory) factory;
118     }
119
120
121     /**
122      * Returns the size threshold beyond which files are written directly to
123      * disk.
124      *
125      * @return The size threshold, in bytes.
126      *
127      * @see #setSizeThreshold(int)
128      *
129      * @deprecated Use <code>DiskFileItemFactory</code> instead.
130      */

131     public int getSizeThreshold() {
132         return fileItemFactory.getSizeThreshold();
133     }
134
135
136     /**
137      * Sets the size threshold beyond which files are written directly to disk.
138      *
139      * @param sizeThreshold The size threshold, in bytes.
140      *
141      * @see #getSizeThreshold()
142      *
143      * @deprecated Use <code>DiskFileItemFactory</code> instead.
144      */

145     public void setSizeThreshold(int sizeThreshold) {
146         fileItemFactory.setSizeThreshold(sizeThreshold);
147     }
148
149
150     /**
151      * Returns the location used to temporarily store files that are larger
152      * than the configured size threshold.
153      *
154      * @return The path to the temporary file location.
155      *
156      * @see #setRepositoryPath(String)
157      *
158      * @deprecated Use <code>DiskFileItemFactory</code> instead.
159      */

160     public String JavaDoc getRepositoryPath() {
161         return fileItemFactory.getRepository().getPath();
162     }
163
164
165     /**
166      * Sets the location used to temporarily store files that are larger
167      * than the configured size threshold.
168      *
169      * @param repositoryPath The path to the temporary file location.
170      *
171      * @see #getRepositoryPath()
172      *
173      * @deprecated Use <code>DiskFileItemFactory</code> instead.
174      */

175     public void setRepositoryPath(String JavaDoc repositoryPath) {
176         fileItemFactory.setRepository(new File JavaDoc(repositoryPath));
177     }
178
179
180     // --------------------------------------------------------- Public methods
181

182
183     /**
184      * Processes an <a HREF="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
185      * compliant <code>multipart/form-data</code> stream. If files are stored
186      * on disk, the path is given by <code>getRepository()</code>.
187      *
188      * @param req The servlet request to be parsed. Must be non-null.
189      * @param sizeThreshold The max size in bytes to be stored in memory.
190      * @param sizeMax The maximum allowed upload size, in bytes.
191      * @param path The location where the files should be stored.
192      *
193      * @return A list of <code>FileItem</code> instances parsed from the
194      * request, in the order that they were transmitted.
195      *
196      * @exception FileUploadException if there are problems reading/parsing
197      * the request or storing files.
198      *
199      * @deprecated Use <code>ServletFileUpload</code> instead.
200      */

201     public List JavaDoc /* FileItem */ parseRequest(HttpServletRequest JavaDoc req,
202                                             int sizeThreshold,
203                                             long sizeMax, String JavaDoc path)
204         throws FileUploadException {
205         setSizeThreshold(sizeThreshold);
206         setSizeMax(sizeMax);
207         setRepositoryPath(path);
208         return parseRequest(req);
209     }
210
211 }
212
Popular Tags