Class StringUtil
- java.lang.Object
-
- hu.icellmobilsoft.coffee.tool.utils.string.StringUtil
-
public class StringUtil extends Object
StringUtil- Since:
- 1.0.0
- Author:
- imre.scheffer, czenczl
-
-
Constructor Summary
Constructors Constructor Description StringUtil()Default constructor, constructs a new object.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringencodeValue(String value)URL encodeStringvalue.static StringmaskPropertyValue(String key, Object value, String... keyPatterns)Masks value, if key ignore-case matches keyPattern.static StringmaskUriAuthenticationCredentials(String uri)Mask authentication credentials in URI connection string.static StringmaskValueInXmlJson(String text, String... keyPatterns)Masks values belonging to properties ignore-case matching keyPattern in XML or JSON texts.static StringreplaceAllIgnoreCase(String text, String regex, String replacement)Replace a regex in text.static StringupperCase(String string)Transforms inputStringto upper-case.
-
-
-
Method Detail
-
upperCase
public static String upperCase(String string)
Transforms inputStringto upper-case. Transforms "ß" to "ẞ".- Parameters:
string- inputString- Returns:
- upper-case
Stringor null if empty input
-
encodeValue
public static String encodeValue(String value)
URL encodeStringvalue.- Parameters:
value-Stringto encode- Returns:
- URL encoded
Stringorvalueif 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 maskkeyPatterns- 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 datakeyPatterns- 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 astext.replaceAll(regex, replacement)but replace is case insensitive.- Parameters:
text- the text to checkregex- the regular expression to which this string is to be matchedreplacement- the string to be substituted for each match- Returns:
- replaced
Stringor inputtextif 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
-
-