Class StringUtil
java.lang.Object
org.broadleafcommerce.common.util.StringUtil
Convenience methods for interacting with Java String types
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
cleanseUrlString
(String input) Protect against HTTP Response Splittingstatic String
static double
determineSimilarity
(String test1, String test2) static String
extractFieldNameFromExpression
(String expression) given a string with the format "fields[someFieldName].value" (very common in error validation), returns only "someFieldNamestatic long
getChecksum
(String test) static String
getMapAsJson
(Map<String, Object> objectMap) static String
removeNonNumerics
(String value) Parses out non-numeric charactersstatic String
removeSpecialCharacters
(String input) static String
Utility method for sanitizing a String to neutralize any possible malicious content.static boolean
segmentInclusion
(String bigger, String included) Checks if a string is included in the beginning of another string, but only in dot-separated segment leaps.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
getChecksum
-
segmentInclusion
Checks if a string is included in the beginning of another string, but only in dot-separated segment leaps. Examples:- "sku.date" into "sku.dateExtra" should return false
- "sku.date" into "sku.date.extra" should return true
- "sku" into "sku" should return true
This function avoids "collision" between similarly named, multi-leveled property fields.
- Parameters:
bigger
- the bigger (haystack) Stringincluded
- the string to be sought (needle)- Returns:
-
determineSimilarity
-
cleanseUrlString
Protect against HTTP Response Splitting- Returns:
-
decodeUrl
-
removeSpecialCharacters
-
extractFieldNameFromExpression
given a string with the format "fields[someFieldName].value" (very common in error validation), returns only "someFieldName- Parameters:
expression
-- Returns:
-
getMapAsJson
-
removeNonNumerics
Parses out non-numeric characters- Parameters:
value
-- Returns:
-
sanitize
Utility method for sanitizing a String to neutralize any possible malicious content. This is used primarily to protect log messages by encoding for any possible forgery or injection attempts.Given an Object of type Integer or Long, converts the Object instance to a Long. This will throw a ClassCastException if the past parameter is not either an Integer or a Long.
- Parameters:
string
-- Returns:
- String
-