Package org.appng.api.support
Class ApplicationRequest
- java.lang.Object
-
- org.appng.api.support.ApplicationRequest
-
- All Implemented Interfaces:
Request
,RequestSupport
,ValidationProvider
,RequestContainer
,org.springframework.core.convert.ConversionService
public class ApplicationRequest extends Object implements Request
DefaultRequest
implementation, mostly delegating method-calls to one of the internal objects.- Author:
- Matthias Müller
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApplicationRequest.ApplicationPath
Helper class used to simplify include conditions for actions and datasources on a page.
Registered as variablePATH
, so conditions can look like
-
Constructor Summary
Constructors Constructor Description ApplicationRequest()
ApplicationRequest(Request request, PermissionProcessor permissionProcessor, RequestSupport requestSupport)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addErrorMessage(FieldProcessor fp, MessageParam localizable)
Adds an error to theFieldProcessor
usingFieldProcessor.addErrorMessage(String)
.void
addErrorMessage(FieldProcessor fp, MessageParam localizable, String fieldBinding)
Adds an error to aFieldDef
usingFieldProcessor.addErrorMessage(org.appng.xml.platform.FieldDef, String)
.void
addParameter(String key, String value)
void
addParameters(Map<String,String> singleParameters)
void
addValidationMetaData(MetaData metaData, ClassLoader classLoader, Class<?>... groups)
Based on the JSR-303 annotations of theMetaData
's bindclass, this method adds theValidation
to theFieldDef
initions.ApplicationRequest.ApplicationPath
applicationPath()
Creates a newApplicationRequest.ApplicationPath
to be used to evaluate include-conditions on a page.boolean
canConvert(Class<?> sourceType, Class<?> targetType)
boolean
canConvert(org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
<T> T
convert(Object source, Class<T> targetType)
Object
convert(Object source, org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
void
fillBindObject(Object instance, FieldProcessor fp, RequestContainer container, ClassLoader classLoader)
Fills the givenbindobject
with the (converted) values provided by aRequestContainer
.List<String>
getAcceptedTypes(String uploadName)
ApplicationConfigProvider
getApplicationConfig()
Object
getBindObject(FieldProcessor fp, RequestContainer container, ClassLoader classLoader)
Creates, fills and returns a new bindobject.String
getEncoding()
Environment
getEnvironment()
Returns theEnvironment
for thisRequest
.ExpressionEvaluator
getExpressionEvaluator()
Returns theExpressionEvaluator
for thisRequest
.FieldConverter
getFieldConverter()
Returns aFieldConverter
Map<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()
LabelSupport
getLabelSupport()
Locale
getLocale()
String
getMessage(String key, Object... args)
Retrieves a message from the underlyingMessageSource
, using theLocale
provided byEnvironment.getLocale()
.org.springframework.context.MessageSource
getMessageSource()
Returns the currently usedMessageSource
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.ParameterSupport
getParameterSupportDollar()
Returns theParameterSupport
for thisRequest
.PermissionProcessor
getPermissionProcessor()
Returns thePermissionProcessor
for thisRequest
.String
getRedirectTarget()
RequestSupport
getRequestSupport()
Subject
getSubject()
List<String>
getUrlParameters()
Returns a list of URL-Parameters for a JSP-page, which are those path-elements appearing after the name of the JSP-page itself.ValidationProvider
getValidationProvider()
Request
getWrappedRequest()
void
handleException(FieldProcessor fp, Exception e)
Handles anException
.boolean
hasParameter(String name)
Checks whether a parameter with the given name exists.org.springframework.http.HttpHeaders
headers()
Returns theHttpHeaders
for the underlyingHttpServletRequest
.boolean
isGet()
Checks whether thisRequest
originates of a HTTP GET-request.boolean
isMultiPart()
boolean
isPost()
Checks whether thisRequest
originates of a HTTP POST-request.boolean
isRedirect()
Checks whether a redirect-target has been set for thisRequest
.boolean
isValid()
void
setAcceptedTypes(String uploadName, String... types)
void
setApplicationConfig(ApplicationConfigProvider applicationConfigProvider)
void
setEncoding(String encoding)
void
setLabel(Label label)
void
setLabels(Config config)
void
setLabels(Config config, ParameterSupport fieldParameters)
void
setLabels(Labels labels)
void
setLabelSupport(LabelSupport labelSupport)
void
setMaxSize(long maxSize)
void
setMaxSize(long maxSize, boolean strict)
void
setPermissionProcessor(PermissionProcessor permissionProcessor)
<T> void
setPropertyValue(T source, T target, String property)
Copies the property fromsource
totarget
.<T> void
setPropertyValues(T source, T target, MetaData metaData)
void
setRedirectTarget(String redirectTarget)
void
setRequestSupport(RequestSupport requestSupport)
void
setTempDir(File tempDir)
void
setUrlParameters(List<String> urlParameters)
void
setValidationProvider(ValidationProvider validationProvider)
void
setWrappedRequest(Request wrappedRequest)
void
validateBean(Object bean, FieldProcessor fp, Class<?>... groups)
Validates the given bean by adding error-messages to theFieldDef
initions, usingFieldProcessor.addErrorMessage(FieldDef, String)
.void
validateBean(Object bean, FieldProcessor fp, String[] excludeBindings, Class<?>... groups)
Validates the given bean by adding error-messages to theFieldDef
initions, usingFieldProcessor.addErrorMessage(FieldDef, String)
.void
validateField(Object bean, FieldProcessor fp, String fieldBinding, Class<?>... groups)
Validates a singleFieldDef
by adding error-messages to it, usingFieldProcessor.addErrorMessage(FieldDef, String)
.
-
-
-
Field Detail
-
I18N_VAR
public static final String I18N_VAR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ApplicationRequest
public ApplicationRequest()
-
ApplicationRequest
public ApplicationRequest(Request request, PermissionProcessor permissionProcessor, RequestSupport requestSupport)
-
-
Method Detail
-
getPermissionProcessor
public PermissionProcessor getPermissionProcessor()
Description copied from interface:Request
Returns thePermissionProcessor
for thisRequest
.- Specified by:
getPermissionProcessor
in interfaceRequest
- Returns:
- the
PermissionProcessor
-
setPermissionProcessor
public void setPermissionProcessor(PermissionProcessor permissionProcessor)
-
getLabelSupport
public LabelSupport getLabelSupport()
-
setLabelSupport
public void setLabelSupport(LabelSupport labelSupport)
-
getWrappedRequest
public Request getWrappedRequest()
-
setWrappedRequest
public void setWrappedRequest(Request wrappedRequest)
-
getEnvironment
public Environment getEnvironment()
Description copied from interface:RequestSupport
Returns theEnvironment
for thisRequest
.- Specified by:
getEnvironment
in interfaceRequestSupport
- Returns:
- the
Environment
-
getRequestSupport
public RequestSupport getRequestSupport()
-
setRequestSupport
public void setRequestSupport(RequestSupport requestSupport)
-
getRedirectTarget
public String getRedirectTarget()
-
setRedirectTarget
public void setRedirectTarget(String redirectTarget)
-
canConvert
public boolean canConvert(Class<?> sourceType, Class<?> targetType)
- Specified by:
canConvert
in interfaceorg.springframework.core.convert.ConversionService
-
handleException
public void handleException(FieldProcessor fp, Exception e) throws BusinessException
Description copied from interface:RequestSupport
Handles anException
. If the given Exception is aBusinessException
, the very sameBusinessException
is being re-thrown. Otherwise, theException
is being wrapped into a newBusinessException
which is then being thrown.
If the givenException
is aMessageParam
,RequestSupport.addErrorMessage(FieldProcessor, MessageParam)
is being called.- Specified by:
handleException
in interfaceRequestSupport
- Parameters:
fp
- aFieldProcessor
e
- anException
- Throws:
BusinessException
- See Also:
MessageParam
,RequestSupport.addErrorMessage(FieldProcessor, MessageParam)
-
addErrorMessage
public void addErrorMessage(FieldProcessor fp, MessageParam localizable)
Description copied from interface:RequestSupport
Adds an error to theFieldProcessor
usingFieldProcessor.addErrorMessage(String)
.MessageParam.getMessageKey()
is used for the message key,MessageParam.getMessageArgs()
for the message arguments.- Specified by:
addErrorMessage
in interfaceRequestSupport
- Parameters:
fp
- aFieldProcessor
localizable
- aMessageParam
- See Also:
MessageParam
-
addErrorMessage
public void addErrorMessage(FieldProcessor fp, MessageParam localizable, String fieldBinding)
Description copied from interface:RequestSupport
Adds an error to aFieldDef
usingFieldProcessor.addErrorMessage(org.appng.xml.platform.FieldDef, String)
.MessageParam.getMessageKey()
is used for the message key,MessageParam.getMessageArgs()
for the message arguments.- Specified by:
addErrorMessage
in interfaceRequestSupport
- Parameters:
fp
- aFieldProcessor
localizable
- aMessageParam
fieldBinding
- the binding of theFieldDef
to add the error to- See Also:
MessageParam
-
convert
public <T> T convert(Object source, Class<T> targetType)
- Specified by:
convert
in interfaceorg.springframework.core.convert.ConversionService
-
setPropertyValues
public <T> void setPropertyValues(T source, T target, MetaData metaData)
Description copied from interface:RequestSupport
- Specified by:
setPropertyValues
in interfaceRequestSupport
- Parameters:
source
- the source object to read the fields fromtarget
- the target object to write the fields tometaData
- theMetaData
-
setPropertyValue
public <T> void setPropertyValue(T source, T target, String property)
Description copied from interface:RequestSupport
Copies the property fromsource
totarget
.- Specified by:
setPropertyValue
in interfaceRequestSupport
- Parameters:
source
- the source object to read the property fromtarget
- the target object to write the property toproperty
- the name of the property to set
-
canConvert
public boolean canConvert(org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
- Specified by:
canConvert
in interfaceorg.springframework.core.convert.ConversionService
-
convert
public Object convert(Object source, org.springframework.core.convert.TypeDescriptor sourceType, org.springframework.core.convert.TypeDescriptor targetType)
- Specified by:
convert
in interfaceorg.springframework.core.convert.ConversionService
-
getBindObject
public Object getBindObject(FieldProcessor fp, RequestContainer container, ClassLoader classLoader) throws BusinessException
Description copied from interface:RequestSupport
Creates, fills and returns a new bindobject. The type of the returned object is obtained fromfp.getMetaData().getBindClass()
. TheMetaData
'sFieldDef
initions are responsible for which fields are getting filled.- Specified by:
getBindObject
in interfaceRequestSupport
- Parameters:
fp
- the currentFieldProcessor
container
- theRequestContainer
used to retrieve the values for filling the bindobjectclassLoader
- theClassLoader
used to load the bindclass- Returns:
- a new bindobject
- Throws:
BusinessException
- if the bindclass could not be loaded, instantiated or initialized, or if an error occurred during filling the bindobject- See Also:
RequestSupport.fillBindObject(Object, FieldProcessor, RequestContainer, ClassLoader)
-
fillBindObject
public void fillBindObject(Object instance, FieldProcessor fp, RequestContainer container, ClassLoader classLoader) throws BusinessException
Description copied from interface:RequestSupport
Fills the givenbindobject
with the (converted) values provided by aRequestContainer
. The type of thebindobject
must matchfp.getMetaData().getBindClass()
. TheMetaData
'sFieldDef
initions are responsible for which fields are getting filled.- Specified by:
fillBindObject
in interfaceRequestSupport
- Parameters:
instance
- the bindobject to fillfp
- the currentFieldProcessor
container
- theRequestContainer
used to retrieve the values for filling the bindobjectclassLoader
- theClassLoader
used to load the bindclass- Throws:
BusinessException
-- if the type of the
bindobject
is not assignable from the type returned byfp.getMetaData().getBindClass()
- if the type returned by
fp.getMetaData().getBindClass()
can not be instanciated
- if the type of the
-
getMessage
public String getMessage(String key, Object... args)
Description copied from interface:RequestSupport
Retrieves a message from the underlyingMessageSource
, using theLocale
provided byEnvironment.getLocale()
.- Specified by:
getMessage
in interfaceRequestSupport
- Parameters:
key
- the message keyargs
- the message arguments
-
getMessageSource
public org.springframework.context.MessageSource getMessageSource()
Description copied from interface:RequestSupport
Returns the currently usedMessageSource
- Specified by:
getMessageSource
in interfaceRequestSupport
- Returns:
- a
MessageSource
-
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
-
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)
-
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
-
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)
-
getHttpServletRequest
public javax.servlet.http.HttpServletRequest getHttpServletRequest()
-
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
-
getEncoding
public String getEncoding()
-
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
-
setEncoding
public void setEncoding(String encoding)
-
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
-
isMultiPart
public boolean isMultiPart()
-
isPost
public boolean isPost()
Description copied from interface:Request
Checks whether thisRequest
originates of a HTTP POST-request.
-
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
-
isGet
public boolean isGet()
Description copied from interface:Request
Checks whether thisRequest
originates of a HTTP GET-request.
-
isValid
public boolean isValid()
-
setTempDir
public void setTempDir(File tempDir)
-
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)
-
setMaxSize
public void setMaxSize(long maxSize)
-
setMaxSize
public void setMaxSize(long maxSize, boolean strict)
-
getSubject
public Subject getSubject()
Description copied from interface:Request
- Specified by:
getSubject
in interfaceRequest
- Returns:
- the
Subject
-
getExpressionEvaluator
public ExpressionEvaluator getExpressionEvaluator()
Description copied from interface:Request
Returns theExpressionEvaluator
for thisRequest
.- Specified by:
getExpressionEvaluator
in interfaceRequest
- Returns:
- the
ExpressionEvaluator
-
getParameterSupportDollar
public ParameterSupport getParameterSupportDollar()
Description copied from interface:Request
Returns theParameterSupport
for thisRequest
.- Specified by:
getParameterSupportDollar
in interfaceRequest
- Returns:
- the
ParameterSupport
-
isRedirect
public boolean isRedirect()
Description copied from interface:Request
Checks whether a redirect-target has been set for thisRequest
.- Specified by:
isRedirect
in interfaceRequest
- Returns:
true
if a redirect-target has been set for thisRequest
,false
otherwise
-
setLabels
public void setLabels(Config config)
-
setLabels
public final void setLabels(Config config, ParameterSupport fieldParameters)
-
setLabel
public void setLabel(Label label)
-
setLabels
public void setLabels(Labels labels)
-
getFieldConverter
public FieldConverter getFieldConverter()
Description copied from interface:RequestSupport
Returns aFieldConverter
- Specified by:
getFieldConverter
in interfaceRequestSupport
- Returns:
- a
FieldConverter
-
getApplicationConfig
public ApplicationConfigProvider getApplicationConfig()
-
setApplicationConfig
public void setApplicationConfig(ApplicationConfigProvider applicationConfigProvider)
-
getValidationProvider
public ValidationProvider getValidationProvider()
-
setValidationProvider
public void setValidationProvider(ValidationProvider validationProvider)
-
getUrlParameters
public List<String> getUrlParameters()
Description copied from interface:Request
Returns a list of URL-Parameters for a JSP-page, which are those path-elements appearing after the name of the JSP-page itself. So if the page is namedcontact
and the path is/contact/europe/germany
, the resultingList
would be equal toArrays.asList("europe","germany")
.- Specified by:
getUrlParameters
in interfaceRequest
- Returns:
- the URL-Parameters for a JSP-Page
- See Also:
Path.getJspUrlParameters()
-
validateBean
public void validateBean(Object bean, FieldProcessor fp, Class<?>... groups)
Description copied from interface:ValidationProvider
Validates the given bean by adding error-messages to theFieldDef
initions, usingFieldProcessor.addErrorMessage(FieldDef, String)
.- Specified by:
validateBean
in interfaceValidationProvider
- Parameters:
bean
- the bean to validatefp
- theFieldProcessor
containing theMetaData
for the beangroups
- the JSR-303 validation groups to use- See Also:
FieldProcessor.addErrorMessage(FieldDef, String)
-
validateBean
public void validateBean(Object bean, FieldProcessor fp, String[] excludeBindings, Class<?>... groups)
Description copied from interface:ValidationProvider
Validates the given bean by adding error-messages to theFieldDef
initions, usingFieldProcessor.addErrorMessage(FieldDef, String)
.- Specified by:
validateBean
in interfaceValidationProvider
- Parameters:
bean
- the bean to validatefp
- theFieldProcessor
containing theMetaData
for the beanexcludeBindings
- an array of field-bindings to ignore during validationgroups
- the JSR-303 validation groups to use- See Also:
FieldProcessor.addErrorMessage(FieldDef, String)
-
validateField
public void validateField(Object bean, FieldProcessor fp, String fieldBinding, Class<?>... groups)
Description copied from interface:ValidationProvider
Validates a singleFieldDef
by adding error-messages to it, usingFieldProcessor.addErrorMessage(FieldDef, String)
.- Specified by:
validateField
in interfaceValidationProvider
- Parameters:
bean
- the bean to validatefp
- theFieldProcessor
containing theMetaData
for the beanfieldBinding
- the binding of theFieldDef
to validategroups
- the JSR-303 validation groups to use- See Also:
FieldProcessor.addErrorMessage(FieldDef, String)
-
addValidationMetaData
public void addValidationMetaData(MetaData metaData, ClassLoader classLoader, Class<?>... groups) throws ClassNotFoundException
Description copied from interface:ValidationProvider
Based on the JSR-303 annotations of theMetaData
's bindclass, this method adds theValidation
to theFieldDef
initions.- Specified by:
addValidationMetaData
in interfaceValidationProvider
- Parameters:
metaData
- theMetaData
to add theValidation
s toclassLoader
- theClassLoader
to load theMetaData
s bindClassgroups
- the JSR-303 validation groups to use- Throws:
ClassNotFoundException
- if the bindClass can not be loaded- See Also:
Min
,Max
,Size
,Digits
,NotNull
,Future
,Past
,Type
,Pattern
,FileUpload
-
headers
public org.springframework.http.HttpHeaders headers()
Description copied from interface:Request
Returns theHttpHeaders
for the underlyingHttpServletRequest
.
-
applicationPath
public ApplicationRequest.ApplicationPath applicationPath()
Creates a newApplicationRequest.ApplicationPath
to be used to evaluate include-conditions on a page.- Returns:
- the
ApplicationRequest.ApplicationPath
- Since:
- 1.21
- See Also:
Path.getApplicationUrlParameters()
-
-