HDIV API 2.0.4

org.hdiv.filter
Class AbstractValidatorHelper

java.lang.Object
  extended by org.hdiv.filter.AbstractValidatorHelper
All Implemented Interfaces:
IValidationHelper, org.springframework.beans.factory.BeanFactoryAware
Direct Known Subclasses:
ValidatorHelperRequest, ValidatorHelperThreadLocal

public abstract class AbstractValidatorHelper
extends java.lang.Object
implements IValidationHelper, org.springframework.beans.factory.BeanFactoryAware

It validates client requests by comsuming an object of type IState and validating all the entry data, besides replacing relative values by its real values.

Since:
HDIV 2.0
Author:
Roberto Velasco, Gorka Vicente

Constructor Summary
AbstractValidatorHelper()
           
 
Method Summary
abstract  void endPage()
          Handle the storing of HDIV's state, which is done after action invocation.
 org.springframework.beans.factory.BeanFactory getBeanFactory()
           
 IDataValidator getDataValidator()
           
 HDIVConfig getHdivConfig()
           
 Logger getLogger()
           
 javax.servlet.http.HttpServletRequest getRequest()
           
 RequestWrapper getRequestWrapper()
           
 StateUtil getStateUtil()
           
 java.lang.String getTarget()
           
 void init(javax.servlet.http.HttpServletRequest request)
          Initialization of the objects needed for the validation process.
 void initTesting()
          Testing objects initilization.
 boolean isTheSameAction()
          Checks if the action received in the request is the same as the one stored in the HDIV state.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
          Callback that supplies the owning factory to a bean instance.
 void setDataValidator(IDataValidator dataValidator)
           
 void setHdivConfig(HDIVConfig hdivConfig)
           
 void setLogger(Logger logger)
           
 void setRequest(javax.servlet.http.HttpServletRequest request)
           
 void setRequestWrapper(RequestWrapper requestWrapper)
           
 void setStateUtil(StateUtil stateUtil)
           
 void setTarget(java.lang.String target)
           
 void setTargetWithoutContextPath(java.lang.String targetWithoutContextPath)
           
abstract  void startPage()
          It is called in the pre-processing stage of each user request.
 boolean validate()
          Checks if the values of the parameters received in the request request are valid.
 void validateEditableParameter(java.lang.String parameter, java.lang.String[] values, java.lang.String dataType, java.util.Hashtable unauthorizedParameters)
          Checks if the values values are valid for the editable parameter parameter.
 boolean validateHDIVSuffix(java.lang.String value)
          Checks if the suffix added in the memory version to all requests in the HDIV parameter is the same as the one stored in session, which is the original suffix.
 boolean validateRequestCookies(javax.servlet.http.Cookie[] requestCookies)
          Checks if the cookies received in the request are correct.
 boolean validateStartPageParameters()
          It validates the parameters of an init page because our application can receive requests that require validation but don't have any HDIV state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidatorHelper

public AbstractValidatorHelper()
Method Detail

init

public void init(javax.servlet.http.HttpServletRequest request)
Initialization of the objects needed for the validation process.

Specified by:
init in interface IValidationHelper
Parameters:
request - HTTP servlet request
Throws:
HDIVException - if there is an initialization error.

initTesting

public void initTesting()
Testing objects initilization.


validate

public boolean validate()
Checks if the values of the parameters received in the request request are valid. These values are valid if and only if the noneditable parameters havenīt been modified.
Validation process is as follows.
1. If the action to which the request is directed is an init page, then it is a valid request.
2. if the cookies received in the request are not found in the user session, the validation is incorrect.
3. if the state recover process has produced an error, incorrect validation.
4. If the action received in the request is different to the action of the recovered state, incorrect validation.
5. If not, all the parameter values are checked and if all the received values are valid then the request is valid.
5.1. If it is an init parameter or a HDIV parameter then it is a valid parameter.
5.2. If the received parameter is not in the state:
5.2.1. If it has been defined by the user as a no validation required parameter, then it is a valid parameter.
5.2.2. otherwise, it is a no valid request.
5.3. If the parameter is editable, if validations have been defined values are checked.
5.4. If it is a noneditable parameter, all the received values are checked.

Specified by:
validate in interface IValidationHelper
Returns:
True If all the parameter values of the request request pass the the HDIV validation. False, otherwise.
Throws:
HDIVException - If the request doesn't pass the HDIV validation an exception is thrown explaining the cause of the error.

