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.servlet;
017:
018: import java.util.List;
019:
020: import javax.servlet.http.HttpServletRequest;
021:
022: import net.jforum.util.legacy.commons.fileupload.FileItemFactory;
023: import net.jforum.util.legacy.commons.fileupload.FileUpload;
024: import net.jforum.util.legacy.commons.fileupload.FileUploadException;
025:
026: /**
027: * <p>High level API for processing file uploads.</p>
028: *
029: * <p>This class handles multiple files per single HTML widget, sent using
030: * <code>multipart/mixed</code> encoding type, as specified by
031: * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
032: * #parseRequest(HttpServletRequest)} to acquire a list of {@link
033: * org.apache.commons.fileupload.FileItem}s associated with a given HTML
034: * widget.</p>
035: *
036: * <p>How the data for individual parts is stored is determined by the factory
037: * used to create them; a given part may be in memory, on disk, or somewhere
038: * else.</p>
039: *
040: * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
041: * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
042: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
043: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
044: * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
045: * @author Sean C. Sullivan
046: *
047: * @version $Id: ServletFileUpload.java,v 1.3 2005/07/26 03:06:05 rafaelsteil Exp $
048: */
049: public class ServletFileUpload extends FileUpload {
050:
051: // ---------------------------------------------------------- Class methods
052:
053: /**
054: * Utility method that determines whether the request contains multipart
055: * content.
056: *
057: * @param req The servlet request to be evaluated. Must be non-null.
058: *
059: * @return <code>true</code> if the request is multipart;
060: * <code>false</code> otherwise.
061: */
062: //NOTE: This method cannot be enabled until the one in FileUploadBase is
063: // removed, since it is not possible to override a static method.
064: //public static final boolean isMultipartContent(
065: // HttpServletRequest request) {
066: // if (!"post".equals(request.getMethod().toLowerCase())) {
067: // return false;
068: // }
069: // return FileUploadBase.isMultipartContent(
070: // new ServletRequestContext(request));
071: //}
072:
073: // ----------------------------------------------------------- Constructors
074:
075: /**
076: * Constructs an uninitialised instance of this class. A factory must be
077: * configured, using <code>setFileItemFactory()</code>, before attempting
078: * to parse requests.
079: *
080: * @see #FileUpload(FileItemFactory)
081: */
082: public ServletFileUpload() {
083: super ();
084: }
085:
086: /**
087: * Constructs an instance of this class which uses the supplied factory to
088: * create <code>FileItem</code> instances.
089: *
090: * @see #FileUpload()
091: */
092: public ServletFileUpload(FileItemFactory fileItemFactory) {
093: super (fileItemFactory);
094: }
095:
096: // --------------------------------------------------------- Public methods
097:
098: /**
099: * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
100: * compliant <code>multipart/form-data</code> stream.
101: *
102: * @param request The servlet request to be parsed.
103: *
104: * @return A list of <code>FileItem</code> instances parsed from the
105: * request, in the order that they were transmitted.
106: *
107: * @exception FileUploadException if there are problems reading/parsing
108: * the request or storing files.
109: */
110: public List /* FileItem */parseRequest(HttpServletRequest request)
111: throws FileUploadException {
112: return parseRequest(new ServletRequestContext(request));
113: }
114: }
|