Class CssValidator

java.lang.Object
org.owasp.validator.css.CssValidator

public class CssValidator extends Object
Encapsulates all the necessary operations for validating individual elements of a stylesheet (namely: selectors, conditions, and properties).
Author:
Jason Li
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a validator for CSS selectors, conditions, and properties based on the given AntiSamy policy.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isValidCondition(String selectorName, org.w3c.css.sac.Condition condition)
    Determines whether the given condition is valid according to this validator's policy.
    boolean
    Returns whether the given CssMediaQuery is valid
    boolean
    isValidProperty(String name, org.w3c.css.sac.LexicalUnit lu)
    Determines whether the given property (both name and value) are valid according to this validator's policy.
    boolean
    isValidSelector(String selectorName, org.w3c.css.sac.Selector selector)
    Determines whether the given selector name is valid according to this validator's policy.
    lexicalValueToString(org.w3c.css.sac.LexicalUnit lu)
    Converts the given lexical unit to a String representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CssValidator

      public CssValidator(Policy policy)
      Constructs a validator for CSS selectors, conditions, and properties based on the given AntiSamy policy.
      Parameters:
      policy - the policy file to use with this validator
  • Method Details

    • isValidProperty

      public boolean isValidProperty(String name, org.w3c.css.sac.LexicalUnit lu)
      Determines whether the given property (both name and value) are valid according to this validator's policy.
      Parameters:
      name - the name of the property
      lu - the value of the property
      Returns:
      true if this property name/value is valid; false otherwise
    • isValidSelector

      public boolean isValidSelector(String selectorName, org.w3c.css.sac.Selector selector) throws ScanException
      Determines whether the given selector name is valid according to this validator's policy.
      Parameters:
      selectorName - the name of the selector
      selector - the object representation of the selector
      Returns:
      true if this selector name is valid; false otherwise
      Throws:
      ScanException - When there is a problem encountered while scanning this selector
    • isValidCondition

      public boolean isValidCondition(String selectorName, org.w3c.css.sac.Condition condition) throws ScanException
      Determines whether the given condition is valid according to this validator's policy.
      Parameters:
      selectorName - the name of the selector that contains this condition
      condition - the object representation of this condition
      Returns:
      true if this condition is valid; false otherwise
      Throws:
      ScanException - When there is a problem encountered while scanning this condition
    • lexicalValueToString

      public String lexicalValueToString(org.w3c.css.sac.LexicalUnit lu)
      Converts the given lexical unit to a String representation. This method does not perform any validation - it is meant to be used in conjunction with the validator/logging methods.
      Parameters:
      lu - the lexical unit to convert
      Returns:
      a String representation of the given lexical unit
    • isValidMediaQuery

      public boolean isValidMediaQuery(CssMediaQuery mediaQuery)
      Returns whether the given CssMediaQuery is valid
      Parameters:
      mediaQuery - mediaQuery
      Returns:
      valid mediaQuery?