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