Search in sources :

Example 1 with MultipartRequestWrapper

use of org.apache.struts.upload.MultipartRequestWrapper in project cu-kfs by CU-CommunityApps.

the class WebUtils method getFileParametersForMultipartRequest.

private static Map getFileParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
    Map parameters = new HashMap();
    Hashtable elements = multipartHandler.getFileElements();
    Enumeration e = elements.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        parameters.put(key, elements.get(key));
    }
    if (request instanceof MultipartRequestWrapper) {
        request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
        e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            parameters.put(key, request.getParameterValues(key));
        }
    } else {
        LOG.debug("Gathering multipart parameters for unwrapped request");
    }
    return parameters;
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Hashtable(java.util.Hashtable) MultipartRequestWrapper(org.apache.struts.upload.MultipartRequestWrapper) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with MultipartRequestWrapper

use of org.apache.struts.upload.MultipartRequestWrapper in project sonarqube by SonarSource.

the class RequestUtils method getAllParametersForMultipartRequest.

/**
     * <p>Create a <code>Map</code> containing all of the parameters supplied
     * for a multipart request, keyed by parameter name. In addition to text
     * and file elements from the multipart body, query string parameters are
     * included as well.</p>
     *
     * @param request          The (wrapped) HTTP request whose parameters are
     *                         to be added to the map.
     * @param multipartHandler The multipart handler used to parse the
     *                         request.
     * @return the map containing all parameters for this multipart request.
     */
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
    Map parameters = new HashMap();
    Hashtable elements = multipartHandler.getAllElements();
    Enumeration e = elements.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        parameters.put(key, elements.get(key));
    }
    if (request instanceof MultipartRequestWrapper) {
        request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
        e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            parameters.put(key, request.getParameterValues(key));
        }
    } else {
        log.debug("Gathering multipart parameters for unwrapped request");
    }
    return parameters;
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) MultipartRequestWrapper(org.apache.struts.upload.MultipartRequestWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with MultipartRequestWrapper

use of org.apache.struts.upload.MultipartRequestWrapper in project jaffa-framework by jaffa-projects.

the class CustomRequestProcessor method getAllParametersForMultipartRequest.

/**
 *<p>Create a <code>Map</code> containing all of the parameters supplied for a multipart
 * request, keyed by parameter name. In addition to text and file elements
 * from the multipart body, query string parameters are included as well.</p>
 *
 * @param request The (wrapped) HTTP request whose parameters are to be
 *                added to the map.
 * @param multipartHandler The multipart handler used to parse the request.
 *
 * @return the map containing all parameters for this multipart request.
 */
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
    Map parameters = new HashMap();
    Hashtable elements = multipartHandler.getAllElements();
    Enumeration e = elements.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        parameters.put(key, elements.get(key));
    }
    if (request instanceof MultipartRequestWrapper) {
        request = ((MultipartRequestWrapper) request).getRequest();
        e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            parameters.put(key, request.getParameterValues(key));
        }
    } else {
        log.debug("Gathering multipart parameters for unwrapped request");
    }
    return parameters;
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) MultipartRequestWrapper(org.apache.struts.upload.MultipartRequestWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MultipartRequestWrapper

use of org.apache.struts.upload.MultipartRequestWrapper in project sonar-java by SonarSource.

the class RequestUtils method getAllParametersForMultipartRequest.

/**
 * <p>Create a <code>Map</code> containing all of the parameters supplied
 * for a multipart request, keyed by parameter name. In addition to text
 * and file elements from the multipart body, query string parameters are
 * included as well.</p>
 *
 * @param request          The (wrapped) HTTP request whose parameters are
 *                         to be added to the map.
 * @param multipartHandler The multipart handler used to parse the
 *                         request.
 * @return the map containing all parameters for this multipart request.
 */
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
    Map parameters = new HashMap();
    Hashtable elements = multipartHandler.getAllElements();
    Enumeration e = elements.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        parameters.put(key, elements.get(key));
    }
    if (request instanceof MultipartRequestWrapper) {
        request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
        e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            parameters.put(key, request.getParameterValues(key));
        }
    } else {
        log.debug("Gathering multipart parameters for unwrapped request");
    }
    return parameters;
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) MultipartRequestWrapper(org.apache.struts.upload.MultipartRequestWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MultipartRequestWrapper

use of org.apache.struts.upload.MultipartRequestWrapper in project xwiki-platform by xwiki.

the class Utils method handleMultipart.

/**
 * Process a multi-part request, extracting all the uploaded files.
 *
 * @param request the current request to process
 * @param context the current context
 * @return the instance of the {@link FileUploadPlugin} used to parse the uploaded files
 */
public static FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context) {
    FileUploadPlugin fileupload = null;
    try {
        if (request instanceof MultipartRequestWrapper) {
            fileupload = new FileUploadPlugin("fileupload", "fileupload", context);
            context.put("fileuploadplugin", fileupload);
            fileupload.loadFileList(context);
            MultipartRequestWrapper mpreq = (MultipartRequestWrapper) request;
            List<FileItem> fileItems = fileupload.getFileItems(context);
            for (FileItem item : fileItems) {
                if (item.isFormField()) {
                    String sName = item.getFieldName();
                    String sValue = item.getString(context.getWiki().getEncoding());
                    mpreq.setParameter(sName, sValue);
                }
            }
        }
    } catch (Exception e) {
        if ((e instanceof XWikiException) && (((XWikiException) e).getCode() == XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE)) {
            context.put("exception", e);
        } else {
            LOGGER.error("Failed to process MultiPart request", e);
        }
    }
    return fileupload;
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) FileUploadPlugin(com.xpn.xwiki.plugin.fileupload.FileUploadPlugin) MultipartRequestWrapper(org.apache.struts.upload.MultipartRequestWrapper) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

MultipartRequestWrapper (org.apache.struts.upload.MultipartRequestWrapper)6 Enumeration (java.util.Enumeration)4 HashMap (java.util.HashMap)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 XWikiException (com.xpn.xwiki.XWikiException)1 FileUploadPlugin (com.xpn.xwiki.plugin.fileupload.FileUploadPlugin)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 LinkedHashMap (java.util.LinkedHashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 FileItem (org.apache.commons.fileupload.FileItem)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1