Class StringUtil


  • public class StringUtil
    extends Object
    StringUtil
    Since:
    1.0.0
    Author:
    imre.scheffer, czenczl
    • Constructor Detail

      • StringUtil

        public StringUtil()
        Default constructor, constructs a new object.
    • Method Detail

      • upperCase

        public static String upperCase​(String string)
        Transforms input String to upper-case. Transforms "ß" to "ẞ".
        Parameters:
        string - input String
        Returns:
        upper-case String or null if empty input
      • encodeValue

        public static String encodeValue​(String value)
        URL encode String value.
        Parameters:
        value - String to encode
        Returns:
        URL encoded String or value if empty input or encoding error
      • maskPropertyValue

        public static String maskPropertyValue​(String key,
                                               Object value,
                                               String... keyPatterns)
        Masks value, if key ignore-case matches keyPattern.
        Parameters:
        key - The key to check against keyPattern.
        value - The value to mask
        keyPatterns - Regex array to check against
        Returns:
        "*" if key and keyPattern are not blank and key matches keyPattern (case ignored); value otherwise
      • maskValueInXmlJson

        public static String maskValueInXmlJson​(String text,
                                                String... keyPatterns)
        Masks values belonging to properties ignore-case matching keyPattern in XML or JSON texts. ie.:
        keypattern = .*?(pass).*?
        Example input-output pairs
        text result
        <pass>abc</pass> <pass>*</pass>
        <userPassword>abc</userPassword> <userPassword>*</userPassword>
        <userName>abc</userName> <userName>abc</userName>
        "pass":"abc" "pass":"*"
        "userPassword":"abc" "userPassword":"*"
        "userName":"abc" "userName":"abc"
        Parameters:
        text - XML or JSON text to replace sensitive data
        keyPatterns - The patterns to which keys are checked
        Returns:
        masked String
      • replaceAllIgnoreCase

        public static String replaceAllIgnoreCase​(String text,
                                                  String regex,
                                                  String replacement)
        Replace a regex in text. Basically the same as text.replaceAll(regex, replacement) but replace is case insensitive.
        Parameters:
        text - the text to check
        regex - the regular expression to which this string is to be matched
        replacement - the string to be substituted for each match
        Returns:
        replaced String or input text if invalid input
      • maskUriAuthenticationCredentials

        public static String maskUriAuthenticationCredentials​(String uri)
        Mask authentication credentials in URI connection string. This function replaces the "username:password" part between the "//" and "@" signs in the URI with "*:*". E.g.:
        "mongodb://username:password@localhost:12345" becomes "mongodb://*:*@localhost:12345"
        Parameters:
        uri - the uri to mask
        Returns:
        masked URI or unchanged if invalid input