Package org.appng.forms.impl
Class FormUploadBean
- java.lang.Object
-
- org.appng.forms.impl.FormUploadBean
-
- All Implemented Interfaces:
FormUpload
public class FormUploadBean extends Object implements FormUpload
DefaultFormUpload
implementation.- Author:
- Matthias Müller
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
getAcceptedTypes()
byte[]
getBytes()
Returns the bytes of the uploadedFile
.String
getContentType()
Returns the content-type (if any) for thisFormUpload
.File
getFile()
long
getMaxSize()
Returns the maximum size (in bytes) for the uploadedFile
(default: -1, which means there is no limit).long
getMinSize()
Returns the minimum size (in bytes) for the uploaded file (default: 0).String
getOriginalFilename()
Returns the name of the original (without any path prefix) file which was uploaded.boolean
isValid()
Returnstrue
if, and only if, all of those methods returntrue
:FormUpload.isValidFile()
FormUpload.isValidSize()
FormUpload.isValidType()
boolean
isValid(Class<? extends FormUploadValidator> validatorClass)
CallsFormUploadValidator.isValid(FormUpload)
using thisFormUpload
and returns the result.boolean
isValid(String[] types, long minSize, long maxSize)
Checks whether thisFormUpload
has one of the given types and matches the given size restrictions.boolean
isValid(FormUploadValidator validator)
CallsFormUploadValidator.isValid(FormUpload)
using thisFormUpload
and returns the result.boolean
isValidFile()
boolean
isValidSize()
Checks whether theFile
has a valid size.boolean
isValidType()
Checks whether theFile
's extension or content-type are contained in the list of accepted types for thisFormUpload
.long
size()
Returns the size (in bytes) of the uploadedFile
.String
toString()
-
-
-
Method Detail
-
getAcceptedTypes
public List<String> getAcceptedTypes()
Description copied from interface:FormUpload
- Specified by:
getAcceptedTypes
in interfaceFormUpload
- Returns:
- the list of accepted types
- See Also:
FormUpload.getContentType()
-
getOriginalFilename
public String getOriginalFilename()
Description copied from interface:FormUpload
Returns the name of the original (without any path prefix) file which was uploaded.- Specified by:
getOriginalFilename
in interfaceFormUpload
- Returns:
- the name of the original file
-
getFile
public File getFile()
Description copied from interface:FormUpload
Returns theFile
which has been locally saved, but only ifFormUpload.isValid()
returnstrue
. The name of this file may have nothing to do with the file's original name.- Specified by:
getFile
in interfaceFormUpload
- Returns:
- the
File
, ornull
if no file was uploaded orFormUpload.isValid()
returnsfalse
- See Also:
FormUpload.getOriginalFilename()
-
size
public long size()
Description copied from interface:FormUpload
Returns the size (in bytes) of the uploadedFile
.- Specified by:
size
in interfaceFormUpload
- Returns:
- the size
-
getMaxSize
public long getMaxSize()
Description copied from interface:FormUpload
Returns the maximum size (in bytes) for the uploadedFile
(default: -1, which means there is no limit).- Specified by:
getMaxSize
in interfaceFormUpload
- Returns:
- the maximum size
-
getMinSize
public long getMinSize()
Description copied from interface:FormUpload
Returns the minimum size (in bytes) for the uploaded file (default: 0).- Specified by:
getMinSize
in interfaceFormUpload
- Returns:
- the minimum size
-
getBytes
public byte[] getBytes()
Description copied from interface:FormUpload
Returns the bytes of the uploadedFile
.- Specified by:
getBytes
in interfaceFormUpload
- Returns:
- the bytes
-
isValidSize
public boolean isValidSize()
Description copied from interface:FormUpload
Checks whether theFile
has a valid size. Note that by default, there is no minimum size. The default maximum size is provided by the concreteFormUpload
.- Specified by:
isValidSize
in interfaceFormUpload
- Returns:
true
if the file's size is valid,false
otherwise- See Also:
FormUpload.isValid(String[], long, long)
,FormUpload.getMinSize()
,FormUpload.getMaxSize()
-
isValid
public boolean isValid()
Description copied from interface:FormUpload
Returnstrue
if, and only if, all of those methods returntrue
:- Specified by:
isValid
in interfaceFormUpload
- Returns:
true
if thisFormUpload
is valid,false
otherwise.
-
isValid
public boolean isValid(String[] types, long minSize, long maxSize)
Description copied from interface:FormUpload
Checks whether thisFormUpload
has one of the given types and matches the given size restrictions. Delegates toFormUpload.isValidSize()
andFormUpload.isValidType()
.- Specified by:
isValid
in interfaceFormUpload
- Parameters:
types
- an array containing the allowed file-extensions (without.
) and content-typesminSize
- the minimum size of the file (in bytes)maxSize
- the maximum size of the file (in bytes)- Returns:
true
if thisFormUpload
is valid,false
otherwise.- See Also:
FormUpload.isValidSize()
,FormUpload.isValidType()
,FormUpload.getContentType()
,FormUpload.getAcceptedTypes()
-
isValid
public boolean isValid(FormUploadValidator validator)
Description copied from interface:FormUpload
CallsFormUploadValidator.isValid(FormUpload)
using thisFormUpload
and returns the result.- Specified by:
isValid
in interfaceFormUpload
- Parameters:
validator
- aFormUploadValidator
- Returns:
- the result returned by
FormUploadValidator.isValid(FormUpload)
-
isValid
public boolean isValid(Class<? extends FormUploadValidator> validatorClass)
Description copied from interface:FormUpload
CallsFormUploadValidator.isValid(FormUpload)
using thisFormUpload
and returns the result.- Specified by:
isValid
in interfaceFormUpload
- Parameters:
validatorClass
- a type extendingFormUploadValidator
- Returns:
- the result returned by
FormUploadValidator.isValid(FormUpload)
-
isValidFile
public boolean isValidFile()
Description copied from interface:FormUpload
- Specified by:
isValidFile
in interfaceFormUpload
- Returns:
true
if theFile
is valid,false
otherwise
-
isValidType
public boolean isValidType()
Description copied from interface:FormUpload
Checks whether theFile
's extension or content-type are contained in the list of accepted types for thisFormUpload
. IfFormUpload.getAcceptedTypes()
isnull
or empty, all types are allowed.- Specified by:
isValidType
in interfaceFormUpload
- Returns:
true
if the uploadedFile
has a valid type,false
otherwise.- See Also:
FormUpload.getAcceptedTypes()
,FormUpload.getContentType()
-
getContentType
public String getContentType()
Description copied from interface:FormUpload
Returns the content-type (if any) for thisFormUpload
. Usually the content-type has been retrieved usingServletRequest.getContentType()
- Specified by:
getContentType
in interfaceFormUpload
- Returns:
- the content type for this
FormUpload
, ornull
-
-