Package thredds.util
Class StringValidateEncodeUtils
java.lang.Object
thredds.util.StringValidateEncodeUtils
Utility methods for validating strings.
- Since:
- 3.16.47
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsAmpersandCharacters(String string) Return true if the given String contains any ampersand ("&") characters; otherwise return false.static booleancontainsAngleBracketCharacters(String string) Return true if the given String contains any less than ("<") or greater than (">") characters; otherwise return false.static booleancontainsBackslashCharacters(String string) Return true if the given String contains any backslash ("\") characters; otherwise return false.static booleandescendOnlyFilePath(String path) Return true if the given path does not ascend into parent directory.static StringunicodeCodePoint2PercentHexString(int codePoint, String charsetName) Return the percentHexOctets string that represents the given Unicode code point in the given character set or null if the given character set cannot encode the given code point.static booleanvalidAlphanumericString(String alphNumString) Return true if the given String is an alphanumeric string.static booleanvalidAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) Return true if the given String is an alphanumeric string and one of the valid strings in the constrained set.static booleanvalidBooleanString(String boolString) Return true if the given String is "true" or "false", ignoring case.static booleanvalidDecimalNumber(String number) static booleanvalidFilePath(String path) Return true if the given String is a valid File path.static booleanvalidIdString(String id) Return true if the given String is a valid ID string.static booleanReturn true if the given String is a valid path.static booleanvalidPercentHexOctetsString(String percentHexOctetsString) Check that the given string is a valid percentHexOctets string.static booleanvalidSingleLineString(String singleLineString) Return true if the given String is a valid single-line String.static booleanvalidUriString(String uri) Return true if the given String is a valid URI string.
-
Field Details
-
CHARACTER_ENCODING_UTF_8
- See Also:
-
-
Method Details
-
validSingleLineString
Return true if the given String is a valid single-line String.A string will be considered a valid single-line string if it does not contain any characters from these Unicode general categories:
- Cc - Other, Control
- Cf - Other, Format
- Cs - Other, Surrogate
- Co - Other, Private Use
- Cn - Other, Not Assigned
- Zl - Separator, Line
- Zp - Separator, Paragraph
Or, in other words, allow: Letters, Numbers, Marks, Punctuation, Symbols, and Space separators.
- Parameters:
singleLineString- the String to validate- Returns:
- true if the given String is a valid single-line String.
-
validPath
Return true if the given String is a valid path.A String is considered a valid path if:
- when passed to validSingleLineString(String) true is returned, and
- it does not contain any parent path segments ("../").
- Parameters:
path- the String to validate- Returns:
- true if the given String is a valid path.
- See Also:
-
validFilePath
Return true if the given String is a valid File path.A String is considered a valid File path if:
- when passed to validPath(String) true is returned; and
- it does not contain the Java File path separator (java.io.File.pathSeparatorChar) which is system dependant.
- Parameters:
path- the String to validate- Returns:
- true if the given String is a valid File path.
- See Also:
-
validUriString
Return true if the given String is a valid URI string.A String is considered a valid URI path if:
- when passed to validPath(String) true is returned; and
- ??? see Note below
NOTE: Check compliance with URI RFC (RFC 3986) - TODO.
- Parameters:
uri- the String to validate.- Returns:
- true if the given String is a valid URI string.
-
validIdString
Return true if the given String is a valid ID string.A String is considered a valid ID string if:
- it contains no space separator characters (Unicode general category Zs - Separator, Space); and
- true is returned when the string is passed to validSingleLineString(String).
- Parameters:
id- the String to validate- Returns:
- true if the given String is a valid ID string.
- See Also:
-
containsAngleBracketCharacters
Return true if the given String contains any less than ("<") or greater than (">") characters; otherwise return false.- Parameters:
string- the String to check.- Returns:
- true if the given String contains any less than ("<") or greater than (">") characters
-
containsAmpersandCharacters
Return true if the given String contains any ampersand ("&") characters; otherwise return false.- Parameters:
string- the String to check.- Returns:
- true if the given String contains any ampersand ("&") characters
-
containsBackslashCharacters
Return true if the given String contains any backslash ("\") characters; otherwise return false.- Parameters:
string- the String to check.- Returns:
- true if the given String contains any backslash ("\") characters
-
validDecimalNumber
-
validBooleanString
Return true if the given String is "true" or "false", ignoring case.- Parameters:
boolString- the String to validate.- Returns:
- true if the given String is "true" or "false", ignoring case.
-
validAlphanumericString
Return true if the given String is an alphanumeric string.- Parameters:
alphNumString- the String to validate.- Returns:
- true if the given String is an alphanumeric string.
-
validAlphanumericStringConstrainedSet
public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) Return true if the given String is an alphanumeric string and one of the valid strings in the constrained set.- Parameters:
alphNumString- the String to validate.constrainedSet- the set of valid stringsignoreCase- if true ignore the case of the letters- Returns:
- true if the given String is an alphanumeric string.
-
descendOnlyFilePath
Return true if the given path does not ascend into parent directory.- Parameters:
path- the path to check- Returns:
- true if the given path does not ascend into parent directory.
-
validPercentHexOctetsString
Check that the given string is a valid percentHexOctets string. The string is considered valid if it only contains a sequence of "%" prefixed, two character strings where each two character string is composed only of US-ASCII digits and upper- or lower-case A-F.For example: "%31%32" or "%7b%7d%7E"
- Parameters:
percentHexOctetsString- the string to check for validity- Returns:
- true if the string is valid, false otherwise.
-
unicodeCodePoint2PercentHexString
Return the percentHexOctets string that represents the given Unicode code point in the given character set or null if the given character set cannot encode the given code point.- Parameters:
codePoint- the given Unicode code pointcharsetName- the name of the character set.- Returns:
- the percentHexOctets string that represents the given Unicode code point in the given character set.
- Throws:
IllegalArgumentException- if the code point is not defined or the the character set is not supported.
-