isTheSameAction

public boolean isTheSameAction()
Checks if the action received in the request is the same as the one stored in the HDIV state.

Returns:
True if the actions are the same. False otherwise.

validateStartPageParameters

public boolean validateStartPageParameters()
It validates the parameters of an init page because our application can receive requests that require validation but don't have any HDIV state. So, despite being init pages, editable data validation must be done.

Returns:
True if the values of the editable parameters pass the validations defined in hdiv-config.xml. False otherwise.
Since:
HDIV 1.1.2

validateRequestCookies

public boolean validateRequestCookies(javax.servlet.http.Cookie[] requestCookies)
Checks if the cookies received in the request are correct. For that, it checks if they are in the user session.

Parameters:
requestCookies - cookies received in the request
Returns:
True if all the cookies received in the request are correct. They must have been previously stored in the user session by HDIV to be correct. False otherwise.
Since:
HDIV 1.1

validateEditableParameter

public void validateEditableParameter(java.lang.String parameter,
                                      java.lang.String[] values,
                                      java.lang.String dataType,
                                      java.util.Hashtable unauthorizedParameters)
Checks if the values values are valid for the editable parameter parameter. This validation is defined by the user in the hdiv-validations.xml file of Spring. If the values are not valid, an error message with the parameter and the received values will be log.

Parameters:
parameter - parameter name
values - parameter's values
dataType - editable data type
unauthorizedParameters - Unauthorized editable parameters
Since:
HDIV 1.1

validateHDIVSuffix

public boolean validateHDIVSuffix(java.lang.String value)
Checks if the suffix added in the memory version to all requests in the HDIV parameter is the same as the one stored in session, which is the original suffix. So any request using the memory version should keep the suffix unchanged.

Parameters:
value - value received in the HDIV parameter
Returns:
True if the received value of the suffix is valid. False otherwise.

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance. Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method.

Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (may not be null). The bean can immediately call methods on the factory.

getBeanFactory

public org.springframework.beans.factory.BeanFactory getBeanFactory()
Returns:
Returns the beanFactory.

getDataValidator

public IDataValidator getDataValidator()
Returns:
Returns the data validator.

setDataValidator

public void setDataValidator(IDataValidator dataValidator)
Parameters:
dataValidator - The data validator to set.

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns:
Returns the request.

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Parameters:
request - The request to set.

getTarget

public java.lang.String getTarget()
Specified by:
getTarget in interface IValidationHelper
Returns:
Returns the target.

setTarget

public void setTarget(java.lang.String target)
Specified by:
setTarget in interface IValidationHelper
Parameters:
target - The target to set.

setTargetWithoutContextPath

public void setTargetWithoutContextPath(java.lang.String targetWithoutContextPath)
Specified by:
setTargetWithoutContextPath in interface IValidationHelper
Parameters:
targetWithoutContextPath - The target without context path to set.

getRequestWrapper

public RequestWrapper getRequestWrapper()
Specified by:
getRequestWrapper in interface IValidationHelper
Returns:
Returns the uwrapper for HTTP servlet request.

getLogger

public Logger getLogger()
Returns:
Returns the user logger.

setLogger

public void setLogger(Logger logger)
Parameters:
logger - The user logger to set.

getStateUtil

public StateUtil getStateUtil()
Returns:
Returns the utility methods for state.

setStateUtil

public void setStateUtil(StateUtil stateUtil)
Parameters:
stateUtil - The state utility to set.

getHdivConfig

public HDIVConfig getHdivConfig()
Returns:
Returns the HDIV configuration object.

setHdivConfig

public void setHdivConfig(HDIVConfig hdivConfig)
Specified by:
setHdivConfig in interface IValidationHelper
Parameters:
hdivConfig - The HDIV configuration object to set.

setRequestWrapper

public void setRequestWrapper(RequestWrapper requestWrapper)
Specified by:
setRequestWrapper in interface IValidationHelper
Parameters:
request - The request to set. Only for testing

startPage

public abstract void startPage()
It is called in the pre-processing stage of each user request.

Specified by:
startPage in interface IValidationHelper

endPage

public abstract void endPage()
Handle the storing of HDIV's state, which is done after action invocation.

Specified by:
endPage in interface IValidationHelper
Parameters:
request - http request
Throws:
java.lang.Exception - if there is an error in storing process.

HDIV 2.0.4

Copyright © 2008 hdiv.org. All Rights Reserved.