Class CssHandler
java.lang.Object
org.owasp.validator.css.CssHandler
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionCssHandler(Policy policy, List<String> errorMessages, ResourceBundle messages) Constructs a handler for stylesheets using the given policy.CssHandler(Policy policy, List<String> errorMessages, ResourceBundle messages, String tagName) Constructs a handler for stylesheets using the given policy. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidEmpties the stylesheet buffer.voidendDocument(org.w3c.css.sac.InputSource source) voidvoidendMedia(org.w3c.css.sac.SACMediaList media) voidvoidendSelector(org.w3c.css.sac.SelectorList selectors) Returns the cleaned stylesheet.Returns the error messages generated during parsing, if any.Returns a list of imported stylesheets from the main parsed stylesheet.voidignorableAtRule(String atRule) voidimportStyle(String uri, org.w3c.css.sac.SACMediaList media, String defaultNamespaceURI) voidnamespaceDeclaration(String prefix, String uri) voidvoidstartDocument(org.w3c.css.sac.InputSource arg0) voidvoidstartMedia(org.w3c.css.sac.SACMediaList media) voidvoidstartSelector(org.w3c.css.sac.SelectorList selectors)
-
Constructor Details
-
CssHandler
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 useerrorMessages- the List of error messages to add error messages too if there are errorsmessages- 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 useerrorMessages- the List of error messages to add error messages too if there are errorsmessages- the error message bundle to pull fromtagName- the tag name associated with this inline style
-
-
Method Details
-
getCleanStylesheet
-
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
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
- Specified by:
commentin interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-
ignorableAtRule
- Specified by:
ignorableAtRulein interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-
importStyle
-
namespaceDeclaration
-
startDocument
public void startDocument(org.w3c.css.sac.InputSource arg0) throws org.w3c.css.sac.CSSException - Specified by:
startDocumentin interfaceorg.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:
endDocumentin interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-
startFontFace
public void startFontFace() throws org.w3c.css.sac.CSSException- Specified by:
startFontFacein interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-
endFontFace
public void endFontFace() throws org.w3c.css.sac.CSSException- Specified by:
endFontFacein interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-
startPage
-
endPage
-
startSelector
public void startSelector(org.w3c.css.sac.SelectorList selectors) throws org.w3c.css.sac.CSSException - Specified by:
startSelectorin interfaceorg.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:
endSelectorin interfaceorg.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:
propertyin interfaceorg.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:
startMediain interfaceorg.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:
endMediain interfaceorg.w3c.css.sac.DocumentHandler- Throws:
org.w3c.css.sac.CSSException
-