Package thredds.util

Class StringValidateEncodeUtils

java.lang.Object
thredds.util.StringValidateEncodeUtils

public class StringValidateEncodeUtils extends Object
Utility methods for validating strings.
Since:
3.16.47
  • Field Details

  • Method Details

    • validSingleLineString

      public static boolean validSingleLineString(String singleLineString)
      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

      public static boolean validPath(String path)
      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

      public static boolean validFilePath(String path)
      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

      public static boolean validUriString(String uri)
      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

      public static boolean validIdString(String id)
      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

      public static boolean containsAngleBracketCharacters(String string)
      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

      public static boolean containsAmpersandCharacters(String string)
      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

      public static boolean containsBackslashCharacters(String string)
      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

      public static boolean validDecimalNumber(String number)
    • validBooleanString

      public static boolean validBooleanString(String boolString)
      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

      public static boolean validAlphanumericString(String alphNumString)
      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 strings
      ignoreCase - if true ignore the case of the letters
      Returns:
      true if the given String is an alphanumeric string.
    • descendOnlyFilePath

      public static boolean descendOnlyFilePath(String path)
      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

      public static boolean validPercentHexOctetsString(String percentHexOctetsString)
      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

      public static String unicodeCodePoint2PercentHexString(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.
      Parameters:
      codePoint - the given Unicode code point
      charsetName - 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.