Class DateValidationRule
- java.lang.Object
-
- org.owasp.esapi.reference.validation.BaseValidationRule
-
- org.owasp.esapi.reference.validation.DateValidationRule
-
- All Implemented Interfaces:
ValidationRule
public class DateValidationRule extends BaseValidationRule
A validator performs syntax and possibly semantic validation of a single piece of data from an untrusted source.- Since:
- June 1, 2007
- Author:
- Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
- See Also:
Validator
-
-
Field Summary
-
Fields inherited from class org.owasp.esapi.reference.validation.BaseValidationRule
allowNull, encoder
-
-
Constructor Summary
Constructors Constructor Description DateValidationRule(java.lang.String typeName, Encoder encoder, java.text.DateFormat newFormat)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Date
getValid(java.lang.String context, java.lang.String input)
Parse the input, throw exceptions if validation failsjava.util.Date
sanitize(java.lang.String context, java.lang.String input)
The method is similar to ValidationRuile.getSafe except that it returns a harmless object that may or may not have any similarity to the original input (in some cases you may not care).java.util.Date
sanitize(java.lang.String context, java.lang.String input, ValidationErrorList errorList)
Same as sanitize(String, String) except it returns any ValidationException generated in the provided errorList.void
setDateFormat(java.text.DateFormat newFormat)
-
Methods inherited from class org.owasp.esapi.reference.validation.BaseValidationRule
assertValid, charArrayToSet, getEncoder, getSafe, getTypeName, getValid, isAllowNull, isValid, setAllowNull, setEncoder, setTypeName, whitelist, whitelist
-
-
-
-
Constructor Detail
-
DateValidationRule
public DateValidationRule(java.lang.String typeName, Encoder encoder, java.text.DateFormat newFormat)
-
-
Method Detail
-
setDateFormat
public final void setDateFormat(java.text.DateFormat newFormat)
-
getValid
public java.util.Date getValid(java.lang.String context, java.lang.String input) throws ValidationException
Parse the input, throw exceptions if validation fails- Parameters:
context
- for logginginput
- the value to be parsed- Returns:
- a validated value
- Throws:
ValidationException
- if any validation rules fail, except if theESAPI.properties
> property "Validator.ValidationRule.getValid.ignore509Fix" is set totrue
, which is the default behavior for ESAPI 2.x releases. See ESAPI GitHub Issues 521 for futher details.- See Also:
ValidationRule.getValid(String context, String input, ValidationErrorList errorList)
-
sanitize
public java.util.Date sanitize(java.lang.String context, java.lang.String input)
The method is similar to ValidationRuile.getSafe except that it returns a harmless object that may or may not have any similarity to the original input (in some cases you may not care). In most cases this should be the same as the getSafe method only instead of throwing an exception, return some default value.- Specified by:
sanitize
in classBaseValidationRule
- Returns:
- a parsed version of the input or a default value.
-
sanitize
public java.util.Date sanitize(java.lang.String context, java.lang.String input, ValidationErrorList errorList)
Same as sanitize(String, String) except it returns any ValidationException generated in the provided errorList.- Parameters:
errorList
- The error list to add any ValidationException to.- Returns:
- The valid sanitized Date, or Date(0) if the supplied input was not a valid date.
-
-