Package org.appng.forms.impl
Class RequestBean
- java.lang.Object
-
- org.appng.forms.impl.RequestBean
-
- All Implemented Interfaces:
Request
,RequestContainer
public class RequestBean extends Object implements Request
The defaultRequest
-implementation.- Author:
- Matthias Müller
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,List<FormUpload>>
formUploads
protected String
host
protected Map<String,List<String>>
parameters
-
Fields inherited from interface org.appng.forms.Request
REQUEST_PARSED
-
-
Constructor Summary
Constructors Constructor Description RequestBean()
RequestBean(long maxSize)
RequestBean(long maxSize, File tempDir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addParameter(String key, String value)
Adds the given parameter to thisRequest
, but only if such a parameter not already exists.void
addParameters(Map<String,String> singleParameters)
Adds the given parameters to thisRequest
, but only for those parameters not already existsing.List<String>
getAcceptedTypes(String uploadName)
Returns the accepted file-extensions/content-types for the input field with the given name.String
getEncoding()
Return the encoding for this requestMap<String,List<FormUpload>>
getFormUploads()
Returns allFormUpload
s for the request as immutable map.List<FormUpload>
getFormUploads(String name)
Returns an immutableList
of allFormUpload
s for the parameter with the given name.String
getHost()
Returns the host name for this requestjavax.servlet.http.HttpServletRequest
getHttpServletRequest()
Returns the previously processedHttpServletRequest
String
getParameter(String name)
Returns the value for the parameter with the given name.
Note that for a multi-valued parameter, any of the submitted values is returned.List<String>
getParameterList(String name)
Returns aList
containing all the values for the parameter with the given name.Set<String>
getParameterNames()
Returns an immutableSet
containing the names of all request parameters.Map<String,String>
getParameters()
Returns an immutableMap
containing the name of each request-parameter as a key and a single parameter value as the map's value.
Note that for multi-valued parameters, the returned map contains any of the submitted values.Map<String,List<String>>
getParametersList()
Returns an immutableMap
containing the name of each request-parameter as a key and the list of submitted values as value.XSSUtil
getXssUtil()
boolean
hasParameter(String name)
Checks whether a parameter with the given name exists.boolean
isGet()
Returnstrue
if this is a HTPP GET request.boolean
isMultiPart()
Returnstrue
if this is a multipart request.boolean
isPost()
Returnstrue
if this is a HTPP POST request.boolean
isValid()
Checks whether this is a validRequest
, i.e.void
process(javax.servlet.http.HttpServletRequest servletRequest)
Processes the givenHttpServletRequest
.void
setAcceptedTypes(String uploadName, String... types)
Sets the accepted mime-types or filetype-extensions for the given fieldvoid
setEncoding(String encoding)
Sets the encoding for this requestvoid
setHost(String host)
void
setMaxSize(long maxSize)
Sets the maximum size for aFormUpload
within thisRequest
.void
setMaxSize(long maxSize, boolean isStrict)
Sets the maximum size for aFormUpload
within thisRequest
, and additionally defines if violations should be handled strict.void
setTempDir(File tempDir)
Sets the (absolute) temporary directory for storingFormUpload
s.void
setXssUtil(XSSUtil xssUtil)
-
-
-
Constructor Detail
-
RequestBean
public RequestBean()
-
RequestBean
public RequestBean(long maxSize)
-
RequestBean
public RequestBean(long maxSize, File tempDir)
-
-
Method Detail
-
getFormUploads
public List<FormUpload> getFormUploads(String name)
Description copied from interface:RequestContainer
Returns an immutableList
of allFormUpload
s for the parameter with the given name.- Specified by:
getFormUploads
in interfaceRequestContainer
- Parameters:
name
- the name of the parameters- Returns:
- a list if
FormUpload
s (nevernull
, but may be empty)
-
process
public void process(javax.servlet.http.HttpServletRequest servletRequest)
Description copied from interface:Request
Processes the givenHttpServletRequest
. Must only be called once perHttpServletRequest
.
-
getEncoding
public String getEncoding()
Description copied from interface:Request
Return the encoding for this request- Specified by:
getEncoding
in interfaceRequest
- Returns:
- the encoding
-
setEncoding
public void setEncoding(String encoding)
Description copied from interface:Request
Sets the encoding for this request- Specified by:
setEncoding
in interfaceRequest
- Parameters:
encoding
- the encoding
-
isMultiPart
public boolean isMultiPart()
Description copied from interface:Request
Returnstrue
if this is a multipart request.- Specified by:
isMultiPart
in interfaceRequest
- Returns:
true
if this is a multipart request,false
otherwise
-
isPost
public boolean isPost()
Description copied from interface:Request
Returnstrue
if this is a HTPP POST request.
-
isGet
public boolean isGet()
Description copied from interface:Request
Returnstrue
if this is a HTPP GET request.
-
setTempDir
public void setTempDir(File tempDir)
Description copied from interface:Request
Sets the (absolute) temporary directory for storingFormUpload
s. Note that, if not set or not existent, the directory specified by theSystem
properteyjava.io.tmpdir
is used.- Specified by:
setTempDir
in interfaceRequest
- Parameters:
tempDir
- the directory for storingFormUpload
s
-
setMaxSize
public void setMaxSize(long maxSize)
Description copied from interface:Request
Sets the maximum size for aFormUpload
within thisRequest
.- Specified by:
setMaxSize
in interfaceRequest
- Parameters:
maxSize
- the maximum size of aFormUpload
- See Also:
FormUpload.getMaxSize()
-
setMaxSize
public void setMaxSize(long maxSize, boolean isStrict)
Description copied from interface:Request
Sets the maximum size for aFormUpload
within thisRequest
, and additionally defines if violations should be handled strict.- Specified by:
setMaxSize
in interfaceRequest
- Parameters:
maxSize
- the maximum size of aFormUpload
isStrict
- if set totrue
, and aFormUpload
exceeds the given size, the wholeRequest
will be marked as invalid.- See Also:
Request.isValid()
-
setAcceptedTypes
public void setAcceptedTypes(String uploadName, String... types)
Description copied from interface:Request
Sets the accepted mime-types or filetype-extensions for the given field- Specified by:
setAcceptedTypes
in interfaceRequest
- Parameters:
uploadName
- the name of the input-field (type="file")types
- the accepted mimetypes (e.g. image/jpeg, image/png) or file extensions (e.g jgp,png), those can be used in combination
-
getAcceptedTypes
public List<String> getAcceptedTypes(String uploadName)
Description copied from interface:Request
Returns the accepted file-extensions/content-types for the input field with the given name.- Specified by:
getAcceptedTypes
in interfaceRequest
- Parameters:
uploadName
- the name of the input field- Returns:
- a list of accepted tyes
- See Also:
FormUpload.getAcceptedTypes()
-
isValid
public boolean isValid()
Description copied from interface:Request
Checks whether this is a validRequest
, i.e. noException
occurred duringRequest.process(HttpServletRequest)
.
-
getHttpServletRequest
public javax.servlet.http.HttpServletRequest getHttpServletRequest()
Description copied from interface:Request
Returns the previously processedHttpServletRequest
- Specified by:
getHttpServletRequest
in interfaceRequest
- Returns:
- the
HttpServletRequest
-
addParameter
public void addParameter(String key, String value)
Description copied from interface:Request
Adds the given parameter to thisRequest
, but only if such a parameter not already exists. This prevents overwriting a parameter which is already present in the originalHttpServletRequest
.- Specified by:
addParameter
in interfaceRequest
- Parameters:
key
- the parameter namevalue
- the parameter value
-
addParameters
public void addParameters(Map<String,String> singleParameters)
Description copied from interface:Request
Adds the given parameters to thisRequest
, but only for those parameters not already existsing. This prevents overwriting a parameter which is already present in the originalHttpServletRequest
. The givenMap
uses the parameter name as the key and the parameter value as the value.- Specified by:
addParameters
in interfaceRequest
- Parameters:
singleParameters
- the parameters to add- See Also:
Request.addParameter(String, String)
,RequestContainer.getParameter(String)
-
getFormUploads
public Map<String,List<FormUpload>> getFormUploads()
Description copied from interface:RequestContainer
Returns allFormUpload
s for the request as immutable map. Returns aMap
using the parameters name as a key and aList
ofFormUpload
s as the value.- Specified by:
getFormUploads
in interfaceRequestContainer
- Returns:
- a
Map
containing theFileUpload
s
-
getHost
public String getHost()
Description copied from interface:RequestContainer
Returns the host name for this request- Specified by:
getHost
in interfaceRequestContainer
- Returns:
- the host name
-
getParameter
public String getParameter(String name)
Description copied from interface:RequestContainer
Returns the value for the parameter with the given name.
Note that for a multi-valued parameter, any of the submitted values is returned. UseRequestContainer.getParameterList(String)
instead if you want to deal with a multi-valued parameter.- Specified by:
getParameter
in interfaceRequestContainer
- Parameters:
name
- the name of the parameter- Returns:
- the value of the parameter (may be null)
-
getParameterList
public List<String> getParameterList(String name)
Description copied from interface:RequestContainer
Returns aList
containing all the values for the parameter with the given name.- Specified by:
getParameterList
in interfaceRequestContainer
- Parameters:
name
- the name of the parameter- Returns:
- a
List
(nevernull
, but may be empty) containing all the values for the given parameter
-
getParameterNames
public Set<String> getParameterNames()
Description copied from interface:RequestContainer
Returns an immutableSet
containing the names of all request parameters.- Specified by:
getParameterNames
in interfaceRequestContainer
- Returns:
- the parameters names
-
getParameters
public Map<String,String> getParameters()
Description copied from interface:RequestContainer
Returns an immutableMap
containing the name of each request-parameter as a key and a single parameter value as the map's value.
Note that for multi-valued parameters, the returned map contains any of the submitted values. UseRequestContainer.getParametersList()
instead if you want to deal with multi-valued parameters.- Specified by:
getParameters
in interfaceRequestContainer
- Returns:
- a
Map
containing the request parameters
-
getParametersList
public Map<String,List<String>> getParametersList()
Description copied from interface:RequestContainer
Returns an immutableMap
containing the name of each request-parameter as a key and the list of submitted values as value.- Specified by:
getParametersList
in interfaceRequestContainer
- Returns:
- a
Map
containing the request parameters (including multi-valued ones)
-
hasParameter
public boolean hasParameter(String name)
Description copied from interface:RequestContainer
Checks whether a parameter with the given name exists.- Specified by:
hasParameter
in interfaceRequestContainer
- Parameters:
name
- the name of the parameter- Returns:
true
if such a parameter exists,false
otherwise
-
setHost
public void setHost(String host)
-
getXssUtil
public XSSUtil getXssUtil()
-
setXssUtil
public void setXssUtil(XSSUtil xssUtil)
-
-