You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by fr...@apache.org on 2008/04/23 09:11:33 UTC
svn commit: r650767 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket:
markup/html/form/ListMultipleChoice.java util/string/StringList.java
util/string/Strings.java util/upload/FileUploadBase.java
util/upload/ParameterParser.java
Author: frankbille
Date: Wed Apr 23 00:11:32 2008
New Revision: 650767
URL: http://svn.apache.org/viewvc?rev=650767&view=rev
Log:
More generics
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListMultipleChoice.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/StringList.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/ParameterParser.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListMultipleChoice.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListMultipleChoice.java?rev=650767&r1=650766&r2=650767&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListMultipleChoice.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListMultipleChoice.java Wed Apr 23 00:11:32 2008
@@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
@@ -196,23 +195,13 @@
@Override
public final String getModelValue()
{
- // Get the list of selected values
- Object modelObject = getModelObject();
- if (modelObject != null && !(modelObject instanceof Collection))
- {
- throw new WicketRuntimeException(
- "Model object for a ListMultipleChoice must be a Collection (found " +
- modelObject.getClass() + ")");
- }
- final Collection<T> selectedValues = (Collection)modelObject;
+ final Collection<T> selectedValues = getModelObject();
final AppendingStringBuffer buffer = new AppendingStringBuffer();
if (selectedValues != null)
{
final List< ? extends T> choices = getChoices();
- for (final Iterator<T> iterator = selectedValues.iterator(); iterator.hasNext();)
+ for (T object : selectedValues)
{
- final T object = iterator.next();
-
int index = choices.indexOf(object);
buffer.append(getChoiceRenderer().getIdValue(object, index));
buffer.append(VALUE_SEPARATOR);
@@ -271,7 +260,7 @@
else
{
// TODO 1.3: check if its safe to return Collections.EMPTY_LIST here
- return new ArrayList();
+ return new ArrayList<T>();
}
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/StringList.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/StringList.java?rev=650767&r1=650766&r2=650767&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/StringList.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/StringList.java Wed Apr 23 00:11:32 2008
@@ -56,7 +56,7 @@
private static final long serialVersionUID = 1L;
// The underlying list of strings
- private final List strings;
+ private final List<String> strings;
// The total length of all strings in the list
private int totalLength;
@@ -124,15 +124,15 @@
* The collection to add as strings
* @return The list
*/
- public static StringList valueOf(final Collection collection)
+ public static StringList valueOf(final Collection< ? > collection)
{
if (collection != null)
{
final StringList strings = new StringList(collection.size());
- for (final Iterator iterator = collection.iterator(); iterator.hasNext();)
+ for (Object object : collection)
{
- strings.add(StringValue.valueOf(iterator.next()));
+ strings.add(StringValue.valueOf(object));
}
return strings;
@@ -209,7 +209,7 @@
*/
public StringList()
{
- this.strings = new ArrayList();
+ strings = new ArrayList<String>();
}
/**
@@ -220,7 +220,7 @@
*/
public StringList(final int size)
{
- this.strings = new ArrayList(size);
+ strings = new ArrayList<String>(size);
}
/**
@@ -280,15 +280,16 @@
* @return The string at the index
* @throws IndexOutOfBoundsException
*/
+ @Override
public String get(final int index)
{
- return (String)strings.get(index);
+ return strings.get(index);
}
/**
* @return List value (not a copy of this list)
*/
- public List getList()
+ public List<String> getList()
{
return strings;
}
@@ -298,11 +299,12 @@
*
* @return Typesafe string iterator
*/
+ @Override
public IStringIterator iterator()
{
return new IStringIterator()
{
- private final Iterator iterator = strings.iterator();
+ private final Iterator<String> iterator = strings.iterator();
public boolean hasNext()
{
@@ -311,7 +313,7 @@
public String next()
{
- return (String)iterator.next();
+ return iterator.next();
}
};
}
@@ -335,7 +337,7 @@
*/
public void remove(final int index)
{
- String string = (String)strings.remove(index);
+ String string = strings.remove(index);
totalLength = totalLength - string.length();
}
@@ -350,6 +352,7 @@
/**
* @return The number of strings in this list.
*/
+ @Override
public int size()
{
return strings.size();
@@ -368,14 +371,16 @@
*
* @return The string array
*/
+ @Override
public String[] toArray()
{
- return (String[])strings.toArray(new String[size()]);
+ return strings.toArray(new String[size()]);
}
/**
* @return The total length of all strings in this list.
*/
+ @Override
public int totalLength()
{
return totalLength;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java?rev=650767&r1=650766&r2=650767&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java Wed Apr 23 00:11:32 2008
@@ -281,7 +281,7 @@
* @return The escaped string
*/
public static CharSequence escapeMarkup(final String s, final boolean escapeSpaces,
- final boolean convertToHtmlUnicodeEscapes)
+ final boolean convertToHtmlUnicodeEscapes)
{
if (s == null)
{
@@ -592,13 +592,13 @@
}
if (s.equalsIgnoreCase("on") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") ||
- s.equalsIgnoreCase("1"))
+ s.equalsIgnoreCase("1"))
{
return true;
}
if (s.equalsIgnoreCase("off") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") ||
- s.equalsIgnoreCase("0"))
+ s.equalsIgnoreCase("0"))
{
return false;
}
@@ -707,7 +707,7 @@
* @return The resulting string with searchFor replaced with replaceWith
*/
public static CharSequence replaceAll(final CharSequence s, final CharSequence searchFor,
- CharSequence replaceWith)
+ CharSequence replaceWith)
{
if (s == null)
{
@@ -815,7 +815,7 @@
{
return new String[0];
}
- final List strings = new ArrayList();
+ final List<String> strings = new ArrayList<String>();
int pos = 0;
while (true)
{
@@ -942,7 +942,7 @@
else
{
throw new StringValueConversionException("Expected single character, not \"" + s +
- "\"");
+ "\"");
}
}
@@ -1138,7 +1138,7 @@
* the location where the component was created or added in the java code.
* @return a string giving the line precise location where the component was added or created.
*/
- public static String toString(final Component component, final Throwable location)
+ public static String toString(final Component< ? > component, final Throwable location)
{
Class componentClass = component.getClass();
@@ -1156,8 +1156,8 @@
// differentiator for the message (e.g. "component foo was ***added***"
// or "component foo was ***created***")
AppendingStringBuffer sb = new AppendingStringBuffer("The " + componentType.toLowerCase() +
- " with id '" + component.getId() + "' that failed to render was " +
- location.getMessage() + "\n");
+ " with id '" + component.getId() + "' that failed to render was " +
+ location.getMessage() + "\n");
// a list of stacktrace elements that need to be skipped in the location
// stack trace
@@ -1221,7 +1221,7 @@
{
if (throwable != null)
{
- ArrayList al = new ArrayList();
+ List<Throwable> al = new ArrayList<Throwable>();
Throwable cause = throwable;
al.add(cause);
while (cause.getCause() != null && cause != cause.getCause())
@@ -1233,7 +1233,7 @@
AppendingStringBuffer sb = new AppendingStringBuffer(256);
// first print the last cause
int length = al.size() - 1;
- cause = (Throwable)al.get(length);
+ cause = al.get(length);
if (throwable instanceof WicketRuntimeException)
{
sb.append("WicketMessage: ");
@@ -1248,7 +1248,7 @@
sb.append("\n\nComplete stack:\n\n");
for (int i = 0; i < length; i++)
{
- outputThrowable((Throwable)al.get(i), sb, true);
+ outputThrowable(al.get(i), sb, true);
sb.append("\n");
}
}
@@ -1287,7 +1287,7 @@
* @param stopAtWicketServlet
*/
private static void outputThrowable(Throwable cause, AppendingStringBuffer sb,
- boolean stopAtWicketServlet)
+ boolean stopAtWicketServlet)
{
sb.append(cause);
sb.append("\n");
@@ -1301,8 +1301,7 @@
sb.append(traceString);
sb.append("\n");
if (stopAtWicketServlet &&
- (traceString.startsWith("org.apache.wicket.protocol.http.WicketServlet") || traceString
- .startsWith("org.apache.wicket.protocol.http.WicketFilter")))
+ (traceString.startsWith("org.apache.wicket.protocol.http.WicketServlet") || traceString.startsWith("org.apache.wicket.protocol.http.WicketFilter")))
{
return;
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java?rev=650767&r1=650766&r2=650767&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/FileUploadBase.java Wed Apr 23 00:11:32 2008
@@ -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:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
* @author <a href="mailto:jvanzyl@apache.org">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,31 +228,31 @@
/**
* 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.
*/
- public List /* FileItem */parseRequest(RequestContext ctx) throws FileUploadException
+ public List<FileItem> parseRequest(RequestContext ctx) throws FileUploadException
{
if (ctx == null)
{
throw new IllegalArgumentException("ctx parameter cannot be null");
}
- ArrayList items = new ArrayList();
+ List<FileItem> items = new ArrayList<FileItem>();
String contentType = ctx.getContentType();
if ((null == contentType) || (!contentType.toLowerCase().startsWith(MULTIPART)))
{
throw new InvalidContentTypeException("the request doesn't contain a " +
- MULTIPART_FORM_DATA + " or " + MULTIPART_MIXED +
- " stream, content type header is " + contentType);
+ MULTIPART_FORM_DATA + " or " + MULTIPART_MIXED +
+ " stream, content type header is " + contentType);
}
int requestSize = ctx.getContentLength();
@@ -264,7 +264,7 @@
if (sizeMax >= 0 && requestSize > sizeMax)
{
throw new SizeLimitExceededException("the request was rejected because "
- + "its size exceeds allowed range");
+ + "its size exceeds allowed range");
}
try
@@ -273,7 +273,7 @@
if (boundary == null)
{
throw new FileUploadException("the request was rejected because "
- + "no multipart boundary was found");
+ + "no multipart boundary was found");
}
InputStream input = ctx.getInputStream();
@@ -288,13 +288,13 @@
final int maxHeaderBytes = 65536;
while (nextPart)
{
- Map headers = parseHeaders(multi.readHeaders(maxHeaderBytes));
+ Map<String, String> headers = parseHeaders(multi.readHeaders(maxHeaderBytes));
String fieldName = getFieldName(headers);
if (fieldName != null)
{
String subContentType = getHeader(headers, CONTENT_TYPE);
if (subContentType != null &&
- subContentType.toLowerCase().startsWith(MULTIPART_MIXED))
+ subContentType.toLowerCase().startsWith(MULTIPART_MIXED))
{
// Multiple files.
byte[] subBoundary = getBoundary(subContentType);
@@ -306,7 +306,7 @@
if (getFileName(headers) != null)
{
FileItem item = createItem(headers, false);
- items.add(item);
+ items.add(item);
OutputStream os = item.getOutputStream();
try
{
@@ -330,7 +330,7 @@
else
{
FileItem item = createItem(headers, getFileName(headers) == null);
- items.add(item);
+ items.add(item);
OutputStream os = item.getOutputStream();
try
{
@@ -352,12 +352,13 @@
}
catch (IOException e)
{
- 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);
+ for (int i = 0; i < items.size(); i++)
+ {
+ FileItem item = items.get(i);
+ item.delete();
+ }
+ throw new FileUploadException("Processing of " + MULTIPART_FORM_DATA +
+ " request failed. " + e.getMessage(), e);
}
return items;
@@ -369,10 +370,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)
@@ -380,8 +381,8 @@
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
- Map params = parser.parse(contentType, ';');
- String boundaryStr = (String)params.get("boundary");
+ Map<String, String> params = parser.parse(contentType, ';');
+ String boundaryStr = params.get("boundary");
if (boundaryStr == null)
{
@@ -402,13 +403,13 @@
/**
* 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)
+ protected String getFileName(Map<String, String> headers)
{
String fileName = null;
String cd = getHeader(headers, CONTENT_DISPOSITION);
@@ -417,10 +418,10 @@
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
- Map params = parser.parse(cd, ';');
+ Map<String, String> params = parser.parse(cd, ';');
if (params.containsKey("filename"))
{
- fileName = (String)params.get("filename");
+ fileName = params.get("filename");
if (fileName != null)
{
fileName = fileName.trim();
@@ -448,13 +449,13 @@
/**
* 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)
+ protected String getFieldName(Map<String, String> headers)
{
String fieldName = null;
String cd = getHeader(headers, CONTENT_DISPOSITION);
@@ -464,8 +465,8 @@
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
- Map params = parser.parse(cd, ';');
- fieldName = (String)params.get("name");
+ Map<String, String> params = parser.parse(cd, ';');
+ fieldName = params.get("name");
if (fieldName != null)
{
fieldName = fieldName.trim();
@@ -477,37 +478,37 @@
/**
* 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.
*/
- protected FileItem createItem(Map /* String, String */headers, boolean isFormField)
+ protected FileItem createItem(Map<String, String> headers, boolean isFormField)
{
return getFileItemFactory().createItem(getFieldName(headers),
- getHeader(headers, CONTENT_TYPE), isFormField, getFileName(headers));
+ getHeader(headers, CONTENT_TYPE), isFormField, getFileName(headers));
}
/**
* <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)
+ protected Map<String, String> parseHeaders(String headerPart)
{
- Map headers = new HashMap();
+ Map<String, String> headers = new HashMap<String, String>();
char[] buffer = new char[MAX_HEADER_SIZE];
boolean done = false;
int j = 0;
@@ -563,18 +564,18 @@
/**
* 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.
*/
- protected final String getHeader(Map /* String, String */headers, String name)
+ protected final String getHeader(Map<String, String> headers, String name)
{
- return (String)headers.get(name.toLowerCase());
+ return headers.get(name.toLowerCase());
}
@@ -597,7 +598,7 @@
/**
* Constructs an <code>InvalidContentTypeException</code> with the specified detail
* message.
- *
+ *
* @param message
* The detail message.
*/
@@ -626,7 +627,7 @@
/**
* Constructs an <code>UnknownSizeException</code> with the specified detail message.
- *
+ *
* @param message
* The detail message.
*/
@@ -655,7 +656,7 @@
/**
* Constructs an <code>SizeExceededException</code> with the specified detail message.
- *
+ *
* @param message
* The detail message.
*/
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/ParameterParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/ParameterParser.java?rev=650767&r1=650766&r2=650767&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/ParameterParser.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/upload/ParameterParser.java Wed Apr 23 00:11:32 2008
@@ -241,11 +241,11 @@
*
* @return a map of name/value pairs
*/
- public Map parse(final String str, char separator)
+ public Map<String, String> parse(final String str, char separator)
{
if (str == null)
{
- return new HashMap();
+ return new HashMap<String, String>();
}
return parse(str.toCharArray(), separator);
}
@@ -261,11 +261,11 @@
*
* @return a map of name/value pairs
*/
- public Map parse(final char[] chars, char separator)
+ public Map<String, String> parse(final char[] chars, char separator)
{
if (chars == null)
{
- return new HashMap();
+ return new HashMap<String, String>();
}
return parse(chars, 0, chars.length, separator);
}
@@ -285,14 +285,14 @@
*
* @return a map of name/value pairs
*/
- public Map parse(final char[] chars, int offset, int length, char separator)
+ public Map<String, String> parse(final char[] chars, int offset, int length, char separator)
{
if (chars == null)
{
- return new HashMap();
+ return new HashMap<String, String>();
}
- HashMap params = new HashMap();
+ Map<String, String> params = new HashMap<String, String>();
this.chars = chars;
pos = offset;
len = length;