Class CssVariableUtil

java.lang.Object
com.itextpdf.styledxmlparser.util.CssVariableUtil

public class CssVariableUtil extends Object
Utility class for resolving css variables in declarations.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • MAX_CSS_VAR_COUNT

      private static final int MAX_CSS_VAR_COUNT
      Max count of css var expressions in single declaration.
      See Also:
  • Constructor Details

    • CssVariableUtil

      private CssVariableUtil()
  • Method Details

    • resolveCssVariables

      public static void resolveCssVariables(Map<String,String> styles)
      Resolve all css variables in style map
      Parameters:
      styles - css styles map
    • containsVarExpression

      public static boolean containsVarExpression(String expression)
      Checks for var expression.
      Parameters:
      expression - css expression to check
      Returns:
      true if there is a var expression, false otherwise
    • isCssVariable

      public static boolean isCssVariable(String property)
      Checks property for css variable.
      Parameters:
      property - css property to check
      Returns:
      true if it is a css variable, false otherwise
    • expandShorthand

      private static List<CssDeclaration> expandShorthand(CssDeclaration declaration)
    • resolveSingleVar

      private static CssDeclaration resolveSingleVar(String key, String expression, Map<String,String> styles)
      Resolve single css var expression recursively
      Parameters:
      key - css style property
      expression - css expression
      styles - css styles map
      Returns:
      resolved var expression if present or null if none found
    • resolveVarRecursively

      private static String resolveVarRecursively(String expression, Map<String,String> styles, int level)
      Resolves variables without taking into account default values
      Parameters:
      expression - var value
      styles - element styles
      level - current var expression nesting level
      Returns:
      resolved var expression
    • resolveVarExpression

      private static String resolveVarExpression(String varExpression, Map<String,String> styles)
      Resolve css variable expression, if there is a fallback value and primary value is null, default value will be returned.
      Parameters:
      varExpression - expression as the following: var(.+?(?:,.*?)?)
      styles - map of styles containing resolved variables
      Returns:
      resolved var expression