Class Util

java.lang.Object
org.casbin.jcasbin.util.Util

public class Util extends Object
  • Field Details

    • enableLog

      public static boolean enableLog
    • evalReg

      private static Pattern evalReg
    • escapeAssertionRegex

      private static Pattern escapeAssertionRegex
    • LOGGER

      private static org.slf4j.Logger LOGGER
    • md5AlgorithmName

      private static final String md5AlgorithmName
      See Also:
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • logPrint

      public static void logPrint(String v)
      logPrint prints the log.
      Parameters:
      v - the log.
    • logPrintf

      public static void logPrintf(String format, String... v)
      logPrintf prints the log with the format.
      Parameters:
      format - the format of the log.
      v - the log.
    • logPrintfWarn

      public static void logPrintfWarn(String format, Object... v)
      logPrintf prints the log with the format as a warning.
      Parameters:
      format - the format of the log.
      v - the log.
    • logPrintfError

      public static void logPrintfError(String format, Object... v)
      logPrintf prints the log with the format as an error.
      Parameters:
      format - the format of the log.
      v - the log.
    • logPrintfError

      public static void logPrintfError(String message, Throwable t)
      logPrintf prints the log with the format as an error.
      Parameters:
      message - the message accompanying the exception
      t - the exception (throwable) to log
    • logEnforce

      public static void logEnforce(Object[] request, boolean result, List<String> explain)
      logEnforce prints the log of Enforce.
      Parameters:
      request - the Enforce request.
      result - the Enforce result.
      explain - to explain enforcement by matched rules.
    • escapeAssertion

      public static String escapeAssertion(String s)
      escapeAssertion escapes the dots in the assertion, because the expression evaluation doesn't support such variable names.
      Parameters:
      s - the value of the matcher and effect assertions.
      Returns:
      the escaped value.
    • convertInSyntax

      public static String convertInSyntax(String expString)
      convertInSyntax Convert 'in' to 'include' to fit aviatorscript,because aviatorscript don't support native 'in' syntax
      Parameters:
      expString - the value of the matcher
      Returns:
      the 'include' expression.
    • removeComments

      public static String removeComments(String s)
      removeComments removes the comments starting with # in the text.
      Parameters:
      s - a line in the model.
      Returns:
      the line without comments.
    • arrayEquals

      public static boolean arrayEquals(List<String> a, List<String> b)
      arrayEquals determines whether two string arrays are identical.
      Parameters:
      a - the first array.
      b - the second array.
      Returns:
      whether a equals to b.
    • array2DEquals

      public static boolean array2DEquals(List<List<String>> a, List<List<String>> b)
      array2DEquals determines whether two 2-dimensional string arrays are identical.
      Parameters:
      a - the first 2-dimensional array.
      b - the second 2-dimensional array.
      Returns:
      whether a equals to b.
    • arrayRemoveDuplicates

      public static List<String> arrayRemoveDuplicates(List<String> s)
      arrayRemoveDuplicates removes any duplicated elements in a string array preserving the order.
      Parameters:
      s - the array.
      Returns:
      the array without duplicates.
    • arrayToString

      public static String arrayToString(List<String> s)
      arrayToString gets a printable string for a string array.
      Parameters:
      s - the array.
      Returns:
      the string joined by the array elements.
    • paramsToString

      public static String paramsToString(String[] s)
      paramsToString gets a printable string for variable number of parameters.
      Parameters:
      s - the parameters.
      Returns:
      the string joined by the parameters.
    • splitCommaDelimited

      public static String[] splitCommaDelimited(String s)
      splitCommaDelimited splits a comma-delimited string according to the default processing method of the CSV file into a string array. It assumes that any number of whitespace might exist before or after the token and that tokens do not include whitespace as part of their value unless they are enclosed by double quotes.
      Parameters:
      s - the string.
      Returns:
      the array with the string tokens.
    • setEquals

      public static boolean setEquals(List<String> a, List<String> b)
      setEquals determines whether two string sets are identical.
      Parameters:
      a - the first set.
      b - the second set.
      Returns:
      whether a equals to b.
    • hasEval

      public static boolean hasEval(String exp)
    • replaceEval

      public static String replaceEval(String s, String replacement)
    • md5

      public static String md5(String data)
    • getDigest

      private static MessageDigest getDigest(String algorithm)
    • isJsonString

      public static boolean isJsonString(String str)
      Helper method to check if a string is a valid JSON
      Parameters:
      str - the string to be checked.
      Returns:
      whether the string is a valid