Class MultipartFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class MultipartFilter
    extends JcmsServletFilter
    implements javax.servlet.Filter

    Filter for automatic file upload processing. it wrapper HttpServletRequest to pass any form parameters in usuall form (normally they are not accessible cause JSDK web container are not required to implement RFC1867).

    Use filter attribute "uploadDir" to set temporary directory. If there is no attribute, then create a unique sub directory in the java.io.tmpdir path.

    Use filter attribute "sizeMax" to set max size otherwise use 2048000000L.

    Use filter attribute "sizeThreshold" the threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.. Default value is 4096.

    FIXME:

    FileItem access is done through attributes. By default they are named after the form field name. However you are allowed to supply attributePrefix and/or attributeSuffix that will be used to "decorate" the attribute name. Request parameter is still set with a fake value defined by filter attribute "fakeParam".

    Since:
    jcms-5.7.0
    Author:
    Jean-Philippe Encausse
    • Constructor Summary

      Constructors 
      Constructor Description
      MultipartFilter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      void doFilter​(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
      Wraps the ServletRequest into a MultiPart Request if it contains multipart data.
      static java.util.Map<java.lang.String,​java.lang.String> getFileUploadStatus​(java.lang.String field, java.lang.String token)  
      void init​(javax.servlet.FilterConfig cfg)  
      void initFileUpload()
      Initialise filter's parameter from FilterConfing and JCMS Properties
      protected javax.servlet.http.HttpServletRequest wrapRequest​(javax.servlet.http.HttpServletRequest request)
      Wrap the request into a MultipartRequest if we are in MultipartContent with upload
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UPLOAD_DIR

        public static final java.lang.String UPLOAD_DIR
        Name of directory, created inside the temporary directory, that will be used to store temporary upload file.
        See Also:
        Constant Field Values
      • CACHE_MULTIPART_PATHINFO

        public static final java.lang.String CACHE_MULTIPART_PATHINFO
        See Also:
        Constant Field Values
      • config

        protected javax.servlet.FilterConfig config
      • directory

        protected java.io.File directory
      • sizeThreshold

        protected int sizeThreshold
      • sizeMax

        protected long sizeMax
      • countMax

        protected long countMax
      • initFilter

        protected boolean initFilter
    • Constructor Detail

      • MultipartFilter

        public MultipartFilter()
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig cfg)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
        See Also:
        Filter.init(FilterConfig)
      • initFileUpload

        public void initFileUpload()
                            throws javax.servlet.ServletException
        Initialise filter's parameter from FilterConfing and JCMS Properties
        Throws:
        javax.servlet.ServletException
      • doFilter

        public void doFilter​(javax.servlet.ServletRequest req,
                             javax.servlet.ServletResponse res,
                             javax.servlet.FilterChain chain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
        Wraps the ServletRequest into a MultiPart Request if it contains multipart data.
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        java.io.IOException
        javax.servlet.ServletException
        See Also:
        Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
      • wrapRequest

        protected javax.servlet.http.HttpServletRequest wrapRequest​(javax.servlet.http.HttpServletRequest request)
                                                             throws org.apache.commons.fileupload.FileUploadException,
                                                                    java.io.UnsupportedEncodingException
        Wrap the request into a MultipartRequest if we are in MultipartContent with upload
        Parameters:
        request - current HttpServletRequest
        Returns:
        the given request if it's not a multipart content with upload, or a new instance of MultipartRequest
        Throws:
        org.apache.commons.fileupload.FileUploadException
        java.io.UnsupportedEncodingException
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Filter
        See Also:
        Filter.destroy()
      • getFileUploadStatus

        public static java.util.Map<java.lang.String,​java.lang.String> getFileUploadStatus​(java.lang.String field,
                                                                                                 java.lang.String token)