View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.fileupload.portlet;
17  
18  import java.util.List;
19  import javax.portlet.ActionRequest;
20  import org.apache.commons.fileupload.FileItemFactory;
21  import org.apache.commons.fileupload.FileUpload;
22  import org.apache.commons.fileupload.FileUploadBase;
23  import org.apache.commons.fileupload.FileUploadException;
24  
25  /***
26   * <p>High level API for processing file uploads.</p>
27   *
28   * <p>This class handles multiple files per single HTML widget, sent using
29   * <code>multipart/mixed</code> encoding type, as specified by
30   * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Use {@link
31   * #parseRequest(HttpServletRequest)} to acquire a list of {@link
32   * org.apache.commons.fileupload.FileItem}s associated with a given HTML
33   * widget.</p>
34   *
35   * <p>How the data for individual parts is stored is determined by the factory
36   * used to create them; a given part may be in memory, on disk, or somewhere
37   * else.</p>
38   *
39   * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
40   * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
41   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
42   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
43   * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
44   * @author Sean C. Sullivan
45   *
46   * @since FileUpload 1.1
47   *
48   * @version $Id: PortletFileUpload.java 350090 2005-12-01 00:56:20Z martinc $
49   */
50  public class PortletFileUpload extends FileUpload {
51  
52      // ---------------------------------------------------------- Class methods
53  
54  
55      /***
56       * Utility method that determines whether the request contains multipart
57       * content.
58       *
59       * @param request The portlet request to be evaluated. Must be non-null.
60       *
61       * @return <code>true</code> if the request is multipart;
62       *         <code>false</code> otherwise.
63       */
64      public static final boolean isMultipartContent(ActionRequest request) {
65          return FileUploadBase.isMultipartContent(
66                  new PortletRequestContext(request));
67      }
68  
69  
70      // ----------------------------------------------------------- Constructors
71  
72  
73      /***
74       * Constructs an uninitialised instance of this class. A factory must be
75       * configured, using <code>setFileItemFactory()</code>, before attempting
76       * to parse requests.
77       *
78       * @see FileUpload#FileUpload(FileItemFactory)
79       */
80      public PortletFileUpload() {
81          super();
82      }
83  
84  
85      /***
86       * Constructs an instance of this class which uses the supplied factory to
87       * create <code>FileItem</code> instances.
88       *
89       * @see FileUpload#FileUpload()
90       */
91      public PortletFileUpload(FileItemFactory fileItemFactory) {
92          super(fileItemFactory);
93      }
94  
95  
96      // --------------------------------------------------------- Public methods
97  
98  
99      /***
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 }