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

public interface CSSStyleSheet<R extends CSSRule> extends org.w3c.dom.css.CSSStyleSheet
A style sheet.

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 Details

    • COMMENTS_IGNORE

      static final short COMMENTS_IGNORE
      Ignore all comments when parsing a sheet.
      See Also:
    • COMMENTS_PRECEDING

      static final short COMMENTS_PRECEDING
      When 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_AUTO
      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.
      See Also:
  • Method Details

    • addRule

      void addRule(R cssrule) throws DOMException
      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

      void addStyleSheet(AbstractCSSStyleSheet sheet)
      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 interface org.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 interface org.w3c.dom.stylesheets.StyleSheet
      Returns:
      the media query list.
    • clone

      CSSStyleSheet<R> clone()
      Clone this style sheet.
      Returns:
      the cloned style sheet.
    • createCounterStyleRule

      CSSCounterStyleRule createCounterStyleRule(String name) throws DOMException
      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

      CSSFontFeatureValuesRule createFontFeatureValuesRule(String[] fontFamily)
      Create a CSSFontFeatureValuesRule compatible with this implementation.
      Parameters:
      fontFamily - the font family.
      Returns:
      a CSSFontFeatureValuesRule object.
    • createImportRule

      org.w3c.dom.css.CSSImportRule createImportRule(MediaQueryList mediaList, String href)
      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

      CSSKeyframesRule createKeyframesRule(String keyframesName) throws DOMException
      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

      CSSMarginRule createMarginRule(String name)
      Create a CSS margin rule compatible with this implementation.
      Parameters:
      name - the margin rule name.
      Returns:
      a CSS margin rule.
    • createMediaRule

      CSSMediaRule createMediaRule(MediaQueryList mediaList)
      Create a CSS media rule.
      Parameters:
      mediaList - a list of media types for the new rule.
      Returns:
      a CSS media rule.
    • createNamespaceRule

      CSSNamespaceRule createNamespaceRule(String prefix, String namespaceUri) throws DOMException
      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

      CSSPropertyRule createPropertyRule(String name)
      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

      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).

      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

      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).

      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

      boolean parseStyleSheet(Reader reader) throws DOMException, IOException
      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

      boolean parseStyleSheet(Reader reader, short commentMode) throws DOMException, IOException
      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 not COMMENTS_IGNORE, the comments preceding a rule shall be available through CSSRule.getPrecedingComments(), and if COMMENTS_AUTO was set also the trailing ones, through the method CSSRule.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.