NIHVIVO-160 Add getFileItem()
This commit is contained in:
parent
3646092f4d
commit
77f9fd2d30
3 changed files with 40 additions and 1 deletions
|
@ -19,7 +19,6 @@ import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
import org.apache.commons.fileupload.FileUploadException;
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
|
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
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.
|
// New functionality to be implemented by the subclasses.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Was this a multipart HTTP request? */
|
||||||
public abstract boolean isMultipart();
|
public abstract boolean isMultipart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the map of file items, by name.
|
||||||
|
*/
|
||||||
public abstract Map<String, List<FileItem>> getFiles();
|
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.
|
// Delegated methods.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -133,6 +133,29 @@ class MultipartHttpServletRequest extends FileUploadServletRequest {
|
||||||
return files;
|
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,
|
// Parameter-related methods won't find anything on the delegate request,
|
||||||
// since parsing consumed the parameters. So we need to look to the parsed
|
// since parsing consumed the parameters. So we need to look to the parsed
|
||||||
|
|
|
@ -36,6 +36,11 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileItem getFileItem(String string) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Since this is not a multipart request, the parameter methods can be
|
// Since this is not a multipart request, the parameter methods can be
|
||||||
// delegated.
|
// delegated.
|
||||||
|
|
Loading…
Add table
Reference in a new issue