|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.owasp.esapi.reference.validation.BaseValidationRule
public abstract class BaseValidationRule
A ValidationRule performs syntax and possibly semantic validation of a single piece of data from an untrusted source.
Validator
Field Summary | |
---|---|
protected boolean |
allowNull
|
protected Encoder |
encoder
|
Constructor Summary | |
---|---|
BaseValidationRule(String typeName)
|
|
BaseValidationRule(String typeName,
Encoder encoder)
|
Method Summary | |
---|---|
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 get valid, then call sanitize, 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.owasp.esapi.ValidationRule |
---|
getValid |
Field Detail |
---|
protected boolean allowNull
protected Encoder encoder
Constructor Detail |
---|
public BaseValidationRule(String typeName)
public BaseValidationRule(String typeName, Encoder encoder)
Method Detail |
---|
public void setAllowNull(boolean flag)
setAllowNull
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)
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 characters
public 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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |