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.portlet;
018:
019: import java.io.IOException;
020: import java.util.List;
021:
022: import javax.portlet.ActionRequest;
023:
024: import org.apache.commons.fileupload.FileItemFactory;
025: import org.apache.commons.fileupload.FileItemIterator;
026: import org.apache.commons.fileupload.FileUpload;
027: import org.apache.commons.fileupload.FileUploadBase;
028: import org.apache.commons.fileupload.FileUploadException;
029:
030: /**
031: * <p>High level API for processing file uploads.</p>
032: *
033: * <p>This class handles multiple files per single HTML widget, sent using
034: * <code>multipart/mixed</code> encoding type, as specified by
035: * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
036: * #parseRequest(javax.servlet.http.HttpServletRequest)} to acquire a list
037: * of {@link org.apache.commons.fileupload.FileItem FileItems} associated
038: * with a given HTML widget.</p>
039: *
040: * <p>How the data for individual parts is stored is determined by the factory
041: * used to create them; a given part may be in memory, on disk, or somewhere
042: * else.</p>
043: *
044: * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
045: * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
046: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
047: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
048: * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
049: * @author Sean C. Sullivan
050: *
051: * @since FileUpload 1.1
052: *
053: * @version $Id: PortletFileUpload.java 479484 2006-11-27 01:06:53Z jochen $
054: */
055: public class PortletFileUpload extends FileUpload {
056:
057: // ---------------------------------------------------------- Class methods
058:
059: /**
060: * Utility method that determines whether the request contains multipart
061: * content.
062: *
063: * @param request The portlet request to be evaluated. Must be non-null.
064: *
065: * @return <code>true</code> if the request is multipart;
066: * <code>false</code> otherwise.
067: */
068: public static final boolean isMultipartContent(ActionRequest request) {
069: return FileUploadBase
070: .isMultipartContent(new PortletRequestContext(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#FileUpload(FileItemFactory)
081: */
082: public PortletFileUpload() {
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#FileUpload()
091: * @param fileItemFactory The factory to use for creating file items.
092: */
093: public PortletFileUpload(FileItemFactory fileItemFactory) {
094: super (fileItemFactory);
095: }
096:
097: // --------------------------------------------------------- Public methods
098:
099: /**
100: * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
101: * compliant <code>multipart/form-data</code> stream.
102: *
103: * @param request The portlet request to be parsed.
104: *
105: * @return A list of <code>FileItem</code> instances parsed from the
106: * request, in the order that they were transmitted.
107: *
108: * @throws FileUploadException if there are problems reading/parsing
109: * the request or storing files.
110: */
111: public List /* FileItem */parseRequest(ActionRequest request)
112: throws FileUploadException {
113: return parseRequest(new PortletRequestContext(request));
114: }
115:
116: /**
117: * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
118: * compliant <code>multipart/form-data</code> stream.
119: *
120: * @param request The portlet request to be parsed.
121: *
122: * @return An iterator to instances of <code>FileItemStream</code>
123: * parsed from the request, in the order that they were
124: * transmitted.
125: *
126: * @throws FileUploadException if there are problems reading/parsing
127: * the request or storing files.
128: * @throws IOException An I/O error occurred. This may be a network
129: * error while communicating with the client or a problem while
130: * storing the uploaded content.
131: */
132: public FileItemIterator getItemIterator(ActionRequest request)
133: throws FileUploadException, IOException {
134: return super
135: .getItemIterator(new PortletRequestContext(request));
136: }
137: }
|