public class StringValidationRule extends Object
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
allowNull |
protected List<Pattern> |
blacklistPatterns |
protected Encoder |
encoder |
protected int |
maxLength |
protected int |
minLength |
protected String |
typeName |
protected boolean |
validateInputAndCanonical |
protected List<Pattern> |
whitelistPatterns |
| Constructor and Description |
|---|
StringValidationRule(String typeName) |
StringValidationRule(String typeName,
Encoder encoder) |
StringValidationRule(String typeName,
Encoder encoder,
String whitelistPattern) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBlacklistPattern(Pattern p) |
void |
addBlacklistPattern(String pattern) |
void |
addWhitelistPattern(Pattern p) |
void |
addWhitelistPattern(String pattern) |
Encoder |
getEncoder() |
String |
getTypeName() |
String |
getValid(String context,
String input) |
boolean |
isAllowNull() |
String |
sanitize(String context,
String input) |
void |
setAllowNull(boolean allowNull) |
void |
setMaximumLength(int length) |
void |
setMinimumLength(int length) |
void |
setValidateInputAndCanonical(boolean flag)
Set the flag which determines whether the in input itself is checked as well as the canonical form of the input.
|
String |
whitelist(String input,
char[] whitelist) |
String |
whitelist(String input,
Set<Character> whitelist)
Removes characters that aren't in the whitelist from the input String.
|
protected String typeName
protected Encoder encoder
protected boolean allowNull
protected int minLength
protected int maxLength
protected boolean validateInputAndCanonical
public StringValidationRule(String typeName)
public void addWhitelistPattern(String pattern)
pattern - A String which will be compiled into a regular expression pattern to add to the whitelistIllegalArgumentException - if pattern is nullpublic void addWhitelistPattern(Pattern p)
p - A regular expression pattern to add to the whitelistIllegalArgumentException - if p is nullpublic void addBlacklistPattern(String pattern)
pattern - A String which will be compiled into a regular expression pattern to add to the blacklistIllegalArgumentException - if pattern is nullpublic void addBlacklistPattern(Pattern p)
p - A regular expression pattern to add to the blacklistIllegalArgumentException - if p is nullpublic void setMinimumLength(int length)
public void setMaximumLength(int length)
public void setValidateInputAndCanonical(boolean flag)
flag - The value to setpublic String getValid(String context, String input) throws ValidationException
ValidationExceptionpublic String whitelist(String input, Set<Character> whitelist)
input - String to be sanitizedwhitelist - allowed characterspublic String getTypeName()
public Encoder getEncoder()
public boolean isAllowNull()
public void setAllowNull(boolean allowNull)
Copyright © 2017. All rights reserved.