Class CascadingStyleSheet

  • All Implemented Interfaces:
    ICSSSourceLocationAware

    @NotThreadSafe
    public class CascadingStyleSheet
    extends AbstractHasTopLevelRules
    implements ICSSSourceLocationAware
    This is the main object for a parsed CSS declaration. It has special handling for import and namespace rules, as these rules must always be on the beginning of a file. All other rules (all implementing ICSSTopLevelRule) are maintained in a combined list.
    Author:
    Philip Helger
    • Constructor Detail

      • CascadingStyleSheet

        public CascadingStyleSheet()
    • Method Detail

      • hasImportRules

        public boolean hasImportRules()
        Returns:
        true if at least one @import rule is present, false otherwise.
      • getImportRuleCount

        @Nonnegative
        public int getImportRuleCount()
        Returns:
        The number of contained @import rules. Always ≥ 0.
      • getImportRuleAtIndex

        @Nullable
        public CSSImportRule getImportRuleAtIndex​(@Nonnegative
                                                  int nIndex)
        Get the @import rule at the specified index.
        Parameters:
        nIndex - The index to be resolved. Should be ≥ 0 and < getImportRuleCount().
        Returns:
        null if an invalid index was specified.
        Since:
        3.7.4
      • addImportRule

        @Nonnull
        public CascadingStyleSheet addImportRule​(@Nonnull
                                                 CSSImportRule aImportRule)
        Add a new @import rule at the end of the @import rule list.
        Parameters:
        aImportRule - The import rule to add. May not be null.
        Returns:
        this
      • removeImportRule

        @Nonnull
        public com.helger.commons.state.EChange removeImportRule​(@Nullable
                                                                 CSSImportRule aImportRule)
        Remove the specified @import rule.
        Parameters:
        aImportRule - The import rule to be removed. May be null.
        Returns:
        EChange.CHANGED if removal was successful, EChange.UNCHANGED otherwise. Never null.
      • removeImportRule

        @Nonnull
        public com.helger.commons.state.EChange removeImportRule​(@Nonnegative
                                                                 int nImportRuleIndex)
        Remove the @import rule at the specified index.
        Parameters:
        nImportRuleIndex - The index to be removed. Should be ≥ 0.
        Returns:
        EChange.CHANGED if removal was successful, EChange.UNCHANGED otherwise. Never null.
      • removeAllImportRules

        @Nonnull
        public com.helger.commons.state.EChange removeAllImportRules()
        Remove all @import rules.
        Returns:
        EChange.CHANGED if any rule was removed, EChange.UNCHANGED otherwise. Never null.
        Since:
        3.7.3
      • getAllImportRules

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<CSSImportRule> getAllImportRules()
        Returns:
        A copy of all contained @import rules. Never null.
      • hasNamespaceRules

        public boolean hasNamespaceRules()
        Returns:
        true if at least one @namespace rule is present, false otherwise.
      • getNamespaceRuleCount

        @Nonnegative
        public int getNamespaceRuleCount()
        Returns:
        The number of contained @namespace rules. Always ≥ 0.
      • getNamespaceRuleAtIndex

        @Nullable
        public CSSNamespaceRule getNamespaceRuleAtIndex​(@Nonnegative
                                                        int nIndex)
        Get the @namespace rule at the specified index.
        Parameters:
        nIndex - The index to be resolved. Should be ≥ 0 and < getNamespaceRuleCount().
        Returns:
        null if an invalid index was specified.
        Since:
        3.7.4
      • addNamespaceRule

        @Nonnull
        public CascadingStyleSheet addNamespaceRule​(@Nonnull
                                                    CSSNamespaceRule aNamespaceRule)
        Add a new @namespace rule at the end of the @namespace rule list.
        Parameters:
        aNamespaceRule - The namespace rule to be added. May not be null.
        Returns:
        this
      • addNamespaceRule

        @Nonnull
        public CascadingStyleSheet addNamespaceRule​(@Nonnegative
                                                    int nIndex,
                                                    @Nonnull
                                                    CSSNamespaceRule aNamespaceRule)
        Add a new @namespace rule at the specified index of the @namespace rule list.
        Parameters:
        nIndex - The index where the rule should be added. Must be ≥ 0.
        aNamespaceRule - The namespace rule to be added. May not be null.
        Returns:
        this
      • removeNamespaceRule

        @Nonnull
        public com.helger.commons.state.EChange removeNamespaceRule​(@Nullable
                                                                    CSSNamespaceRule aNamespaceRule)
        Remove the specified @namespace rule.
        Parameters:
        aNamespaceRule - The namespace rule to be removed. May be null.
        Returns:
        EChange.CHANGED if the namespace rule was successfully removed, EChange.UNCHANGED otherwise. Never null.
      • removeNamespaceRule

        @Nonnull
        public com.helger.commons.state.EChange removeNamespaceRule​(@Nonnegative
                                                                    int nNamespaceRuleIndex)
        Remove the @namespace rule at the specified index.
        Parameters:
        nNamespaceRuleIndex - The index to be removed. Should be ≥ 0.
        Returns:
        EChange.CHANGED if the namespace rule was successfully removed, EChange.UNCHANGED otherwise. Never null.
      • removeAllNamespaceRules

        @Nonnull
        public com.helger.commons.state.EChange removeAllNamespaceRules()
        Remove all @namespace rules.
        Returns:
        EChange.CHANGED if any rule was removed, EChange.UNCHANGED otherwise. Never null.
        Since:
        3.7.3
      • getAllNamespaceRules

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule> getAllNamespaceRules()
        Returns:
        A copy of all @namespace rules. Never null.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object