Author: jcompagner
Date: Sun Dec 16 09:47:09 2007
New Revision: 604663

URL: http://svn.apache.org/viewvc?rev=604663&view=rev
Log:
WICKET-1230

Modified:
    
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java

Modified: 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java?rev=604663&r1=604662&r2=604663&view=diff
==============================================================================
--- 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
 (original)
+++ 
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
 Sun Dec 16 09:47:09 2007
@@ -30,16 +30,16 @@
  * <p>
  * High level API for processing file uploads.
  * </p>
- * 
+ *
  * <p>
  * This class handles multiple files per single HTML widget, sent using 
<code>multipart/mixed</code>
  * encoding type, as specified by <a 
href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>.
- * 
+ *
  * <p>
  * How the data for individual parts is stored is determined by the factory 
used to create them; a
  * given part may be in memory, on disk, or somewhere else.
  * </p>
- * 
+ *
  * @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
@@ -57,16 +57,16 @@
         * <p>
         * Utility method that determines whether the request contains 
multipart content.
         * </p>
-        * 
+        *
         * <p>
         * <strong>NOTE:</strong>This method will be moved to the 
<code>ServletFileUpload</code>
         * class after the FileUpload 1.1 release. Unfortunately, since this 
method is static, it is not
         * possible to provide its replacement until this method is removed.
         * </p>
-        * 
+        *
         * @param ctx
         *            The request context to be evaluated. Must be non-null.
-        * 
+        *
         * @return <code>true</code> if the request is multipart; 
<code>false</code> otherwise.
         */
        public static final boolean isMultipartContent(RequestContext ctx)
@@ -154,7 +154,7 @@
 
        /**
         * Returns the factory class used when creating file items.
-        * 
+        *
         * @return The factory class for new file items.
         */
        public abstract FileItemFactory getFileItemFactory();
@@ -162,7 +162,7 @@
 
        /**
         * Sets the factory class to use when creating file items.
-        * 
+        *
         * @param factory
         *            The factory class for new file items.
         */
