Class StringUtil

java.lang.Object
org.broadleafcommerce.common.util.StringUtil

public class StringUtil extends Object
Convenience methods for interacting with Java String types
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • getChecksum

      public static long getChecksum(String test)
    • segmentInclusion

      public 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. 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) String
      included - the string to be sought (needle)
      Returns:
    • determineSimilarity

      public static double determineSimilarity(String test1, String test2)
    • cleanseUrlString

      public static String cleanseUrlString(String input)
      Protect against HTTP Response Splitting
      Returns:
    • decodeUrl

      public static String decodeUrl(String encodedUrl)
    • removeSpecialCharacters

      public static String removeSpecialCharacters(String input)
    • extractFieldNameFromExpression

      public static String extractFieldNameFromExpression(String expression)
      given a string with the format "fields[someFieldName].value" (very common in error validation), returns only "someFieldName
      Parameters:
      expression -
      Returns:
    • getMapAsJson

      public static String getMapAsJson(Map<String,Object> objectMap)
    • removeNonNumerics

      public static String removeNonNumerics(String value)
      Parses out non-numeric characters
      Parameters:
      value -
      Returns:
    • sanitize

      public static String sanitize(String string)
      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