public abstract class BaseValidationRule extends Object implements ValidationRule
Validator
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowNull |
protected Encoder |
encoder |
Constructor and Description |
---|
BaseValidationRule(String typeName) |
BaseValidationRule(String typeName,
Encoder encoder) |
Modifier and Type | Method and Description |
---|---|
void |
assertValid(String context,
String input)
Check if the input is valid, throw an Exception otherwise
|
static Set<Character> |
charArrayToSet(char[] array)
Convert an array of characters to a
Set<Character> (so duplicates
are removed). |
Encoder |
getEncoder() |
Object |
getSafe(String context,
String input)
Try to call
getvalid , then call a 'sanitize' method for sanitization (if one exists),
finally return a default value. |
String |
getTypeName()
Programmatically supplied name for the validator
|
Object |
getValid(String context,
String input,
ValidationErrorList errorList)
Get a validated value, add the errors to an existing error list
|
boolean |
isAllowNull() |
boolean |
isValid(String context,
String input) |
protected abstract Object |
sanitize(String context,
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).
|
void |
setAllowNull(boolean flag)
Whether or not a valid valid can be null.
|
void |
setEncoder(Encoder encoder) |
void |
setTypeName(String typeName) |
String |
whitelist(String input,
char[] whitelist)
String the input of all chars contained in the list
|
String |
whitelist(String input,
Set<Character> whitelist)
Removes characters that aren't in the whitelist from the input String.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getValid
protected boolean allowNull
protected Encoder encoder
public BaseValidationRule(String typeName)
public void setAllowNull(boolean flag)
getValid
will throw an
Exception and {#code getSafe} will return the default value if flag is set to
truesetAllowNull
in interface ValidationRule
flag
- whether or not null values are valid/safepublic String getTypeName()
getTypeName
in interface ValidationRule
public final void setTypeName(String typeName)
setTypeName
in interface ValidationRule
typeName
- a name, describing the validatorpublic final void setEncoder(Encoder encoder)
setEncoder
in interface ValidationRule
encoder
- the encoder to usepublic void assertValid(String context, String input) throws ValidationException
assertValid
in interface ValidationRule
ValidationException
public Object getValid(String context, String input, ValidationErrorList errorList) throws ValidationException
getValid
in interface ValidationRule
ValidationException
public Object getSafe(String context, String input)
getvalid
, then call a 'sanitize' method for sanitization (if one exists),
finally return a default value.getSafe
in interface ValidationRule
protected abstract Object sanitize(String context, String input)
context
- input
- public boolean isValid(String context, String input)
isValid
in interface ValidationRule
public String whitelist(String input, char[] whitelist)
whitelist
in interface ValidationRule
public String whitelist(String input, Set<Character> whitelist)
whitelist
in interface ValidationRule
input
- String to be sanitizedwhitelist
- allowed characterspublic static Set<Character> charArrayToSet(char[] array)
Set<Character>
(so duplicates
are removed).array
- The character array.Set<Character>
of the unique characters from array
is returned.public boolean isAllowNull()
public Encoder getEncoder()
Copyright © 2022 The Open Web Application Security Project (OWASP). All rights reserved.