Class ValidationHelper


  • public class ValidationHelper
    extends java.lang.Object
    This is a simple helper class with methods to validate strings.
    The methods provided helps validating if a string is a valid integer/real/date. It also provides a method to check if a String is empty.
    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean fixBoolean​(java.lang.String stringToValidate, boolean defaultValue)  
      static int fixInt​(java.lang.String stringToValidate, int defaultValue)  
      static java.lang.Number getValidInt​(java.lang.String value)
      Identical to isValidInt(String), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
      static java.lang.Number getValidReal​(java.lang.String value, java.util.Locale locale)
      Identical to isValidReal(String, Locale), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
      static boolean isNonEmptyString​(java.lang.String value)
      Validates that the given is not empty.
      static boolean isValidDate​(java.lang.String value, java.util.Locale locale)
      Validates that the given string value is a valid date.
      static boolean isValidDate​(java.lang.String value, java.util.Locale locale, java.util.Date min, java.util.Date max)
      Validates that the given string value is a valid date within the given range.
      static boolean isValidInt​(java.lang.String value)
      Validates that the given string value is an integer.
      static boolean isValidInt​(java.lang.String value, int min, int max)
      Validates that the given string value is an integer in the specified range.
      static boolean isValidReal​(java.lang.String value, java.util.Locale locale)
      Validates that the given string value is a valid real number.
      static boolean isValidReal​(java.lang.String value, java.util.Locale locale, double min, double max)
      Validates that the given string value is a valid real number within the given range.
      static boolean validateValueDataType​(java.lang.String value, int dataType, java.util.Locale locale)
      Validates that the given value is valid, in accordance to the data type specified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValidationHelper

        public ValidationHelper()
    • Method Detail

      • isValidInt

        public static boolean isValidInt​(java.lang.String value)
        Validates that the given string value is an integer. The value should be a non-formatted integer (i.e. no grouping of thousands), therefore the locale is not necessary. It uses Integer.parseInt to validate the value
        Parameters:
        value - a non-formated String representation of an integer.
        Returns:
        true if the string represents a valid integer.
      • getValidInt

        public static java.lang.Number getValidInt​(java.lang.String value)
                                            throws java.text.ParseException,
                                                   java.lang.IllegalArgumentException
        Identical to isValidInt(String), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
        Parameters:
        value - unvalidated value
        Returns:
        validated value
        Throws:
        java.text.ParseException - if there was a problem parsing value
        java.lang.NullPointerException - if value is null
        java.lang.IllegalArgumentException - Thrown when system default locale is null.
        Since:
        MicroStrategy Web 8.0.0
      • isValidInt

        public static boolean isValidInt​(java.lang.String value,
                                         int min,
                                         int max)
        Validates that the given string value is an integer in the specified range. The value should be a non-formatted integer (i.e. no grouping of thousands), therefore the locale is not necessary. It uses Integer.parseInt to validate the value
        Parameters:
        value - a non-formated String representation of an integer.
        min - the minimum value
        max - the max value
        Returns:
        true if the string represents a valid integer within the given range.
      • isValidReal

        public static boolean isValidReal​(java.lang.String value,
                                          java.util.Locale locale)
        Validates that the given string value is a valid real number. The value could be formatted based on the given locale. It uses a NumberFormatter to validate the value
        Parameters:
        value - a String representing a real value.
        locale - the locale in which the strings is expected to be formatted.
        Returns:
        true if the string represents a valid real.
      • getValidReal

        public static java.lang.Number getValidReal​(java.lang.String value,
                                                    java.util.Locale locale)
                                             throws java.text.ParseException,
                                                    java.lang.IllegalArgumentException
        Identical to isValidReal(String, Locale), except this returns the validated value, which may be different from the original input value since the validation procedure may strip out whitespace and other redundant symbols.
        Parameters:
        value - unvalidated value
        locale - locale
        Returns:
        validated value
        Throws:
        java.text.ParseException - if there was a problem parsing value
        java.lang.NullPointerException - if value is null
        java.lang.IllegalArgumentException - Thrown when locale is null.
        Since:
        MicroStrategy Web 8.0.0
      • isValidReal

        public static boolean isValidReal​(java.lang.String value,
                                          java.util.Locale locale,
                                          double min,
                                          double max)
        Validates that the given string value is a valid real number within the given range. The value could be formatted based on the given locale. It uses a NumberFormat to validate the value
        Parameters:
        value - a String representing a real value.
        locale - the locale in which the strings is expected to be formatted.
        min - the minimum value
        max - the max value
        Returns:
        true if the string represents a valid real.
      • isValidDate

        public static boolean isValidDate​(java.lang.String value,
                                          java.util.Locale locale)
        Validates that the given string value is a valid date. The value must be formatted based on the given locale using SHORT date format (i.e. mm/dd/yyyy). It uses a DateFormat to validate the value.
        Parameters:
        value - a String representing a date.
        locale - the locale in which the strings is expected to be formatted.
        Returns:
        true if the string represents a valid date.
      • isValidDate

        public static boolean isValidDate​(java.lang.String value,
                                          java.util.Locale locale,
                                          java.util.Date min,
                                          java.util.Date max)
        Validates that the given string value is a valid date within the given range. The value must be formatted based on the given locale using SHORT date format (i.e. mm/dd/yyyy). It uses a DateFormat to validate the value.
        Parameters:
        value - a String representing a date.
        locale - the locale in which the strings is expected to be formatted.
        min - the minimum date
        max - the maximum date
        Returns:
        true if the string represents a valid date.
      • isNonEmptyString

        public static boolean isNonEmptyString​(java.lang.String value)
        Validates that the given is not empty. It checks for null, for empty strings and for strings with only white spaces
        Parameters:
        value - the string to validate
        Returns:
        true if the string is not empty
      • validateValueDataType

        public static boolean validateValueDataType​(java.lang.String value,
                                                    int dataType,
                                                    java.util.Locale locale)
        Validates that the given value is valid, in accordance to the data type specified. Data type should be a value taken from EnumDSSXMLDataType
        Parameters:
        value - the value to validate.
        dataType - the date type used to validate the value.
        locale - locale
        Returns:
        whether the value is valid or not.
      • fixBoolean

        public static boolean fixBoolean​(java.lang.String stringToValidate,
                                         boolean defaultValue)
      • fixInt

        public static int fixInt​(java.lang.String stringToValidate,
                                 int defaultValue)