|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.webwork.interceptor.FileUploadInterceptor
public class FileUploadInterceptor
Interceptor that is based off of MultiPartRequestWrapper
, which is automatically applied for any request that
includes a file. It adds the following parameters, where [File Name] is the name given to the file uploaded by the
HTML form:
ValidationAware
.
These error messages are based on several i18n values stored in webwork-messages.properties, a default i18n file
processed for all i18n requests. You can override the text of these messages by providing text for the following
keys:
acceptFile(java.io.File, java.lang.String, java.lang.String, com.opensymphony.xwork.ValidationAware, java.util.Locale)
method to provide more control over which files
are supported and which are not.
Example code:
<action name="doUpload" class="com.examples.UploadAction"> <interceptor-ref name="fileUpload"/> <interceptor-ref name="basicStack"/> <result name="success">good_result.ftl</result> </action>And then you need to set encoding
multipart/form-data
in the form where the user selects the file to upload.
<ww:form action="doUpload" method="post" enctype="multipart/form-data"> <ww:file name="upload" label="File"/> <ww:submit/> </ww:form>And then in your action code you'll have access to the File object if you provide setters according to the naming convention documented in the start.
public com.examples.UploadAction implemements Action { private File file; private String contentType; private String filename; public void setUpload(File file) { this.file = file; } public void setUploadContentType(String contentType) { this.contentType = contentType; } public void setUploadFileName(String filename) { this.filename = filename; } ... }
Field Summary | |
---|---|
protected String |
allowedTypes
|
protected Set |
allowedTypesSet
|
protected static org.apache.commons.logging.Log |
log
|
protected Long |
maximumSize
|
Constructor Summary | |
---|---|
FileUploadInterceptor()
|
Method Summary | |
---|---|
protected boolean |
acceptFile(File file,
String contentType,
String inputName,
ValidationAware validation,
Locale locale)
Override for added functionality. |
protected boolean |
containsItem(Collection itemCollection,
String key)
|
void |
destroy()
Called to let an interceptor clean up any resources it has allocated. |
protected Set |
getDelimitedValues(String delimitedString)
|
protected String |
getTextMessage(String messageKey,
Object[] args,
Locale locale)
|
void |
init()
Called after an interceptor is created, but before any requests are processed using intercept , giving
the Interceptor a chance to initialize any needed resources. |
String |
intercept(ActionInvocation invocation)
Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code. |
protected boolean |
isNonEmpty(Object[] objArray)
|
void |
setAllowedTypes(String allowedTypes)
|
void |
setMaximumSize(Long maximumSize)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.commons.logging.Log log
protected Long maximumSize
protected String allowedTypes
protected Set allowedTypesSet
Constructor Detail |
---|
public FileUploadInterceptor()
Method Detail |
---|
public void setAllowedTypes(String allowedTypes)
public void setMaximumSize(Long maximumSize)
public void destroy()
Interceptor
destroy
in interface Interceptor
public void init()
Interceptor
intercept
, giving
the Interceptor a chance to initialize any needed resources.
init
in interface Interceptor
public String intercept(ActionInvocation invocation) throws Exception
Interceptor
ActionInvocation
or to short-circuit the processing and just return a String return code.
intercept
in interface Interceptor
ActionInvocation.invoke()
, or from the interceptor itself.
Exception
- any system-level error, as defined in Action.execute()
.protected boolean acceptFile(File file, String contentType, String inputName, ValidationAware validation, Locale locale)
file
- - proposed upload file.contentType
- - contentType of the file.inputName
- - inputName of the file.validation
- - Non-null ValidationAware if the action implements ValidationAware, allowing for better
logging.locale
-
protected boolean containsItem(Collection itemCollection, String key)
itemCollection
- - Collection of string items (all lowercase).key
- - Key to search for.
protected Set getDelimitedValues(String delimitedString)
protected boolean isNonEmpty(Object[] objArray)
protected String getTextMessage(String messageKey, Object[] args, Locale locale)
|
WebWork Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |