Class RegexManager

java.lang.Object
com.smeup.kokos.sdk.util.RegexManager

public class RegexManager extends Object
Author:
mattia.bonardi
  • Field Details

  • Constructor Details

    • RegexManager

      public RegexManager()
  • Method Details

    • parseKeyValueBetweenBrackets

      public static Map<String,String> parseKeyValueBetweenBrackets(String expression)
      Parse key(value) expression NB. Nested brackets must be even This version does NOT throw exceptions - returns empty map on error (for backward compatibility)
      Parameters:
      expression - expression
      Returns:
      key value map (empty if parsing fails)
    • parseKeyValueBetweenBrackets

      public static Map<String,String> parseKeyValueBetweenBrackets(String expression, Language language)
      Parse key(value) expression NB. Nested brackets must be even
      Parameters:
      expression - expression
      language - language for error message localization (can be null)
      Returns:
      key value map
      Throws:
      LocalizableException - if brackets are unbalanced (with localized message)
    • getValueOfSpecificKeyValueBetweenBrackets

      public static String getValueOfSpecificKeyValueBetweenBrackets(String expression, String key)
      Parse single key(value) expression NB. Nested brackets must be even
      Parameters:
      expression - string to parse to extract value from specific key
      key - the 'key' from the key(value) pair involved.
      Returns:
      the 'value' of the key(value) pair involved, null if the key is missing or the brackets are left-unbalanced
    • getValueOfSpecificKeyValueBetweenBracketsRecursive

      public static String getValueOfSpecificKeyValueBetweenBracketsRecursive(String expression, List<String> keys)
      Parses a string to recursively extract a value associated with a sequence of keys, where each key(value) pair is enclosed in brackets. This method applies getValueOfSpecificKeyValueBetweenBrackets(String, String) iteratively for each key in the provided list. The value extracted for one key becomes the input string for extracting the value of the next key in the list.

      For example, if the expression is "outer(inner(value))" and the keys are ["outer", "inner"], the method will first extract "inner(value)" for the key "outer", and then extract "value" from "inner(value)" for the key "inner".

      Parameters:
      expression - The string to parse, containing key(value) expressions.
      keys - A list of keys to sequentially search for and extract values. The order of the keys in the list determines the order of extraction.
      Returns:
      The 'value' associated with the last key in the list, nested within the preceding keys' values. Returns null if any of the keys are not found in their respective expressions, or if the brackets are left-unbalanced at any stage.
    • extractCDataValue

      public static String extractCDataValue(String expression)
      Parse CDATA[value] expression
      Parameters:
      expression - expression
      Returns:
      null expression not match with CDATA
    • parseKeyValueBetweenQuotes

      public static Map<String,String> parseKeyValueBetweenQuotes(String input)
      Parse key="value" expression
      Parameters:
      input - string
      Returns:
      key value
    • parseTPKList

      public static List<FunObject> parseTPKList(String expression)
      Parse type parameter code list T() P() K();T() P() K();T() P() K()...
      Parameters:
      expression - expression
      Returns:
      key value map
    • parseVariableExpression

      public static List<String> parseVariableExpression(String expression)
      Parse variable expression: ${[VARIABLE_NAME]}
      Parameters:
      expression - expression
      Returns:
      key value map
    • parseVariableExpressionWithDefault

      public static Map<String,String> parseVariableExpressionWithDefault(String expression)
      Parse variable expression with default: ${[VARIABLE_NAME]:=[DEFAULT_VALUE]}
      Parameters:
      expression - expression
      Returns:
      key value map
    • parseSmeupVariableExpression

      public static Map<String,SmeupVariable> parseSmeupVariableExpression(String expression)
      Parse Smeup Variable expression: invalid input: '&xx'.yy
      Parameters:
      expression - expression
      Returns:
      key value map
    • parseExpressionBetweenSquareBrackets

      public static List<String> parseExpressionBetweenSquareBrackets(String input)
      Extract values between [ and ]
      Parameters:
      input - expression
      Returns:
      map
    • generateRandomString

      public static String generateRandomString(int stringLength)
      Generate random string given the length
      Parameters:
      stringLength - length
      Returns:
      string
    • findAppMatch

      public static String findAppMatch(Map<String,App> appsMap, String appKey)
    • parseProperties

      public static Map<String,String> parseProperties(String properties)
      Parse properties expression key=value;key2=value2
      Parameters:
      properties - properties string
      Returns:
      key value map
    • parseQueryParamsExpression

      public static Map<String,String> parseQueryParamsExpression(String expression)
      Parse query params expression (a=binvalid input: '&c'=d)
      Parameters:
      expression - string
      Returns:
      map
    • getObjectizedColumn

      public static String[] getObjectizedColumn(String columnObj)
      Checks whether a string is an objectified description: the object of this column has the pipe format "xxxxx|[yyyyy]", where: - xxxxx is a generic label or description, - yyyyy is the mother column. If the format is valid, returns an array with the two split elements {xxxxx, yyyyy}; otherwise, returns original string and null.
      Parameters:
      columnObj - The string to analyze.
      Returns:
      An array of two strings: {xxxxx, yyyyy} if is a valid pipe; otherwise {columnObj, null}.