You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2011/04/23 09:34:22 UTC

svn commit: r1096116 - in /wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload: FileItemHeaders.java FileItemHeadersImpl.java FileUploadBase.java ServletFileUpload.java

Author: jdonnerstag
Date: Sat Apr 23 07:34:22 2011
New Revision: 1096116

URL: http://svn.apache.org/viewvc?rev=1096116&view=rev
Log:
WICKET-3624 
fixed: Remove many Eclipse warnings in wicket-util 

Modified:
    wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeaders.java
    wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeadersImpl.java
    wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
    wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java

Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeaders.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeaders.java?rev=1096116&r1=1096115&r2=1096116&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeaders.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeaders.java Sat Apr 23 07:34:22 2011
@@ -56,7 +56,7 @@ public interface FileItemHeaders
 	 * @return an <code>Enumeration</code> containing the values of the requested header. If the
 	 *         item does not have any headers of that name, return an empty <code>Enumeration</code>
 	 */
-	Iterator getHeaders(String name);
+	Iterator<String> getHeaders(String name);
 
 	/**
 	 * <p>
@@ -70,5 +70,5 @@ public interface FileItemHeaders
 	 * @return an <code>Enumeration</code> containing the values of the requested header. If the
 	 *         item does not have any headers of that name return an empty <code>Enumeration</code>
 	 */
-	Iterator getHeaderNames();
+	Iterator<String> getHeaderNames();
 }

Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeadersImpl.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeadersImpl.java?rev=1096116&r1=1096115&r2=1096116&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeadersImpl.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileItemHeadersImpl.java Sat Apr 23 07:34:22 2011
@@ -17,13 +17,13 @@
 package org.apache.wicket.util.upload;
 
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.wicket.util.lang.Generics;
+
 /**
  * Default implementation of the {@link FileItemHeaders} interface.
  * 
@@ -37,37 +37,37 @@ public class FileItemHeadersImpl impleme
 	/**
 	 * Map of <code>String</code> keys to a <code>List</code> of <code>String</code> instances.
 	 */
-	private final Map headerNameToValueListMap = new HashMap();
+	private final Map<String, List<String>> headerNameToValueListMap = Generics.newHashMap();
 
 	/**
 	 * List to preserve order of headers as added. This would not be needed if a
 	 * <code>LinkedHashMap</code> could be used, but don't want to depend on 1.4.
 	 */
-	private final List headerNameList = new ArrayList();
+	private final List<String> headerNameList = Generics.newArrayList();
 
 	public String getHeader(final String name)
 	{
 		String nameLower = name.toLowerCase();
-		List headerValueList = (List)headerNameToValueListMap.get(nameLower);
+		List<String> headerValueList = headerNameToValueListMap.get(nameLower);
 		if (null == headerValueList)
 		{
 			return null;
 		}
-		return (String)headerValueList.get(0);
+		return headerValueList.get(0);
 	}
 
-	public Iterator getHeaderNames()
+	public Iterator<String> getHeaderNames()
 	{
 		return headerNameList.iterator();
 	}
 
-	public Iterator getHeaders(final String name)
+	public Iterator<String> getHeaders(final String name)
 	{
 		String nameLower = name.toLowerCase();
-		List headerValueList = (List)headerNameToValueListMap.get(nameLower);
+		List<String> headerValueList = headerNameToValueListMap.get(nameLower);
 		if (null == headerValueList)
 		{
-			return Collections.EMPTY_LIST.iterator();
+			headerValueList = Collections.emptyList();
 		}
 		return headerValueList.iterator();
 	}
