com.sun.rave.web.ui.util
Class UploadFilter

java.lang.Object
  extended by com.sun.rave.web.ui.util.UploadFilter
All Implemented Interfaces:
javax.servlet.Filter

public class UploadFilter
extends java.lang.Object
implements javax.servlet.Filter

Use the UploadFilter if your application contains an Upload component (<ui:upload> tag).

Configure the filter by declaring the filter element in the web application's deployment descriptor.

 
  <filter>
    <filter-name>UploadFilter</filter-name>
    <filter-class>com.sun.rave.web.ui.util.UploadFilter</filter-class>
  </filter>
 

Map the filter to the FacesServlet, for example

  <filter-mapping>
    <filter-name>UploadFilter</filter-name>
    <servlet-name>FacesServlet</servlet-name>
  </filter-mapping>
 

The UploadFilter uses the Apache commons fileupload package. You can configure the parameters of the DiskFileUpload class by specifying init parameters to the Filter. The following parameters are available:


Field Summary
static java.lang.String MAX_SIZE
          The name of the filter init parameter used to specify the maximum allowable file upload size.
static java.lang.String SIZE_THRESHOLD
          The name of the filter init parameter used to specify the byte size above which temporary storage of files is on disk.
static java.lang.String TMP_DIR
          The name of the filter init parameter used to specify the directory to be used for temporary storage of uploaded files.
 
Constructor Summary
UploadFilter()
           
 
Method Summary
 void destroy()
          Invoked when the Filter is destroyed
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          The upload filter checks if the incoming request has multipart content.
 void init(javax.servlet.FilterConfig filterConfig)
          Initializes the Upload filter by reading any init parameters.
 java.lang.String toString()
          Return a String representation of the UploadFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_SIZE

public static final java.lang.String MAX_SIZE
The name of the filter init parameter used to specify the maximum allowable file upload size.

See Also:
Constant Field Values

SIZE_THRESHOLD

public static final java.lang.String SIZE_THRESHOLD
The name of the filter init parameter used to specify the byte size above which temporary storage of files is on disk.

See Also:
Constant Field Values

TMP_DIR

public static final java.lang.String TMP_DIR
The name of the filter init parameter used to specify the directory to be used for temporary storage of uploaded files.

See Also:
Constant Field Values
Constructor Detail

UploadFilter

public UploadFilter()
Method Detail

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException

The upload filter checks if the incoming request has multipart content. If it doesn't, the request is passed on as is to the next filter in the chain. If it does, the filter processes the request for form components. If it finds input from an Upload component, the file contents are stored for access by the Upload component's decode method.

For other form components, the input is processed and used to create a request parameter map. The original incoming request is wrapped, and the wrapped request is configured to use the created map. This means that subsequent filters in the chain (and Servlets, and JSPs) see the input from the other components as request parameters.

For advanced users: the UploadFilter uses the Apache commons FileUpload package to process the file upload. When it detects input from an Upload component, a org.apache.commons.fileupload.FileItem is placed in a request attribute whose name is the ID of the HTML input element written by the Upload component.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
response - The servlet response
request - The servlet request we are processing
chain - The filter chain we are processing
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet error occurs

init

public void init(javax.servlet.FilterConfig filterConfig)
Initializes the Upload filter by reading any init parameters.

Specified by:
init in interface javax.servlet.Filter
Parameters:
filterConfig - the filter configuration

toString

public java.lang.String toString()
Return a String representation of the UploadFilter

Overrides:
toString in class java.lang.Object
Returns:
A String representation of the UploadFilter

destroy

public void destroy()
Invoked when the Filter is destroyed

Specified by:
destroy in interface javax.servlet.Filter