001: /*
002: * Copyright 2001-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package net.jforum.util.legacy.commons.fileupload;
017:
018: import java.io.File;
019: import java.util.List;
020:
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,v 1.4 2005/07/26 04:01:16 diegopires Exp $
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: *
079: * @deprecated Use <code>FileUpload</code> instead.
080: */
081: public DiskFileUpload(DefaultFileItemFactory fileItemFactory) {
082: super ();
083: this .fileItemFactory = fileItemFactory;
084: }
085:
086: // ----------------------------------------------------- Property accessors
087:
088: /**
089: * Returns the factory class used when creating file items.
090: *
091: * @return The factory class for new file items.
092: *
093: * @deprecated Use <code>FileUpload</code> instead.
094: */
095: public FileItemFactory getFileItemFactory() {
096: return fileItemFactory;
097: }
098:
099: /**
100: * Sets the factory class to use when creating file items. The factory must
101: * be an instance of <code>DefaultFileItemFactory</code> or a subclass
102: * thereof, or else a <code>ClassCastException</code> will be thrown.
103: *
104: * @param factory The factory class for new file items.
105: *
106: * @deprecated Use <code>FileUpload</code> instead.
107: */
108: public void setFileItemFactory(FileItemFactory factory) {
109: this .fileItemFactory = (DefaultFileItemFactory) factory;
110: }
111:
112: /**
113: * Returns the size threshold beyond which files are written directly to
114: * disk.
115: *
116: * @return The size threshold, in bytes.
117: *
118: * @see #setSizeThreshold(int)
119: *
120: * @deprecated Use <code>DiskFileItemFactory</code> instead.
121: */
122: public int getSizeThreshold() {
123: return fileItemFactory.getSizeThreshold();
124: }
125:
126: /**
127: * Sets the size threshold beyond which files are written directly to disk.
128: *
129: * @param sizeThreshold The size threshold, in bytes.
130: *
131: * @see #getSizeThreshold()
132: *
133: * @deprecated Use <code>DiskFileItemFactory</code> instead.
134: */
135: public void setSizeThreshold(int sizeThreshold) {
136: fileItemFactory.setSizeThreshold(sizeThreshold);
137: }
138:
139: /**
140: * Returns the location used to temporarily store files that are larger
141: * than the configured size threshold.
142: *
143: * @return The path to the temporary file location.
144: *
145: * @see #setRepositoryPath(String)
146: *
147: * @deprecated Use <code>DiskFileItemFactory</code> instead.
148: */
149: public String getRepositoryPath() {
150: return fileItemFactory.getRepository().getPath();
151: }
152:
153: /**
154: * Sets the location used to temporarily store files that are larger
155: * than the configured size threshold.
156: *
157: * @param repositoryPath The path to the temporary file location.
158: *
159: * @see #getRepositoryPath()
160: *
161: * @deprecated Use <code>DiskFileItemFactory</code> instead.
162: */
163: public void setRepositoryPath(String repositoryPath) {
164: fileItemFactory.setRepository(new File(repositoryPath));
165: }
166:
167: // --------------------------------------------------------- Public methods
168:
169: /**
170: * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
171: * compliant <code>multipart/form-data</code> stream. If files are stored
172: * on disk, the path is given by <code>getRepository()</code>.
173: *
174: * @param req The servlet request to be parsed. Must be non-null.
175: * @param sizeThreshold The max size in bytes to be stored in memory.
176: * @param sizeMax The maximum allowed upload size, in bytes.
177: * @param path The location where the files should be stored.
178: *
179: * @return A list of <code>FileItem</code> instances parsed from the
180: * request, in the order that they were transmitted.
181: *
182: * @exception FileUploadException if there are problems reading/parsing
183: * the request or storing files.
184: *
185: * @deprecated Use <code>ServletFileUpload</code> instead.
186: */
187: public List /* FileItem */parseRequest(HttpServletRequest req,
188: int sizeThreshold, long sizeMax, String path)
189: throws FileUploadException {
190: setSizeThreshold(sizeThreshold);
191: setSizeMax(sizeMax);
192: setRepositoryPath(path);
193: return parseRequest(req);
194: }
195:
196: }
|