// Put a valid UploadedFile instance into the map that contains all of the
// uploaded file's attributes, along with a successful status.
Map<String, Object> attributeMap = new HashMap<String, Object>();
String id = Long.toString(((long) hashCode()) + System.currentTimeMillis());
String message = null;
UploadedFile uploadedFile = uploadedFileFactory.getUploadedFile(copiedFileAbsolutePath,
attributeMap, diskFileItem.getCharSet(), diskFileItem.getContentType(),
headersMap, id, message, fileName, diskFileItem.getSize(),
UploadedFile.Status.FILE_SAVED);
facesRequestParameterMap.addValue(fieldName, copiedFileAbsolutePath);
addUploadedFile(uploadedFileMap, fieldName, uploadedFile);
logger.debug("Received uploaded file fieldName=[{0}] fileName=[{1}]", fieldName,
fileName);
}
else {
if ((fileName != null) && (fileName.trim().length() > 0)) {
Exception e = new IOException("Failed to copy the stream of uploaded file=[" +
fileName + "] to a temporary file (possibly a zero-length uploaded file)");
UploadedFile uploadedFile = uploadedFileFactory.getUploadedFile(e);
addUploadedFile(uploadedFileMap, fieldName, uploadedFile);
}
}
}
}
catch (Exception e) {
logger.error(e);
UploadedFile uploadedFile = uploadedFileFactory.getUploadedFile(e);
String fieldName = Integer.toString(totalFiles);
addUploadedFile(uploadedFileMap, fieldName, uploadedFile);
}
}
}
}
// If there was an error in parsing the request for file parts, then put a bogus UploadedFile instance in
// the map so that the developer can have some idea that something went wrong.
catch (Exception e) {
logger.error(e);
UploadedFile uploadedFile = uploadedFileFactory.getUploadedFile(e);
addUploadedFile(uploadedFileMap, "unknown", uploadedFile);
}
return uploadedFileMap;
}