com.jalios.jcms.upload
Class MultipartFilter

java.lang.Object
  extended by com.jalios.jcms.servlet.JcmsServletFilter
      extended by com.jalios.jcms.upload.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 sub directory UPLOAD_DIR in javax.servlet.context.tempdir 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
Version:
$Revision: 31607 $
Author:
Jean-Philippe Encausse

Field Summary
protected  javax.servlet.FilterConfig config
           
protected  File directory
           
protected  boolean initFilter
           
static String PROGRESS_STATUS
           
static String REVISION
           
protected  long sizeMax
           
protected  int sizeThreshold
           
static String UPLOAD_DIR
           
static String UPLOAD_ERROR
           
 
Constructor Summary
MultipartFilter()
           
 
Method Summary
 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 Map<String,String> getFileUploadStatus(String field, String token)
           
 void init(javax.servlet.FilterConfig cfg)
           
 void initFileUpload()
          Initialise filter's parameter from FilterConfing and JCMS Properties
protected  void registerJSONClass(javax.servlet.http.HttpServletRequest request)
          Register MultipartRequest class in JSON for use by docChooser.js upload status
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 com.jalios.jcms.servlet.JcmsServletFilter
endFilter, initJSONBridge, processFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

PROGRESS_STATUS

public static final String PROGRESS_STATUS
See Also:
Constant Field Values

UPLOAD_ERROR

public static final String UPLOAD_ERROR
See Also:
Constant Field Values

UPLOAD_DIR

public static final String UPLOAD_DIR
See Also:
Constant Field Values

config

protected javax.servlet.FilterConfig config

directory

protected File directory

sizeThreshold

protected int sizeThreshold

sizeMax

protected long sizeMax

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 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:
IOException
javax.servlet.ServletException
See Also:
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)

registerJSONClass

protected void registerJSONClass(javax.servlet.http.HttpServletRequest request)
Register MultipartRequest class in JSON for use by docChooser.js upload status

Parameters:
request - current HttpServletRequest

wrapRequest

protected javax.servlet.http.HttpServletRequest wrapRequest(javax.servlet.http.HttpServletRequest request)
                                                     throws org.apache.commons.fileupload.FileUploadException,
                                                            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
UnsupportedEncodingException

destroy

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

getFileUploadStatus

public static Map<String,String> getFileUploadStatus(String field,
                                                     String token)


Copyright © 2001-2010 Jalios SA. All Rights Reserved.