Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    This class provides static utility methods for doing string processing.
    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NEWLINE  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static int compareFullServerVersion​(java.lang.String version1, java.lang.String version2)
      Compares IServer versions.
      static int compareFullServerVersionInOrder​(java.lang.String version1, java.lang.String version2)
      Compares IServer versions.
      static int compareMajorServerVersion​(java.lang.String version1, java.lang.String version2)
      Compares IServer versions.
      static int compareServerVersion​(java.lang.String version1, java.lang.String version2)
      Compares IServer versions.
      static java.lang.String escape​(java.lang.String str, java.lang.String toEscape, char escape)
      Applies escape processing to the string parameter 'str'.
      static void escape​(java.lang.String str, java.lang.String toEscape, char escape, java.lang.StringBuilder escaped)
      Applies escape processing to a string, and appends the results to a StringBuilder.
      static java.lang.String getCurrentClassName()  
      static java.lang.String getCurrentMethodName()  
      static java.lang.String getMessageIDFromSessionID​(java.lang.String sessionID)
      Deprecated.
      static java.lang.String getResultCodeFromSessionID​(java.lang.String sessionID)
      Deprecated.
      static java.lang.String getServerNameFromSessionID​(java.lang.String sessionID)
      Deprecated.
      static java.lang.String getSessionInfoFromSessionID​(java.lang.String sessionID)
      Deprecated.
      static boolean hasAsciiChars​(java.lang.String s)
      Test if a string contains any non-ascii characters
      static java.lang.String intArrayToString​(int[] intArray)
      Returns a string representation of an integer array.
      static boolean isEmpty​(java.lang.Object value)  
      static boolean isEmpty​(java.lang.String value)
      A String is considered empty if its null, or when trimmed has zero length.
      static boolean isEqual​(java.lang.Object obj1, java.lang.Object obj2)  
      static boolean isEqual​(java.lang.String str1, java.lang.String str2)
      Checks whether two strings are equal.
      static boolean isEqualIgnoreCase​(java.lang.String str1, java.lang.String str2)  
      static boolean isEqualWithEmpty​(java.lang.String str1, java.lang.String str2)
      Checks whether two strings are equal.
      static boolean isNotEmpty​(java.lang.String value)
      Checks whether the specified string is null or an empty string after trimming.
      static boolean isNotEqual​(java.lang.String str1, java.lang.String str2)
      Checks whether two string are not equal
      static java.lang.String join​(java.lang.String[] array, java.lang.String separator)
      Join an array of strings with the given separator.
      static java.lang.String mergeTokens​(java.util.StringTokenizer strTok, java.lang.String separator)
      Concatenate all tokens in the StringTokenizer and delimit them by the specified separator.
      static java.lang.String parseFirstName​(java.lang.String fullName)  
      static java.lang.String parseLastName​(java.lang.String fullName)  
      static java.lang.String removeCrlf​(java.lang.String value)
      Utility method to remove CRLF "\r", "\n" and encoded CRLF "%0a %0A %0d %0D" from the HTTP header to fix: CWE-113 : Improper Neutralization of CRLF sequences in HTTP Headers (HTTP Response splitting).
      static java.lang.String removeCrlf​(java.lang.String value, boolean isRemoveEncodedCrlf)
      Utility method to remove CRLF "\r", "\n" from the HTTP header to fix: CWE-113 : Improper Neutralization of CRLF sequences in HTTP Headers (HTTP Response splitting).
      static void replace​(java.lang.StringBuilder sb, char[] chars, java.lang.String[] replaces)
      Replaces the characters specified by the char[] with the String specified in the String[].
      static java.lang.CharSequence replace​(java.lang.String str, char[] chars, java.lang.String[] replaces)
      Replaces the characters specified by the char[] with the String specified in the String[].
      static java.lang.String replaceCharsWithStrings​(java.lang.String str, char[] chars, java.lang.String[] replaces)  
      static java.lang.String replaceFileName​(java.lang.String source)  
      static java.lang.String replaceString​(java.lang.String str, java.lang.String pattern, java.lang.String replace)
      Replaces every ocurrence of XX with YY in the passed string.
      static java.lang.String replaceStringByRegex​(java.lang.String source, java.lang.String regex, java.lang.String replacement)  
      static java.lang.String[] split​(java.lang.String str, java.lang.String delimiter)
      Split the String into a string array, according to the delimiter
      static java.util.ArrayList stringToIntArrayList​(java.lang.String str)
      Splits the specified string into tokens based on the delimiter comma and then stores them into an array list.
      static java.util.Optional<java.lang.String> toOptional​(java.lang.String value)
      A String is considered empty if it's null, or when trimmed has zero length.
      • Methods inherited from class java.lang.Object

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

      • NEWLINE

        public static final java.lang.String NEWLINE
        Since:
        MicroStrategy Web 8.1.1
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • replace

        public static void replace​(java.lang.StringBuilder sb,
                                   char[] chars,
                                   java.lang.String[] replaces)
        Replaces the characters specified by the char[] with the String specified in the String[].
        Parameters:
        sb - - Input StringBuilder.
        chars - - Array of Characters that need to be replaced.
        replaces - - Array of Strings that are replacements.
        Since:
        MicroStrategy Web 9.0.1
      • replaceFileName

        public static java.lang.String replaceFileName​(java.lang.String source)
        Since:
        MicroStrategy Web 11.1 This method is only called in Subscription to replace the file name and zip file name now.
      • replaceStringByRegex

        public static java.lang.String replaceStringByRegex​(java.lang.String source,
                                                            java.lang.String regex,
                                                            java.lang.String replacement)
        Parameters:
        source - - Input String
        regex - - RegEx String
        replacement - - String that is replacements.
        Returns:
        the modified string
        Since:
        MicroStrategy Web 11.1 Replaces the source String with the replacement String by RegEx.
      • replaceCharsWithStrings

        public static java.lang.String replaceCharsWithStrings​(java.lang.String str,
                                                               char[] chars,
                                                               java.lang.String[] replaces)
        Since:
        MicroStrategy Web 9.0.0
      • replace

        public static java.lang.CharSequence replace​(java.lang.String str,
                                                     char[] chars,
                                                     java.lang.String[] replaces)
        Replaces the characters specified by the char[] with the String specified in the String[].
        Parameters:
        str - - Input String.
        chars - - Array of Characters that need to be replaced.
        replaces - - Array of Strings that are replacements.
        Returns:
        the original String or a StringBuilder if we replaced any characters.
        Since:
        MicroStrategy Web 9.0.1
      • replaceString

        public static java.lang.String replaceString​(java.lang.String str,
                                                     java.lang.String pattern,
                                                     java.lang.String replace)
        Replaces every ocurrence of XX with YY in the passed string. The various replace functions in String are recommended over this legacy function (which preceded the String functions). This method will be deprecated at some point.
        Parameters:
        str - the string on which to perform the replacement
        pattern - the substring to replace(XX) - note that this is NOT a regular expression
        replace - the replacement substring(YY)
        Returns:
        the modified string
      • getServerNameFromSessionID

        @Deprecated
        public static java.lang.String getServerNameFromSessionID​(java.lang.String sessionID)
        Deprecated.
        Strips and returns the Intelligence Server name from the session ID passed in. This method is deprecated. Instead, use static method IDSSXMLSessionParser.getIServerNodeName()
        Parameters:
        sessionID - an Intelligence Server session ID.
        Returns:
        the Intelligence Server name.
        Throws:
        java.lang.IllegalArgumentException - thrown if the session ID is invalid.
        Since:
        MicroStrategy Web 8.0.0
      • getMessageIDFromSessionID

        @Deprecated
        public static java.lang.String getMessageIDFromSessionID​(java.lang.String sessionID)
        Deprecated.
        Strips and returns the messageID from the session ID passed in. This method is deprecated. Instead, use static method IDSSXMLSessionParser.getMessageId()
        Parameters:
        sessionID - an Intelligence Server session ID.
        Returns:
        the message ID.
      • getResultCodeFromSessionID

        @Deprecated
        public static java.lang.String getResultCodeFromSessionID​(java.lang.String sessionID)
        Deprecated.
        Strips and returns the result code from the session ID passed in. This method is deprecated. Instead, use static method IDSSXMLSessionParser.getRetVal()
        Parameters:
        sessionID - an Intelligence Server session ID.
        Returns:
        the result code.
      • getSessionInfoFromSessionID

        @Deprecated
        public static java.lang.String getSessionInfoFromSessionID​(java.lang.String sessionID)
        Deprecated.
        Strips and returns the session info without message id and result code from the session ID passed in. This method is deprecated. There should be no reason to extract the session info in this way. The contents of the string are undefined and you should make no assumptions of the contents. Instead, use IDSSXMLSessionParser and its methods to extract different parts of the information.
        Parameters:
        sessionID - an Intelligence Server session ID.
        Returns:
        the session info without message id and result code.
      • split

        public static java.lang.String[] split​(java.lang.String str,
                                               java.lang.String delimiter)
        Split the String into a string array, according to the delimiter
        Parameters:
        str - the string on which to perform the spliting.
        delimiter - the delimiter string.
        Returns:
        an array of string.
      • compareMajorServerVersion

        public static int compareMajorServerVersion​(java.lang.String version1,
                                                    java.lang.String version2)
        Compares IServer versions. This method assumes that you are comparing 2 release versions and not intermediate builds. Therefore it only bases its comparison on the major release. returns 1 if version1 > version 2 returns -1 if version2 > version 1 returns 0 if they are identical
        Parameters:
        version1 - MicroStrategy Intelligence Server version string.
        version2 - MicroStrategy Intelligence Server version string.
        Returns:
        whether two major server versions have the same release number
      • compareServerVersion

        public static int compareServerVersion​(java.lang.String version1,
                                               java.lang.String version2)
        Compares IServer versions. This method assumes that you are comparing 2 release versions and not intermediate builds. Therefore it only bases its comparison on the major release, minor release and revision 2 numbers. It does not care about revision 1. returns 1 if version1 > version 2 returns -1 if version2 > version 1 returns 0 if they are identical
        Parameters:
        version1 - MicroStrategy Intelligence Server version string.
        version2 - MicroStrategy Intelligence Server version string.
        Returns:
        whether two server versions have the same release number
        See Also:
        compareFullServerVersion(String, String)
      • compareFullServerVersion

        public static int compareFullServerVersion​(java.lang.String version1,
                                                   java.lang.String version2)
        Compares IServer versions. Takes into account intermediate builds. Version structure: major.minor.release1.release2. Precendence is as follows: major, minor, release 2, release 1. Note that release 2 takes precedence over release 1. Returns 1 if version1 is higher than version2, -1 if version2 is higher, and 0 if they are equals.
        Parameters:
        version1 - MicroStrategy Intelligence Server version string.
        version2 - MicroStrategy Intelligence Server version string.
        Returns:
        whether two server versions have the same release number
        Since:
        MicroStrategy Web 8.1.0
        See Also:
        compareServerVersion(String, String)
      • compareFullServerVersionInOrder

        public static int compareFullServerVersionInOrder​(java.lang.String version1,
                                                          java.lang.String version2)
        Compares IServer versions. Takes into account intermediate builds. Version structure: major.minor.release1.release2. Precendence is as follows: major, minor, release 1, release 2. Returns 1 if version1 is higher than version2, -1 if version2 is higher, and 0 if they are equals.
        Parameters:
        version1 - MicroStrategy Intelligence Server version string.
        version2 - MicroStrategy Intelligence Server version string.
        Returns:
        whether two server versions have the same release number
        See Also:
        compareFullServerVersionInOrder(String, String)
      • intArrayToString

        public static java.lang.String intArrayToString​(int[] intArray)
        Returns a string representation of an integer array. All integer array elements are concatenated into a string and are delimited by a comma.
        Parameters:
        intArray - an integer array.
        Returns:
        the string representation of an integer array.
        Since:
        MicroStrategy Web 8.0.0
      • stringToIntArrayList

        public static java.util.ArrayList stringToIntArrayList​(java.lang.String str)
        Splits the specified string into tokens based on the delimiter comma and then stores them into an array list.
        Parameters:
        str - a string delimited by comma.
        Returns:
        an array list over the string tokens delimited by comma.
        Since:
        MicroStrategy Web 8.0.0
      • isEmpty

        public static boolean isEmpty​(java.lang.String value)

        A String is considered empty if its null, or when trimmed has zero length.

        Parameters:
        value - String to test
        Returns:
        whether String is empty
        Since:
        MicroStrategy Web 7.5.1
      • toOptional

        public static java.util.Optional<java.lang.String> toOptional​(java.lang.String value)

        A String is considered empty if it's null, or when trimmed has zero length.

        Parameters:
        value - String to test
        Returns:
        Optional.empty if String is empty, otherwise the String wrapped by Optional
      • isEmpty

        public static boolean isEmpty​(java.lang.Object value)
        Returns:
        whether value object is null, or if it's a string then resolve as isEmpty(String)
        Since:
        MicroStrategy Web 9.0.0
      • isNotEmpty

        public static boolean isNotEmpty​(java.lang.String value)
        Checks whether the specified string is null or an empty string after trimming.
        Parameters:
        value - the string to check.
        Returns:
        true if the specified string is not null and not empty after trimming white space.
        Since:
        MicroStrategy Web 7.5.3
      • isEqual

        public static boolean isEqual​(java.lang.String str1,
                                      java.lang.String str2)
        Checks whether two strings are equal. Note that a null string and one with only white space are considered NOT the same.
        Parameters:
        str1 - the first string to check equality
        str2 - the second string to check equality
        Returns:
        true if the two strings are the same (null and white space strings are considered different).
        Since:
        MicroStrategy Web 8.0.0
        See Also:
        isEqualWithEmpty(String, String)
      • isEqual

        public static boolean isEqual​(java.lang.Object obj1,
                                      java.lang.Object obj2)
        Since:
        MicroStrategy Web 9.0.0
      • isEqualIgnoreCase

        public static boolean isEqualIgnoreCase​(java.lang.String str1,
                                                java.lang.String str2)
        Since:
        MicroStrategy Web 8.1.0
      • isEqualWithEmpty

        public static boolean isEqualWithEmpty​(java.lang.String str1,
                                               java.lang.String str2)
        Checks whether two strings are equal. Also checks for isEmpty(String) equivalence, i.e. a null string and one with only white space are considered also equal.
        Parameters:
        str1 - the first string to check equality
        str2 - the second string to check equality
        Returns:
        true if the two strings are the same (null and white space strings are considered the same).
        Since:
        MicroStrategy Web 8.1.0
        See Also:
        isEqual(String, String)
      • isNotEqual

        public static boolean isNotEqual​(java.lang.String str1,
                                         java.lang.String str2)
        Checks whether two string are not equal
        Parameters:
        str1 - the first string to check equality
        str2 - the second string to check equality
        Returns:
        true if the two strings are not equal.
        Since:
        MicroStrategy Web 8.0.0
      • mergeTokens

        public static java.lang.String mergeTokens​(java.util.StringTokenizer strTok,
                                                   java.lang.String separator)
        Concatenate all tokens in the StringTokenizer and delimit them by the specified separator.
        Parameters:
        strTok - a StringTokenizer containing string tokens
        separator - the delimiter to separate strings
        Returns:
        a string containing all the tokens from the StringTokenizer but delimited by the specified separator.
        Since:
        MicroStrategy Web 8.0.0
      • escape

        public static java.lang.String escape​(java.lang.String str,
                                              java.lang.String toEscape,
                                              char escape)

        Applies escape processing to the string parameter 'str'. If any characters in 'str' contains any of the escapable characters defined in parameter 'toEscape', they are prefixed by the escape character specified. By default, the escape character does not escape itself - if this is desired, please ensure it's in the 'toEscape' string.

        Parameters:
        str - the original string
        toEscape - characters to escape
        escape - the escape character
        Returns:
        the escaped string
        Since:
        MicroStrategy Web 9.0.1
      • escape

        public static void escape​(java.lang.String str,
                                  java.lang.String toEscape,
                                  char escape,
                                  java.lang.StringBuilder escaped)

        Applies escape processing to a string, and appends the results to a StringBuilder.

        Parameters:
        escaped - Escaped string of 'str'
        Since:
        MicroStrategy Web 9.0.1
        See Also:
        escape(String, String, char)
      • hasAsciiChars

        public static boolean hasAsciiChars​(java.lang.String s)

        Test if a string contains any non-ascii characters

        Parameters:
        s - A non-empty string
        Returns:
        whether it contains non-ascii characters
        Since:
        MicroStrategy Web 9.0.2
      • parseFirstName

        public static java.lang.String parseFirstName​(java.lang.String fullName)
      • parseLastName

        public static java.lang.String parseLastName​(java.lang.String fullName)
      • getCurrentMethodName

        public static java.lang.String getCurrentMethodName()
      • getCurrentClassName

        public static java.lang.String getCurrentClassName()
      • join

        public static java.lang.String join​(java.lang.String[] array,
                                            java.lang.String separator)
        Join an array of strings with the given separator.

        Note: This might be replaced by utility method from commons-lang or guava someday if one of those libraries is added as dependency.

        Parameters:
        array - The array of strings
        separator - The separator
        Returns:
        the resulting string
      • removeCrlf

        public static java.lang.String removeCrlf​(java.lang.String value)
        Utility method to remove CRLF "\r", "\n" and encoded CRLF "%0a %0A %0d %0D" from the HTTP header to fix: CWE-113 : Improper Neutralization of CRLF sequences in HTTP Headers (HTTP Response splitting). Used by com.microstrategy.web.app.utils.HTTPHelper. For encoded CRLF "%0a %0A %0d %0D"
        Parameters:
        value - HTTP header value which has CRLF characters.
        Returns:
        an String without CRLF characters.
        See Also:
        removeCrlf(String value, boolean isRemoveEncodedCrlf)
      • removeCrlf

        public static java.lang.String removeCrlf​(java.lang.String value,
                                                  boolean isRemoveEncodedCrlf)
        Utility method to remove CRLF "\r", "\n" from the HTTP header to fix: CWE-113 : Improper Neutralization of CRLF sequences in HTTP Headers (HTTP Response splitting). If isRemoveEncodedCrlf is true, method will also remove encoded CRLF %0a %0A %0d %0D.
        Parameters:
        value - HTTP header value which has CRLF characters.
        isRemoveEncodedCrlf - a boolean whether to remove encoded CRLF (%0a %0A %0d %0D), it is true by default.
        Returns:
        an String without CRLF characters.