NIHVIVO-160 make the map of FileItems available as an attribute as well as through a method call. That way, if the request is wrapped in a VitroRequest, the map is still accessible.

This commit is contained in:
jeb228 2010-06-07 18:43:40 +00:00
parent 9237b7bd41
commit cbda9a16cc
3 changed files with 13 additions and 1 deletions

View file

@ -27,6 +27,14 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
* request parameters.
* </p>
* <p>
* The request will have an attribute named by {@link #FILE_ITEM_MAP}. Either
* this attribute or the call to {@link #getFiles()} will produce a map that may
* be empty but is never null. The keys to the map are the field names for the
* file fields. Since a form may have multiple fields with the same name, each
* field name maps to a list of items. If a user does not provide a file to be
* uploaded in a given field, the length of the file will be 0.
* </p>
* <p>
* Most methods are declared here, and simply delegate to the wrapped request.
* Methods that have to do with parameters or files are handled differently for
* simple requests and multipart request, and are implemented in the
@ -35,6 +43,8 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
*/
@SuppressWarnings("deprecation")
public abstract class FileUploadServletRequest implements HttpServletRequest {
public static final String FILE_ITEM_MAP = "file_item_map";
// ----------------------------------------------------------------------
// The factory method
// ----------------------------------------------------------------------

View file

@ -69,6 +69,7 @@ class MultipartHttpServletRequest extends FileUploadServletRequest {
LOG.debug("Parameters are: " + this.parameters);
this.files = Collections.unmodifiableMap(files);
LOG.debug("Files are: " + this.files);
request.setAttribute(FILE_ITEM_MAP, this.files);
}
/**

View file

@ -20,6 +20,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
SimpleHttpServletRequestWrapper(HttpServletRequest request) {
super(request);
request.setAttribute(FILE_ITEM_MAP, Collections.EMPTY_MAP);
}
// ----------------------------------------------------------------------
@ -35,7 +36,7 @@ class SimpleHttpServletRequestWrapper extends FileUploadServletRequest {
public Map<String, List<FileItem>> getFiles() {
return Collections.emptyMap();
}
@Override
public FileItem getFileItem(String string) {
return null;