Class CssHandler

java.lang.Object
org.owasp.validator.css.CssHandler
All Implemented Interfaces:
org.w3c.css.sac.DocumentHandler

public class CssHandler extends Object implements org.w3c.css.sac.DocumentHandler
A implementation of a SAC DocumentHandler for CSS validation. The appropriate validation method is called whenever the handler is invoked by the parser. The handler also builds a clean CSS document as the original CSS is scanned.

NOTE: keeping state in this class is not ideal as handler style parsing a la SAX should generally be event driven. However, there is not a fully implemented "DOM" equivalent to CSS at this time. Java has a StyleSheet class that could accomplish this "DOM" like behavior but it has yet to be fully implemented.

Author:
Jason Li
See Also:
  • Constructor Details

    • CssHandler

      public CssHandler(Policy policy, List<String> errorMessages, ResourceBundle messages)
      Constructs a handler for stylesheets using the given policy. The List of embedded stylesheets produced by this constructor is now available via the getImportedStylesheetsURIList() method. This constructor to be used when there is no tag name associated with this inline style.
      Parameters:
      policy - the policy to use
      errorMessages - the List of error messages to add error messages too if there are errors
      messages - the error message bundle to pull from
    • CssHandler

      public CssHandler(Policy policy, List<String> errorMessages, ResourceBundle messages, String tagName)
      Constructs a handler for stylesheets using the given policy. The List of embedded stylesheets produced by this constructor is available via the getImportedStylesheetsURIList() method.
      Parameters:
      policy - the policy to use
      errorMessages - the List of error messages to add error messages too if there are errors
      messages - the error message bundle to pull from
      tagName - the tag name associated with this inline style
  • Method Details

    • getCleanStylesheet

      public String getCleanStylesheet()
      Returns the cleaned stylesheet.
      Returns:
      the cleaned stylesheet.
    • getImportedStylesheetsURIList

      public LinkedList<URI> getImportedStylesheetsURIList()
      Returns a list of imported stylesheets from the main parsed stylesheet.
      Returns:
      the import stylesheet URI list.
    • emptyStyleSheet

      public void emptyStyleSheet()
      Empties the stylesheet buffer.
    • getErrorMessages

      public Collection<String> getErrorMessages()
      Returns the error messages generated during parsing, if any. Note: the lack of error messages does not mean the HTML input being sanitized can be considered safe.
      Returns:
      the error messages generated during parsing
    • comment

      public void comment(String text) throws org.w3c.css.sac.CSSException
      Specified by:
      comment in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • ignorableAtRule

      public void ignorableAtRule(String atRule) throws org.w3c.css.sac.CSSException
      Specified by:
      ignorableAtRule in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • importStyle

      public void importStyle(String uri, org.w3c.css.sac.SACMediaList media, String defaultNamespaceURI) throws org.w3c.css.sac.CSSException
      Specified by:
      importStyle in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • namespaceDeclaration

      public void namespaceDeclaration(String prefix, String uri) throws org.w3c.css.sac.CSSException
      Specified by:
      namespaceDeclaration in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • startDocument

      public void startDocument(org.w3c.css.sac.InputSource arg0) throws org.w3c.css.sac.CSSException
      Specified by:
      startDocument in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • endDocument

      public void endDocument(org.w3c.css.sac.InputSource source) throws org.w3c.css.sac.CSSException
      Specified by:
      endDocument in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • startFontFace

      public void startFontFace() throws org.w3c.css.sac.CSSException
      Specified by:
      startFontFace in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • endFontFace

      public void endFontFace() throws org.w3c.css.sac.CSSException
      Specified by:
      endFontFace in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • startPage

      public void startPage(String name, String pseudoPage) throws org.w3c.css.sac.CSSException
      Specified by:
      startPage in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • endPage

      public void endPage(String name, String pseudoPage) throws org.w3c.css.sac.CSSException
      Specified by:
      endPage in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • startSelector

      public void startSelector(org.w3c.css.sac.SelectorList selectors) throws org.w3c.css.sac.CSSException
      Specified by:
      startSelector in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • endSelector

      public void endSelector(org.w3c.css.sac.SelectorList selectors) throws org.w3c.css.sac.CSSException
      Specified by:
      endSelector in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • property

      public void property(String name, org.w3c.css.sac.LexicalUnit value, boolean important) throws org.w3c.css.sac.CSSException
      Specified by:
      property in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • startMedia

      public void startMedia(org.w3c.css.sac.SACMediaList media) throws org.w3c.css.sac.CSSException
      Specified by:
      startMedia in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException
    • endMedia

      public void endMedia(org.w3c.css.sac.SACMediaList media) throws org.w3c.css.sac.CSSException
      Specified by:
      endMedia in interface org.w3c.css.sac.DocumentHandler
      Throws:
      org.w3c.css.sac.CSSException