Search in sources :

Example 1 with CommonsMultipartRequestHandler

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) Enumeration(java.util.Enumeration) ValidationException(org.kuali.kfs.krad.exception.ValidationException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CommonsMultipartRequestHandler(org.apache.struts.upload.CommonsMultipartRequestHandler) FormFile(org.apache.struts.upload.FormFile)

Aggregations

Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 CommonsMultipartRequestHandler (org.apache.struts.upload.CommonsMultipartRequestHandler)1 FormFile (org.apache.struts.upload.FormFile)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1