Class EscapeUtil

java.lang.Object
org.jolokia.server.core.util.EscapeUtil

public final class EscapeUtil extends Object
Utility class for handling escaping of strings and paths.
Since:
15.03.11
Author:
roland
  • Field Details

    • PATH_ESCAPE

      public static final String PATH_ESCAPE
      Escape character used for path escaping as it can be used in a regexp
      See Also:
    • CSV_ESCAPE

      public static final String CSV_ESCAPE
      Escape character for escaping CSV type string as it can be used in a regexp. E.g. a backslash (\ or "\\") must be doubled (\\ or "\\\\")
      See Also:
  • Method Details

    • combineToPath

      public static String combineToPath(List<String> pParts)
      Combine a list of strings to a single path with proper escaping.
      Parameters:
      pParts - parts to combine
      Returns:
      the combined path
    • parsePath

      public static List<String> parsePath(String pPath)
      Parse a string path and return a list of split up parts.
      Parameters:
      pPath - the path to parse. Can be null
      Returns:
      list of path elements or null if the initial path is null.
    • extractElementsFromPath

      public static Stack<String> extractElementsFromPath(String pPath)
      Get the path as a reverse stack with the first element of the path on top
      Parameters:
      pPath - path to parse
      Returns:
      stack of arguments in reverse order or an empty stack if path was null or empty
    • reversePath

      public static Stack<String> reversePath(List<String> pathParts)
      Reverse path and return as a stack. First path element is on top of the stack.
      Parameters:
      pathParts - path to reverse
      Returns:
      reversed path or an empty stack if no path parts are given. Never return null.
    • split

      public static List<String> split(String pArg, String pEscape, String pDelimiter)
      Split a string on a delimiter, respecting escaping with an escape char. Assuming that a backslash (\) is used as escape char, then the following replacement rules apply:
      • \delimiter for the delimiter as literal
      • \\ for backslashes
      • \(everything else) is the same as (everything else).
      Parameters:
      pArg - argument to split
      pEscape - escape pattern as it can be used in a regular expression.
      pDelimiter - delimiter to use
      Returns:
      the split string as list or an empty array if the argument was null
    • splitAsArray

      public static String[] splitAsArray(String pArg, String pEscape, String pDelimiter)
      Split but return an array which is never null (but might be empty)
      Parameters:
      pArg - argument to split
      pEscape - single character used for escaping
      pDelimiter - delimiter to use
      Returns:
      the split string as list or an empty array if the argument was null
    • escape

      public static String escape(String pArg, String pEscape, String pDelimiter)
      Escape the delimiter in an argument with the given escape char.
      Parameters:
      pArg - string to add escapes to
      pEscape - the escape character (e.g. '\')
      pDelimiter - the delimiter to escape (e.g. ',')
      Returns:
      the escaped char
    • convertSpecialStringTags

      public static String convertSpecialStringTags(String pValue)
      For GET requests, where operation arguments and values to write are given in string representation as part of the URL, certain special tags are used to indicate special values:
      • [null] for indicating a null value
      • "" for indicating an empty string
      This method converts these tags to the proper value. If not a tag, the original value is returned. If you need this tag values in the original semantics, please use POST requests.
      Parameters:
      pValue - the string value to check for a tag
      Returns:
      the converted value or the original one if no tag has been found.