Class AbstractCSSStyleSheet

java.lang.Object
io.sf.carte.doc.style.css.om.AbstractStyleSheet
io.sf.carte.doc.style.css.om.AbstractCSSStyleSheet
All Implemented Interfaces:
CSSStyleSheet<AbstractCSSRule>, Serializable, Cloneable, org.w3c.dom.css.CSSStyleSheet, org.w3c.dom.stylesheets.StyleSheet
Direct Known Subclasses:
BaseCSSStyleSheet

public abstract class AbstractCSSStyleSheet extends AbstractStyleSheet implements CSSStyleSheet<AbstractCSSRule>
Abstract class to be inherited by all CSS style sheets.
See Also:
  • Constructor Details

    • AbstractCSSStyleSheet

      protected AbstractCSSStyleSheet(String title)
  • Method Details

    • getCssRules

      public abstract CSSRuleArrayList getCssRules()
      Description copied from interface: CSSStyleSheet
      Gets the collection of all CSS rules contained within the style sheet.
      Specified by:
      getCssRules in interface CSSStyleSheet<AbstractCSSRule>
      Specified by:
      getCssRules in interface org.w3c.dom.css.CSSStyleSheet
      Returns:
      the list of all CSS rules contained within the style sheet.
    • getParentStyleSheet

      public abstract AbstractCSSStyleSheet getParentStyleSheet()
      Specified by:
      getParentStyleSheet in interface org.w3c.dom.stylesheets.StyleSheet
    • getOwnerRule

      public abstract AbstractCSSRule getOwnerRule()
      Specified by:
      getOwnerRule in interface org.w3c.dom.css.CSSStyleSheet
    • getStyleSheetFactory

      public abstract AbstractCSSStyleSheetFactory getStyleSheetFactory()
      Description copied from interface: CSSStyleSheet
      Get the style sheet factory used to produce this sheet.
      Specified by:
      getStyleSheetFactory in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      the style sheet factory.
    • parseStyleSheet

      public abstract boolean parseStyleSheet(Reader reader) 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.

      Even if a specific media is set at the InputSource, this method does not alter the sheet's current media attribute.

      The comments shall be processed according to CSSStyleSheet.COMMENTS_AUTO.

      To create a sheet, see CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)

      Specified by:
      parseStyleSheet in interface CSSStyleSheet<AbstractCSSRule>
      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 problem is found parsing the sheet.
      IOException - if a problem is found reading the sheet.
    • parseStyleSheet

      public abstract 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.

      Even if a specific media is set at the InputSource, this method does not alter the sheet's current media attribute.

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

      This method resets the state of this sheet's error handler.

      To create a sheet, see CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)

      Specified by:
      parseStyleSheet in interface CSSStyleSheet<AbstractCSSRule>
      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.
    • addStyleSheet

      public abstract 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.

      Specified by:
      addStyleSheet in interface CSSStyleSheet<AbstractCSSRule>
      Parameters:
      sheet - the sheet whose rules are to be added.
    • loadStyleSheet

      public abstract boolean loadStyleSheet(URL url, String referrerPolicy) throws DOMException, IOException
      Load the styles from url into this style sheet.
      Parameters:
      url - the url to load the style sheet from.
      referrerPolicy - the content of the referrerpolicy content attribute, if any, or the empty string.
      Returns:
      true if the NSAC parser reported no errors or fatal errors, false otherwise.
      Throws:
      DOMPolicyException - if the style sheet was served with an invalid content type.
      DOMException - if there is a serious problem parsing the style sheet.
      IOException - if a problem appears fetching the url contents.
    • createFontFaceRule

      public abstract FontFaceRule createFontFaceRule()
      Description copied from interface: CSSStyleSheet
      Create a CSS Font Face rule compatible with this implementation.
      Specified by:
      createFontFaceRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSS Font Face rule object.
    • createImportRule

      public abstract ImportRule createImportRule(MediaQueryList mediaList, String href)
      Description copied from interface: CSSStyleSheet
      Create a CSS import rule compatible with this implementation.
      Specified by:
      createImportRule in interface CSSStyleSheet<AbstractCSSRule>
      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.
    • createMediaRule

      public abstract MediaRule createMediaRule(MediaQueryList mediaList)
      Description copied from interface: CSSStyleSheet
      Create a CSS media rule.
      Specified by:
      createMediaRule in interface CSSStyleSheet<AbstractCSSRule>
      Parameters:
      mediaList - a list of media types for the new rule.
      Returns:
      a CSS media rule.
    • createPageRule

      public abstract PageRule createPageRule()
      Description copied from interface: CSSStyleSheet
      Create a CSS page rule compatible with this implementation.
      Specified by:
      createPageRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSS page rule.
    • createStyleRule

      public abstract StyleRule createStyleRule()
      Description copied from interface: CSSStyleSheet
      Create a CSS style rule.
      Specified by:
      createStyleRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSS style rule.
    • createSupportsRule

      public abstract SupportsRule createSupportsRule()
      Description copied from interface: CSSStyleSheet
      Create a CSSSupportsRule compatible with this implementation.
      Specified by:
      createSupportsRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSSSupportsRule object.
    • createUnknownRule

      public abstract UnknownRule createUnknownRule()
      Description copied from interface: CSSStyleSheet
      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.

      Specified by:
      createUnknownRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSS unknown rule.
    • createViewportRule

      public abstract ViewportRule createViewportRule()
      Description copied from interface: CSSStyleSheet
      Create a CSSViewportRule compatible with this implementation.
      Specified by:
      createViewportRule in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSSViewportRule object.
    • createStyleDeclaration

      public abstract AbstractCSSStyleDeclaration createStyleDeclaration()
      Description copied from interface: CSSStyleSheet
      Create a CSS style declaration compatible with this implementation.
      Specified by:
      createStyleDeclaration in interface CSSStyleSheet<AbstractCSSRule>
      Returns:
      a CSS style declaration.
    • createStyleDeclaration

      protected abstract AbstractCSSStyleDeclaration createStyleDeclaration(BaseCSSDeclarationRule rule)
      Create a style declaration from the given declaration rule.
      Parameters:
      rule - the declaration rule.
      Returns:
      the style declaration.
    • registerNamespace

      protected abstract void registerNamespace(CSSNamespaceRule nsrule)
      Register the namespace from the given namespace rule.
      Parameters:
      nsrule - the namespace rule.
    • unregisterNamespace

      protected abstract void unregisterNamespace(String namespaceURI)
      Unregister the namespace corresponding to the given namespace URI.
      Parameters:
      namespaceURI - the namespace URI.
    • getNamespacePrefix

      protected abstract String getNamespacePrefix(String uri)
      Gets the namespace prefix associated to the given URI.
      Parameters:
      uri - the namespace URI string.
      Returns:
      the namespace prefix.
    • hasDefaultNamespace

      protected abstract boolean hasDefaultNamespace()
      Has this style sheet defined a default namespace ?
      Returns:
      true if a default namespace was defined, false otherwise.
    • setHref

      public abstract void setHref(String href)
    • getOrigin

      public abstract byte getOrigin()
      Get the origin of this sheet.
      Returns:
      the origin of this sheet.
    • clone

      public abstract AbstractCSSStyleSheet clone()
      Clone this style sheet.
      Specified by:
      clone in interface CSSStyleSheet<AbstractCSSRule>
      Specified by:
      clone in class AbstractStyleSheet
      Returns:
      the cloned style sheet.
    • openConnection

      public URLConnection openConnection(URL url, String referrerPolicy) throws IOException
      Description copied from class: AbstractStyleSheet
      Open a non-interactive connection to the given URL.

      If this sheet was obtained through a network connection, the returned connection should be opened by the same user agent (and appropriate credentials) that retrieved this sheet.

      Specified by:
      openConnection in class AbstractStyleSheet
      Parameters:
      url - the URL to connect to.
      referrerPolicy - the content of the referrerpolicy content attribute, if any, or the empty string.
      Returns:
      the network connection.
      Throws:
      IOException - if an I/O problem occurs opening the connection.
    • getFirstStyleRule

      public abstract StyleRule getFirstStyleRule(SelectorList selectorList)
      Get the first style rule that exactly matches the given selector list, if any.

      Rules inside grouping rules are also searched.

      Parameters:
      selectorList - the selector list.
      Returns:
      the first style rule that matches, or null if none.
    • getStyleRules

      public abstract CSSRuleArrayList getStyleRules(Selector selector)
      Get the list of style rules that match the given selector.

      Rules inside grouping rules are also searched.

      Parameters:
      selector - the selector.
      Returns:
      the list of style rule that match, or null if none.
    • acceptStyleRuleVisitor

      public abstract void acceptStyleRuleVisitor(io.sf.carte.util.Visitor<CSSStyleRule> visitor)
      Accept a style rule visitor.
      Parameters:
      visitor - the visitor.
    • acceptDeclarationRuleVisitor

      public abstract void acceptDeclarationRuleVisitor(io.sf.carte.util.Visitor<CSSDeclarationRule> visitor)
      Accept a declaration rule visitor.
      Parameters:
      visitor - the visitor.
    • acceptDescriptorRuleVisitor

      public abstract void acceptDescriptorRuleVisitor(io.sf.carte.util.Visitor<CSSDeclarationRule> visitor)
      Accept a descriptor rule visitor.

      This method scans for declaration rules that declare descriptors.

      Parameters:
      visitor - the visitor.
    • setParentStyleSheet

      protected abstract void setParentStyleSheet(AbstractCSSStyleSheet parent)
      Sets the parent style sheet.
      Parameters:
      parent - the parent style sheet. Cannot be null.
    • parseRelAttribute

      public static byte parseRelAttribute(String relText)
      Parses the rel attribute.
      Parameters:
      relText - the rel attribute.
      Returns:
      0 if rel refers to a style sheet, 1 if the sheet is alternate, -1 if it is not compatible with a style sheet.