Added: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ProgressListener.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ProgressListener.java?rev=942052&view=auto ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ProgressListener.java (added) +++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ProgressListener.java Fri May 7 11:29:36 2010 @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.upload; + + +/** + * The {...@link ProgressListener} may be used to display a progress bar or do stuff like that. + */ +public interface ProgressListener +{ + /** + * Updates the listeners status information. + * + * @param pBytesRead + * The total number of bytes, which have been read so far. + * @param pContentLength + * The total number of bytes, which are being read. May be -1, if this number is + * unknown. + * @param pItems + * The number of the field, which is currently being read. (0 = no item so far, 1 = + * first item is being read, ...) + */ + void update(long pBytesRead, long pContentLength, int pItems); +}
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/RequestContext.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/RequestContext.java?rev=942052&r1=942051&r2=942052&view=diff ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/RequestContext.java (original) +++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/RequestContext.java Fri May 7 11:29:36 2010 @@ -21,7 +21,7 @@ import java.io.InputStream; /** * <p> - * Abstracts access to the request information needed for file uploads. This interface should be + * Abstracts access to the request information needed for file uploads. This interfsace should be * implemented for each type of request that may be handled by FileUpload, such as servlets and * portlets. * </p> @@ -32,6 +32,13 @@ public interface RequestContext { /** + * Retrieve the character encoding for the request. + * + * @return The character encoding for the request. + */ + String getCharacterEncoding(); + + /** * Retrieve the content type of the request. * * @return The content type of the request. Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java?rev=942052&r1=942051&r2=942052&view=diff ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java (original) +++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java Fri May 7 11:29:36 2010 @@ -16,11 +16,11 @@ */ package org.apache.wicket.util.upload; +import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletRequest; - /** * <p> * High level API for processing file uploads. @@ -65,7 +65,16 @@ public class ServletFileUpload extends F { return false; } - return FileUploadBase.isMultipartContent(new ServletRequestContext(request)); + String contentType = request.getContentType(); + if (contentType == null) + { + return false; + } + if (contentType.toLowerCase().startsWith(MULTIPART)) + { + return true; + } + return false; } @@ -73,8 +82,10 @@ public class ServletFileUpload extends F /** - * Constructs an uninitialized instance of this class. A factory must be configured, using + * Constructs an uninitialised instance of this class. A factory must be configured, using * <code>setFileItemFactory()</code>, before attempting to parse requests. + * + * @see FileUpload#FileUpload(FileItemFactory) */ public ServletFileUpload() { @@ -86,7 +97,9 @@ public class ServletFileUpload extends F * Constructs an instance of this class which uses the supplied factory to create * <code>FileItem</code> instances. * + * @see FileUpload#FileUpload() * @param fileItemFactory + * The factory to use for creating file items. */ public ServletFileUpload(FileItemFactory fileItemFactory) { @@ -107,11 +120,35 @@ public class ServletFileUpload extends F * @return A list of <code>FileItem</code> instances parsed from the request, in the order that * they were transmitted. * - * @exception FileUploadException - * if there are problems reading/parsing the request or storing files. + * @throws FileUploadException + * if there are problems reading/parsing the request or storing files. */ + @Override public List<FileItem> parseRequest(HttpServletRequest request) throws FileUploadException { return parseRequest(new ServletRequestContext(request)); } + + + /** + * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> compliant + * <code>multipart/form-data</code> stream. + * + * @param request + * The servlet request to be parsed. + * + * @return An iterator to instances of <code>FileItemStream</code> parsed from the request, in + * the order that they were transmitted. + * + * @throws FileUploadException + * if there are problems reading/parsing the request or storing files. + * @throws IOException + * An I/O error occurred. This may be a network error while communicating with the + * client or a problem while storing the uploaded content. + */ + public FileItemIterator getItemIterator(HttpServletRequest request) throws FileUploadException, + IOException + { + return super.getItemIterator(new ServletRequestContext(request)); + } } Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletRequestContext.java URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletRequestContext.java?rev=942052&r1=942051&r2=942052&view=diff ============================================================================== --- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletRequestContext.java (original) +++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/upload/ServletRequestContext.java Fri May 7 11:29:36 2010 @@ -21,7 +21,6 @@ import java.io.InputStream; import javax.servlet.http.HttpServletRequest; - /** * <p> * Provides access to the request information needed for a request made to an HTTP servlet. @@ -57,6 +56,16 @@ public class ServletRequestContext imple // --------------------------------------------------------- Public Methods /** + * Retrieve the character encoding for the request. + * + * @return The character encoding for the request. + */ + public String getCharacterEncoding() + { + return request.getCharacterEncoding(); + } + + /** * Retrieve the content type of the request. * * @return The content type of the request. @@ -95,7 +104,6 @@ public class ServletRequestContext imple @Override public String toString() { - return "ContentLength=" + this.getContentLength() + ", ContentType=" + - this.getContentType(); + return "ContentLength=" + getContentLength() + ", ContentType=" + getContentType(); } }
