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