@@ -83,10 +83,10 @@ public class FileItemHeadersImpl impleme
 	public synchronized void addHeader(final String name, final String value)
 	{
 		String nameLower = name.toLowerCase();
-		List headerValueList = (List)headerNameToValueListMap.get(nameLower);
+		List<String> headerValueList = headerNameToValueListMap.get(nameLower);
 		if (null == headerValueList)
 		{
-			headerValueList = new ArrayList();
+			headerValueList = Generics.newArrayList();
 			headerNameToValueListMap.put(nameLower, headerValueList);
 			headerNameList.add(nameLower);
 		}

Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java?rev=1096116&r1=1096115&r2=1096116&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java Sat Apr 23 07:34:22 2011
@@ -19,9 +19,6 @@ package org.apache.wicket.util.upload;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -29,6 +26,8 @@ import java.util.NoSuchElementException;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.wicket.util.io.Streams;
+import org.apache.wicket.util.lang.Args;
+import org.apache.wicket.util.lang.Generics;
 import org.apache.wicket.util.upload.MultipartFormInputStream.ItemInputStream;
 
 /**
@@ -57,10 +56,8 @@ import org.apache.wicket.util.upload.Mul
  */
 public abstract class FileUploadBase
 {
-
 	// ---------------------------------------------------------- Class methods
 
-
 	/**
 	 * <p>
 	 * Utility method that determines whether the request contains multipart content.
@@ -87,32 +84,13 @@ public abstract class FileUploadBase
 		return contentType.toLowerCase().startsWith(MULTIPART);
 	}
 
-	/**
-	 * Utility method that determines whether the request contains multipart content.
-	 * 
-	 * @param req
-	 *            The servlet request to be evaluated. Must be non-null.
-	 * 
-	 * @return <code>true</code> if the request is multipart; <code>false</code> otherwise.
-	 * 
-	 * @deprecated Use the method on <code>ServletFileUpload</code> instead.
-	 */
-	@Deprecated
-	public static boolean isMultipartContent(final HttpServletRequest req)
-	{
-		return ServletFileUpload.isMultipartContent(req);
-	}
-
-
 	// ----------------------------------------------------- Manifest constants
 
-
 	/**
 	 * HTTP content type header name.
 	 */
 	public static final String CONTENT_TYPE = "Content-type";
 
-
 	/**
 	 * HTTP content disposition header name.
 	 */
@@ -123,51 +101,33 @@ public abstract class FileUploadBase
 	 */
 	public static final String CONTENT_LENGTH = "Content-length";
 
-
 	/**
 	 * Content-disposition value for form data.
 	 */
 	public static final String FORM_DATA = "form-data";
 
-
 	/**
 	 * Content-disposition value for file attachment.
 	 */
 	public static final String ATTACHMENT = "attachment";
 
-
 	/**
 	 * Part of HTTP content type header.
 	 */
 	public static final String MULTIPART = "multipart/";
 
-
 	/**
 	 * HTTP content type header for multipart forms.
 	 */
 	public static final String MULTIPART_FORM_DATA = "multipart/form-data";
 
-
 	/**
 	 * HTTP content type header for multiple uploads.
 	 */
 	public static final String MULTIPART_MIXED = "multipart/mixed";
 
-
-	/**
-	 * The maximum length of a single header line that will be parsed (1024 bytes).
-	 * 
-	 * @deprecated This constant is no longer used. As of commons-fileupload 1.2, the only
-	 *             applicable limit is the total size of a parts headers,
-	 *             {@link MultipartStream#HEADER_PART_SIZE_MAX}.
-	 */
-	@Deprecated
-	public static final int MAX_HEADER_SIZE = 1024;
-
-
 	// ----------------------------------------------------------- Data members
 
-
 	/**
 	 * The maximum size permitted for the complete request, as opposed to {@link #fileSizeMax}. A
 	 * value of -1 indicates no maximum.
@@ -192,7 +152,6 @@ public abstract class FileUploadBase
 
 	// ----------------------------------------------------- Property accessors
 
-
 	/**
 	 * Returns the factory class used when creating file items.
 	 * 
@@ -200,7 +159,6 @@ public abstract class FileUploadBase
 	 */
 	public abstract FileItemFactory getFileItemFactory();
 
-
 	/**
 	 * Sets the factory class to use when creating file items.
 	 * 
@@ -209,7 +167,6 @@ public abstract class FileUploadBase
 	 */
 	public abstract void setFileItemFactory(FileItemFactory factory);
 
-
 	/**
 	 * Returns the maximum allowed size of a complete request, as opposed to
 	 * {@link #getFileSizeMax()}.
@@ -225,7 +182,6 @@ public abstract class FileUploadBase
 		return sizeMax;
 	}
 
-
 	/**
 	 * Sets the maximum allowed size of a complete request, as opposed to
 	 * {@link #setFileSizeMax(long)}.
@@ -278,7 +234,6 @@ public abstract class FileUploadBase
 		return headerEncoding;
 	}
 
-
 	/**
 	 * Specifies the character encoding to be used when reading the headers of individual part. When
 	 * not specified, or <code>null</code>, the request encoding is used. If that is also not
@@ -292,31 +247,8 @@ public abstract class FileUploadBase
 		headerEncoding = encoding;
 	}
 
-
 	// --------------------------------------------------------- Public methods
 
-
-	/**
-	 * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> compliant
-	 * <code>multipart/form-data</code> stream.
-	 * 
-	 * @param req
-	 *            The servlet request to be parsed.
-	 * 
-	 * @return A list of <code>FileItem</code> instances parsed from the request, in the order that
-	 *         they were transmitted.
-	 * 
-	 * @throws FileUploadException
-	 *             if there are problems reading/parsing the request or storing files.
-	 * 
-	 * @deprecated Use the method in <code>ServletFileUpload</code> instead.
-	 */
-	@Deprecated
-	public List<FileItem> parseRequest(final HttpServletRequest req) throws FileUploadException
-	{
-		return parseRequest(new ServletRequestContext(req));
-	}
-
 	/**
 	 * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> compliant
 	 * <code>multipart/form-data</code> stream.
@@ -357,7 +289,7 @@ public abstract class FileUploadBase
 		try
 		{
 			FileItemIterator iter = getItemIterator(ctx);
-			List<FileItem> items = new ArrayList<FileItem>();
+			List<FileItem> items = Generics.newArrayList();
 			FileItemFactory fac = getFileItemFactory();
 			if (fac == null)
 			{
@@ -436,22 +368,6 @@ public abstract class FileUploadBase
 		return boundary;
 	}
 
-
-	/**
-	 * 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>.
-	 * @deprecated Use {@link #getFileName(FileItemHeaders)}.
-	 */
-	@Deprecated
-	protected String getFileName(final Map<String, String> headers)
-	{
-		return getFileName(getHeader(headers, CONTENT_DISPOSITION));
-	}
-
 	/**
 	 * Retrieves the file name from the <code>Content-disposition</code> header.
 	 * 
@@ -545,45 +461,6 @@ public abstract class FileUploadBase
 	}
 
 	/**
-	 * 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>.
-	 * @deprecated Use {@link #getFieldName(FileItemHeaders)}.
-	 */
-	@Deprecated
-	protected String getFieldName(final Map<String, String> headers)
-	{
-		return getFieldName(getHeader(headers, CONTENT_DISPOSITION));
-	}
-
-
-	/**
-	 * Creates a new {@link 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.
-	 * 
-	 * @throws FileUploadException
-	 *             if an error occurs.
-	 * @deprecated This method is no longer used in favour of internally created instances of
-	 *             {@link FileItem}.
-	 */
-	@Deprecated
-	protected FileItem createItem(final Map<String, String> headers, final boolean isFormField)
-		throws FileUploadException
-	{
-		return getFileItemFactory().createItem(getFieldName(headers),
-			getHeader(headers, CONTENT_TYPE), isFormField, getFileName(headers));
-	}
-
-	/**
 	 * <p>
 	 * Parses the <code>header-part</code> and returns as key/value pairs.
 	 * 
@@ -647,39 +524,6 @@ public abstract class FileUploadBase
 	}
 
 	/**
-	 * <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.
-	 * @deprecated Use {@link #getParsedHeaders(String)}
-	 */
-	@Deprecated
-	protected Map /* String, String */parseHeaders(final String headerPart)
-	{
-		FileItemHeaders headers = getParsedHeaders(headerPart);
-		Map result = new HashMap();
-		for (Iterator iter = headers.getHeaderNames(); iter.hasNext();)
-		{
-			String headerName = (String)iter.next();
-			Iterator iter2 = headers.getHeaders(headerName);
-			StringBuilder headerValue = new StringBuilder((String)iter2.next());
-			while (iter2.hasNext())
-			{
-				headerValue.append(',').append(iter2.next());
-			}
-			result.put(headerName, headerValue.toString());
-		}
-		return result;
-	}
-
-	/**
 	 * Skips bytes until the end of the current line.
 	 * 
 	 * @param headerPart
@@ -729,25 +573,6 @@ public abstract class FileUploadBase
 	}
 
 	/**
-	 * 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.
-	 * @deprecated Use {@link FileItemHeaders#getHeader(String)}.
-	 */
-	@Deprecated
-	protected final String getHeader(final Map<String, String> headers, final String name)
-	{
-		return headers.get(name.toLowerCase());
-	}
-
-	/**
 	 * The iterator, which is returned by {@link FileUploadBase#getItemIterator(RequestContext)}.
 	 */
 	private class FileItemIteratorImpl implements FileItemIterator
@@ -976,10 +801,7 @@ public abstract class FileUploadBase
 		 */
 		FileItemIteratorImpl(final RequestContext ctx) throws FileUploadException, IOException
 		{
-			if (ctx == null)
-			{
-				throw new NullPointerException("ctx parameter");
-			}
+			Args.notNull(ctx, "ctx");
 
 			String contentType = ctx.getContentType();
 			if ((null == contentType) || (!contentType.toLowerCase().startsWith(MULTIPART)))
@@ -1353,41 +1175,6 @@ public abstract class FileUploadBase
 	}
 
 	/**
-	 * Thrown to indicate that the request size is not specified. In other words, it is thrown, if
-	 * the content-length header is missing or contains the value -1.
-	 * 
-	 * @deprecated As of commons-fileupload 1.2, the presence of a content-length header is no
-	 *             longer required.
-	 */
-	@Deprecated
-	public static class UnknownSizeException extends FileUploadException
-	{
-		/**
-		 * The exceptions UID, for serializing an instance.
-		 */
-		private static final long serialVersionUID = 7062279004812015273L;
-
-		/**
-		 * Constructs a <code>UnknownSizeException</code> with no detail message.
-		 */
-		public UnknownSizeException()
-		{
-			super();
-		}
-
-		/**
-		 * Constructs an <code>UnknownSizeException</code> with the specified detail message.
-		 * 
-		 * @param message
-		 *            The detail message.
-		 */
-		public UnknownSizeException(final String message)
-		{
-			super(message);
-		}
-	}
-
-	/**
 	 * Thrown to indicate that the request size exceeds the configured maximum.
 	 */
 	public static class SizeLimitExceededException extends SizeException
@@ -1398,26 +1185,6 @@ public abstract class FileUploadBase
 		private static final long serialVersionUID = -2474893167098052828L;
 
 		/**
-		 * @deprecated Replaced by {@link #SizeLimitExceededException(String, long, long)}
-		 */
-		@Deprecated
-		public SizeLimitExceededException()
-		{
-			this(null, 0, 0);
-		}
-
-		/**
-		 * @deprecated Replaced by {@link #SizeLimitExceededException(String, long, long)}
-		 * @param message
-		 *            The exceptions detail message.
-		 */
-		@Deprecated
-		public SizeLimitExceededException(final String message)
-		{
-			this(message, 0, 0);
-		}
-
-		/**
 		 * Constructs a <code>SizeExceededException</code> with the specified detail message, and
 		 * actual and permitted sizes.
 		 * 

Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java?rev=1096116&r1=1096115&r2=1096116&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/upload/ServletFileUpload.java Sat Apr 23 07:34:22 2011
@@ -123,7 +123,6 @@ public class ServletFileUpload extends F
 	 * @throws FileUploadException
 	 *             if there are problems reading/parsing the request or storing files.
 	 */
-	@Override
 	public List<FileItem> parseRequest(final HttpServletRequest request) throws FileUploadException
 	{
 		return parseRequest(new ServletRequestContext(request));