use of org.apache.struts.upload.CommonsMultipartRequestHandler in project cu-kfs by CU-CommunityApps.
the class WebUtils method getMultipartParameters.
public static void getMultipartParameters(HttpServletRequest request, ActionServletWrapper servletWrapper, ActionForm form, ActionMapping mapping) {
Map params = new HashMap();
try {
CommonsMultipartRequestHandler multipartHandler = new CommonsMultipartRequestHandler();
if (multipartHandler != null) {
// Set servlet and mapping info
if (servletWrapper != null) {
// from pojoformbase
// servlet only affects tempdir on local disk
servletWrapper.setServletFor(multipartHandler);
}
multipartHandler.setMapping((ActionMapping) request.getAttribute(Globals.MAPPING_KEY));
// Initialize multipart request class handler
multipartHandler.handleRequest(request);
Collection<FormFile> files = multipartHandler.getFileElements().values();
Enumeration keys = multipartHandler.getFileElements().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
FormFile file = (FormFile) multipartHandler.getFileElements().get(key);
long maxSize = WebUtils.getMaxUploadSize(form);
if (LOG.isDebugEnabled()) {
LOG.debug(file.getFileSize());
}
if (maxSize > 0 && Long.parseLong(file.getFileSize() + "") > maxSize) {
GlobalVariables.getMessageMap().putError(key.toString(), RiceKeyConstants.ERROR_UPLOADFILE_SIZE, new String[] { file.getFileName(), Long.toString(maxSize) });
}
}
// get file elements for kualirequestprocessor
if (servletWrapper == null) {
request.setAttribute(KRADConstants.UPLOADED_FILE_REQUEST_ATTRIBUTE_KEY, getFileParametersForMultipartRequest(request, multipartHandler));
}
}
} catch (ServletException e) {
throw new ValidationException("unable to handle multipart request " + e.getMessage(), e);
}
}
Aggregations