Interface CSSStyleSheet<R extends CSSRule>
- All Superinterfaces:
org.w3c.dom.css.CSSStyleSheet
,org.w3c.dom.stylesheets.StyleSheet
- All Known Subinterfaces:
DocumentCSSStyleSheet
- All Known Implementing Classes:
AbstractCSSStyleSheet
,BaseCSSStyleSheet
,BaseDocumentCSSStyleSheet
,DOMCSSStyleSheet
,DOMDocumentCSSStyleSheet
This extension to the W3C interface adds utility as well as factory methods. The factory methods create rules that have the same origin specificity (like 'author' or 'user') as this style sheet.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final short
When parsing a sheet, comments found before a rule may be assigned to the previous rule if a newline character was not found between that rule and the comment, otherwise shall be set as preceding the next rule.static final short
Ignore all comments when parsing a sheet.static final short
When parsing a sheet, all comments found before a rule will be considered as belonging to that rule. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts a rule in the current insertion point (generally after the last rule).void
Adds the rules contained by the supplied style sheet, if that sheet is not disabled.clone()
Clone this style sheet.createCounterStyleRule
(String name) Create a CSSCounterStyleRule compatible with this implementation.Create a CSS Font Face rule compatible with this implementation.createFontFeatureValuesRule
(String[] fontFamily) Create a CSSFontFeatureValuesRule compatible with this implementation.org.w3c.dom.css.CSSImportRule
createImportRule
(MediaQueryList mediaList, String href) Create a CSS import rule compatible with this implementation.createKeyframesRule
(String keyframesName) Create a CSSKeyframesRule compatible with this implementation.createMarginRule
(String name) Create a CSS margin rule compatible with this implementation.createMediaRule
(MediaQueryList mediaList) Create a CSS media rule.createNamespaceRule
(String prefix, String namespaceUri) Create a CSS namespace rule compatible with this implementation.Create a CSS page rule compatible with this implementation.createPropertyRule
(String name) Create a CSS property rule compatible with this implementation.Create a CSS style declaration compatible with this implementation.Create a CSS style rule.Create a CSSSupportsRule compatible with this implementation.org.w3c.dom.css.CSSUnknownRule
Create a CSS unknown rule.Create a CSSViewportRule compatible with this implementation.Gets the collection of all CSS rules contained within the style sheet.Gets the error handler for this style sheet.getMedia()
Get the destination media for this sheet.CSSRuleList<? extends CSSRule>
getRulesForProperty
(String longhandPropertyName) Returns a list of rules that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Selector[]
getSelectorsForProperty
(String longhandPropertyName) Returns an array of selectors that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Get the style sheet factory used to produce this sheet.boolean
Check whether this sheet contains rules that have errors or warnings reported to their handlers.boolean
parseStyleSheet
(Reader reader) Parses a source into this style sheet.boolean
parseStyleSheet
(Reader reader, short commentMode) Parses a style sheet.Methods inherited from interface org.w3c.dom.css.CSSStyleSheet
deleteRule, getOwnerRule, insertRule
Methods inherited from interface org.w3c.dom.stylesheets.StyleSheet
getDisabled, getHref, getOwnerNode, getParentStyleSheet, getTitle, getType, setDisabled
-
Field Details
-
COMMENTS_IGNORE
static final short COMMENTS_IGNOREIgnore all comments when parsing a sheet.- See Also:
-
COMMENTS_PRECEDING
static final short COMMENTS_PRECEDINGWhen parsing a sheet, all comments found before a rule will be considered as belonging to that rule.- See Also:
-
COMMENTS_AUTO
static final short COMMENTS_AUTOWhen parsing a sheet, comments found before a rule may be assigned to the previous rule if a newline character was not found between that rule and the comment, otherwise shall be set as preceding the next rule.- See Also:
-
-
Method Details
-
addRule
Inserts a rule in the current insertion point (generally after the last rule).- Parameters:
cssrule
- the rule to be inserted.- Throws:
DOMException
- NAMESPACE_ERR if the rule could not be added due to a namespace-related error.
-
addStyleSheet
Adds the rules contained by the supplied style sheet, if that sheet is not disabled.If the provided sheet does not target all media, a media rule is created.
- Parameters:
sheet
- the sheet whose rules are to be added.
-
getCssRules
CSSRuleList<R> getCssRules()Gets the collection of all CSS rules contained within the style sheet.- Specified by:
getCssRules
in interfaceorg.w3c.dom.css.CSSStyleSheet
- Returns:
- the list of all CSS rules contained within the style sheet.
-
getMedia
MediaQueryList getMedia()Get the destination media for this sheet.- Specified by:
getMedia
in interfaceorg.w3c.dom.stylesheets.StyleSheet
- Returns:
- the media query list.
-
clone
CSSStyleSheet<R> clone()Clone this style sheet.- Returns:
- the cloned style sheet.
-
createCounterStyleRule
Create a CSSCounterStyleRule compatible with this implementation.- Parameters:
name
- the counter-style name.- Returns:
- a CSSCounterStyleRule object.
- Throws:
DOMException
- if the name is invalid.
-
createFontFaceRule
CSSFontFaceRule createFontFaceRule()Create a CSS Font Face rule compatible with this implementation.- Returns:
- a CSS Font Face rule object.
-
createFontFeatureValuesRule
Create a CSSFontFeatureValuesRule compatible with this implementation.- Parameters:
fontFamily
- the font family.- Returns:
- a CSSFontFeatureValuesRule object.
-
createImportRule
Create a CSS import rule compatible with this implementation.- Parameters:
mediaList
- a list of media types for which the new import rule may be used.href
- the URI from which to import the sheet.- Returns:
- a CSS import rule.
-
createKeyframesRule
Create a CSSKeyframesRule compatible with this implementation.- Parameters:
keyframesName
- the name of the keyframes.- Returns:
- a CSSKeyframesRule object.
- Throws:
DOMException
- if the name is invalid.
-
createMarginRule
Create a CSS margin rule compatible with this implementation.- Parameters:
name
- the margin rule name.- Returns:
- a CSS margin rule.
-
createMediaRule
Create a CSS media rule.- Parameters:
mediaList
- a list of media types for the new rule.- Returns:
- a CSS media rule.
-
createNamespaceRule
Create a CSS namespace rule compatible with this implementation.- Parameters:
prefix
- the namespace prefix.namespaceUri
- the namespace URI.- Returns:
- a CSS namespace rule.
- Throws:
DOMException
- INVALID_ACCESS_ERR: if the prefix or the URI are null.
-
createPageRule
CSSPageRule createPageRule()Create a CSS page rule compatible with this implementation.- Returns:
- a CSS page rule.
-
createPropertyRule
Create a CSS property rule compatible with this implementation.- Parameters:
name
- the (unescaped) property name.- Returns:
- a CSS property rule.
-
createStyleRule
CSSStyleRule createStyleRule()Create a CSS style rule.- Returns:
- a CSS style rule.
-
createSupportsRule
CSSSupportsRule createSupportsRule()Create a CSSSupportsRule compatible with this implementation.- Returns:
- a CSSSupportsRule object.
-
createViewportRule
CSSDeclarationRule createViewportRule()Create a CSSViewportRule compatible with this implementation.- Returns:
- a CSSViewportRule object.
-
createStyleDeclaration
CSSStyleDeclaration createStyleDeclaration()Create a CSS style declaration compatible with this implementation.- Returns:
- a CSS style declaration.
-
createUnknownRule
org.w3c.dom.css.CSSUnknownRule createUnknownRule()Create a CSS unknown rule.Its contents can be set with
CSSRule.setCssText(String)
. Be careful to set a text that is compatible with a CSS rule, with an ending semicolon or balanced curly brackets, otherwise its serialization may break the style sheet serialization.- Returns:
- a CSS unknown rule.
-
getErrorHandler
SheetErrorHandler getErrorHandler()Gets the error handler for this style sheet.- Returns:
- the error handler.
-
hasRuleErrorsOrWarnings
boolean hasRuleErrorsOrWarnings()Check whether this sheet contains rules that have errors or warnings reported to their handlers.- Returns:
true
if this sheet contains rules that have errors or warnings.
-
getRulesForProperty
Returns a list of rules that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Grouping rules are scanned too, regardless of the medium or condition.
- Parameters:
longhandPropertyName
- the longhand property name.- Returns:
- the list of rules, or
null
if no rules declare that property, or the property is a shorthand.
-
getSelectorsForProperty
Returns an array of selectors that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Grouping rules are scanned too, regardless of the medium or condition.
- Parameters:
longhandPropertyName
- the longhand property name.- Returns:
- the array of selectors, or
null
if no rules declare that property, or the property is a shorthand.
-
getStyleSheetFactory
CSSStyleSheetFactory getStyleSheetFactory()Get the style sheet factory used to produce this sheet.- Returns:
- the style sheet factory.
-
parseStyleSheet
Parses a source into this style sheet.If this style sheet is not empty, the rules from the parsed source will be added at the end of the rule list.
The comments shall be processed according to
COMMENTS_AUTO
.- Parameters:
reader
- the character stream containing the CSS sheet.- Returns:
true
if the NSAC parser reported no errors or fatal errors,false
otherwise.- Throws:
DOMException
- if a DOM problem is found parsing the sheet.CSSException
- if a non-DOM problem is found parsing the sheet.IOException
- if a problem is found reading the sheet.
-
parseStyleSheet
Parses a style sheet.If the style sheet is not empty, the rules from the parsed source will be added at the end of the rule list, with the same origin as the rule with a highest precedence origin.
If
commentMode
is notCOMMENTS_IGNORE
, the comments preceding a rule shall be available throughCSSRule.getPrecedingComments()
, and ifCOMMENTS_AUTO
was set also the trailing ones, through the methodCSSRule.getTrailingComments()
.To create a sheet, see
CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)
- Parameters:
reader
- the character stream containing the CSS sheet.commentMode
-0
if comments have to be ignored,1
if all comments are considered as preceding a rule,2
if the parser should try to figure out which comments are preceding and trailing a rule (auto mode).- Returns:
true
if the NSAC parser reported no errors or fatal errors,false
otherwise.- Throws:
DOMException
- if a problem is found parsing the sheet.IOException
- if a problem is found reading the sheet.
-