001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.fileupload;
018:
019: import java.io.File;
020: import java.util.List;
021: import javax.servlet.http.HttpServletRequest;
022:
023: /**
024: * <p>High level API for processing file uploads.</p>
025: *
026: * <p>This class handles multiple files per single HTML widget, sent using
027: * <code>multipart/mixed</code> encoding type, as specified by
028: * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
029: * #parseRequest(HttpServletRequest)} to acquire a list of {@link
030: * org.apache.commons.fileupload.FileItem}s associated with a given HTML
031: * widget.</p>
032: *
033: * <p>Individual parts will be stored in temporary disk storage or in memory,
034: * depending on their size, and will be available as {@link
035: * org.apache.commons.fileupload.FileItem}s.</p>
036: *
037: * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
038: * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
039: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
040: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
041: * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
042: * @author Sean C. Sullivan
043: *
044: * @version $Id: DiskFileUpload.java 479484 2006-11-27 01:06:53Z jochen $
045: *
046: * @deprecated Use <code>ServletFileUpload</code> together with
047: * <code>DiskFileItemFactory</code> instead.
048: */
049: public class DiskFileUpload extends FileUploadBase {
050:
051: // ----------------------------------------------------------- Data members
052:
053: /**
054: * The factory to use to create new form items.
055: */
056: private DefaultFileItemFactory fileItemFactory;
057:
058: // ----------------------------------------------------------- Constructors
059:
060: /**
061: * Constructs an instance of this class which uses the default factory to
062: * create <code>FileItem</code> instances.
063: *
064: * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
065: *
066: * @deprecated Use <code>FileUpload</code> instead.
067: */
068: public DiskFileUpload() {
069: super ();
070: this .fileItemFactory = new DefaultFileItemFactory();
071: }
072:
073: /**
074: * Constructs an instance of this class which uses the supplied factory to
075: * create <code>FileItem</code> instances.
076: *
077: * @see #DiskFileUpload()
078: * @param fileItemFactory The file item factory to use.
079: *
080: * @deprecated Use <code>FileUpload</code> instead.
081: */
082: public DiskFileUpload(DefaultFileItemFactory fileItemFactory) {
083: super ();
084: this .fileItemFactory = fileItemFactory;
085: }
086:
087: // ----------------------------------------------------- Property accessors
088:
089: /**
090: * Returns the factory class used when creating file items.
091: *
092: * @return The factory class for new file items.
093: *
094: * @deprecated Use <code>FileUpload</code> instead.
095: */
096: public FileItemFactory getFileItemFactory() {
097: return fileItemFactory;
098: }
099:
100: /**
101: * Sets the factory class to use when creating file items. The factory must
102: * be an instance of <code>DefaultFileItemFactory</code> or a subclass
103: * thereof, or else a <code>ClassCastException</code> will be thrown.
104: *
105: * @param factory The factory class for new file items.
106: *
107: * @deprecated Use <code>FileUpload</code> instead.
108: */
109: public void setFileItemFactory(FileItemFactory factory) {
110: this .fileItemFactory = (DefaultFileItemFactory) factory;
111: }
112:
113: /**
114: * Returns the size threshold beyond which files are written directly to
115: * disk.
116: *
117: * @return The size threshold, in bytes.
118: *
119: * @see #setSizeThreshold(int)
120: *
121: * @deprecated Use <code>DiskFileItemFactory</code> instead.
122: */
123: public int getSizeThreshold() {
124: return fileItemFactory.getSizeThreshold();
125: }
126:
127: /**
128: * Sets the size threshold beyond which files are written directly to disk.
129: *
130: * @param sizeThreshold The size threshold, in bytes.
131: *
132: * @see #getSizeThreshold()
133: *
134: * @deprecated Use <code>DiskFileItemFactory</code> instead.
135: */
136: public void setSizeThreshold(int sizeThreshold) {
137: fileItemFactory.setSizeThreshold(sizeThreshold);
138: }
139:
140: /**
141: * Returns the location used to temporarily store files that are larger
142: * than the configured size threshold.
143: *
144: * @return The path to the temporary file location.
145: *
146: * @see #setRepositoryPath(String)
147: *
148: * @deprecated Use <code>DiskFileItemFactory</code> instead.
149: */
150: public String getRepositoryPath() {
151: return fileItemFactory.getRepository().getPath();
152: }
153:
154: /**
155: * Sets the location used to temporarily store files that are larger
156: * than the configured size threshold.
157: *
158: * @param repositoryPath The path to the temporary file location.
159: *
160: * @see #getRepositoryPath()
161: *
162: * @deprecated Use <code>DiskFileItemFactory</code> instead.
163: */
164: public void setRepositoryPath(String repositoryPath) {
165: fileItemFactory.setRepository(new File(repositoryPath));
166: }
167:
168: // --------------------------------------------------------- Public methods
169:
170: /**
171: * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
172: * compliant <code>multipart/form-data</code> stream. If files are stored
173: * on disk, the path is given by <code>getRepository()</code>.
174: *
175: * @param req The servlet request to be parsed. Must be non-null.
176: * @param sizeThreshold The max size in bytes to be stored in memory.
177: * @param sizeMax The maximum allowed upload size, in bytes.
178: * @param path The location where the files should be stored.
179: *
180: * @return A list of <code>FileItem</code> instances parsed from the
181: * request, in the order that they were transmitted.
182: *
183: * @throws FileUploadException if there are problems reading/parsing
184: * the request or storing files.
185: *
186: * @deprecated Use <code>ServletFileUpload</code> instead.
187: */
188: public List /* FileItem */parseRequest(HttpServletRequest req,
189: int sizeThreshold, long sizeMax, String path)
190: throws FileUploadException {
191: setSizeThreshold(sizeThreshold);
192: setSizeMax(sizeMax);
193: setRepositoryPath(path);
194: return parseRequest(req);
195: }
196:
197: }
|