NIHVIVO-160 Add getFileItem()

This commit is contained in:
jeb228 2010-06-01 16:49:49 +00:00
parent 3646092f4d
commit 77f9fd2d30
3 changed files with 40 additions and 1 deletions

View file

@ -19,7 +19,6 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
/**
@ -71,10 +70,22 @@ public abstract class FileUploadServletRequest implements HttpServletRequest {
// New functionality to be implemented by the subclasses.
// ----------------------------------------------------------------------
/** Was this a multipart HTTP request? */
public abstract boolean isMultipart();
/**
* Get the map of file items, by name.
*/
public abstract Map<String, List<FileItem>> getFiles();
/**
* Find a non-empty file item with this name.
*
* @return the first such file item, or <code>null</code> if no matching,
* non-empty items were found.
*/
public abstract FileItem getFileItem(String string);
// ----------------------------------------------------------------------
// Delegated methods.
// ----------------------------------------------------------------------

View file

@ -133,6 +133,29 @@ class MultipartHttpServletRequest extends FileUploadServletRequest {
return files;
}
/**
* {@inheritDoc}
* <p>
* There may be more than one file item with the given name. If the first
* one is empty (size is zero), keep looking for a non-empty one.
* </p>
*/
@Override
public FileItem getFileItem(String name) {
List<FileItem> items = files.get(name);
if (items == null) {
return null;
}
for (FileItem item : items) {
if (item.getSize() > 0L) {
return item;
}
}
return null;
}
// ----------------------------------------------------------------------
// Parameter-related methods won't find anything on the delegate request,
// since parsing consumed the parameters. So we need to look to the parsed

View file

@ -35,6 +35,11 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
public Map<String, List<FileItem>> getFiles() {
return Collections.emptyMap();
}
@Override
public FileItem getFileItem(String string) {
return null;
}
// ----------------------------------------------------------------------
// Since this is not a multipart request, the parameter methods can be