@@ -171,11 +171,11 @@
 
        /**
         * Returns the maximum allowed upload size.
-        * 
+        *
         * @return The maximum allowed size, in bytes.
-        * 
+        *
         * @see #setSizeMax(long)
-        * 
+        *
         */
        public long getSizeMax()
        {
@@ -185,12 +185,12 @@
 
        /**
         * Sets the maximum allowed upload size. If negative, there is no 
maximum.
-        * 
+        *
         * @param sizeMax
         *            The maximum allowed size, in bytes, or -1 for no maximum.
-        * 
+        *
         * @see #getSizeMax()
-        * 
+        *
         */
        public void setSizeMax(long sizeMax)
        {
@@ -201,7 +201,7 @@
        /**
         * Retrieves the character encoding used when reading the headers of an 
individual part. When
         * not specified, or <code>null</code>, the platform default encoding 
is used.
-        * 
+        *
         * @return The encoding used to read part headers.
         */
        public String getHeaderEncoding()
@@ -213,7 +213,7 @@
        /**
         * Specifies the character encoding to be used when reading the headers 
of individual parts.
         * When not specified, or <code>null</code>, the platform default 
encoding is used.
-        * 
+        *
         * @param encoding
         *            The encoding used to read part headers.
         */
@@ -228,13 +228,13 @@
        /**
         * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 
1867</a> compliant
         * <code>multipart/form-data</code> stream.
-        * 
+        *
         * @param ctx
         *            The context for the request to be parsed.
-        * 
+        *
         * @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.
         */
@@ -306,6 +306,7 @@
                                                        if 
(getFileName(headers) != null)
                                                        {
                                                                FileItem item = 
createItem(headers, false);
+                                items.add(item);
                                                                OutputStream os 
= item.getOutputStream();
                                                                try
                                                                {
@@ -315,7 +316,6 @@
                                                                {
                                                                        
os.close();
                                                                }
-                                                               items.add(item);
                                                        }
                                                        else
                                                        {
@@ -330,6 +330,7 @@
                                        else
                                        {
                                                FileItem item = 
createItem(headers, getFileName(headers) == null);
+                        items.add(item);
                                                OutputStream os = 
item.getOutputStream();
                                                try
                                                {
@@ -339,7 +340,6 @@
                                                {
                                                        os.close();
                                                }
-                                               items.add(item);
                                        }
                                }
                                else
@@ -352,7 +352,11 @@
                }
                catch (IOException e)
                {
-                       throw new FileUploadException("Processing of " + 
MULTIPART_FORM_DATA +
+            for(int i=0;i<items.size();i++) {
+                FileItem item = (FileItem)items.get(i);
+                item.delete();
+            }
+            throw new FileUploadException("Processing of " + 
MULTIPART_FORM_DATA +
                                        " request failed. " + e.getMessage(), 
e);
                }
 
@@ -365,10 +369,10 @@
 
        /**
         * Retrieves the boundary from the <code>Content-type</code> header.
-        * 
+        *
         * @param contentType
         *            The value of the content type header from which to 
extract the boundary value.
-        * 
+        *
         * @return The boundary, as a byte array.
         */
        protected byte[] getBoundary(String contentType)
@@ -398,10 +402,10 @@
 
        /**
         * Retrieves the file name from the <code>Content-disposition</code> 
header.
-        * 
+        *
         * @param headers
         *            A <code>Map</code> containing the HTTP request headers.
-        * 
+        *
         * @return The file name for the current <code>encapsulation</code>.
         */
        protected String getFileName(Map /* String, String */headers)
@@ -444,10 +448,10 @@
 
        /**
         * Retrieves the field name from the <code>Content-disposition</code> 
header.
-        * 
+        *
         * @param headers
         *            A <code>Map</code> containing the HTTP request headers.
-        * 
+        *
         * @return The field name for the current <code>encapsulation</code>.
         */
        protected String getFieldName(Map /* String, String */headers)
@@ -473,12 +477,12 @@
 
        /**
         * Creates a new [EMAIL PROTECTED] FileItem} instance.
-        * 
+        *
         * @param headers
         *            A <code>Map</code> containing the HTTP request headers.
         * @param isFormField
         *            Whether or not this item is a form field, as opposed to a 
file.
-        * 
+        *
         * @return A newly created <code>FileItem</code> instance.
         */
        protected FileItem createItem(Map /* String, String */headers, boolean 
isFormField)
@@ -491,14 +495,14 @@
        /**
         * <p>
         * Parses the <code>header-part</code> and returns as key/value pairs.
-        * 
+        *
         * <p>
         * If there are multiple headers of the same names, the name will map 
to a comma-separated list
         * containing the values.
-        * 
+        *
         * @param headerPart
         *            The <code>header-part</code> of the current 
<code>encapsulation</code>.
-        * 
+        *
         * @return A <code>Map</code> containing the parsed HTTP request 
headers.
         */
        protected Map /* String, String */parseHeaders(String headerPart)
@@ -559,12 +563,12 @@
        /**
         * Returns the header with the specified name from the supplied map. 
The header lookup is
         * case-insensitive.
-        * 
+        *
         * @param headers
         *            A <code>Map</code> containing the HTTP request headers.
         * @param name
         *            The name of the header to return.
-        * 
+        *
         * @return The value of specified header, or a comma-separated list if 
there were multiple
         *         headers of that name.
         */
@@ -593,7 +597,7 @@
                /**
                 * Constructs an <code>InvalidContentTypeException</code> with 
the specified detail
                 * message.
-                * 
+                *
                 * @param message
                 *            The detail message.
                 */
@@ -622,7 +626,7 @@
 
                /**
                 * Constructs an <code>UnknownSizeException</code> with the 
specified detail message.
-                * 
+                *
                 * @param message
                 *            The detail message.
                 */
@@ -651,7 +655,7 @@
 
                /**
                 * Constructs an <code>SizeExceededException</code> with the 
specified detail message.
-                * 
+                *
                 * @param message
                 *            The detail message.
                 */


Reply via email to