Package com.helger.css.decl
Class CascadingStyleSheet
java.lang.Object
com.helger.css.decl.AbstractHasTopLevelRules
com.helger.css.decl.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
-
Field Summary
Fields inherited from class com.helger.css.decl.AbstractHasTopLevelRules
m_aRules -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddImportRule(int nIndex, CSSImportRule aImportRule) Add a new@importrule at a specified index of the@importrule list.addImportRule(CSSImportRule aImportRule) Add a new@importrule at the end of the@importrule list.addNamespaceRule(int nIndex, CSSNamespaceRule aNamespaceRule) Add a new@namespacerule at the specified index of the@namespacerule list.addNamespaceRule(CSSNamespaceRule aNamespaceRule) Add a new@namespacerule at the end of the@namespacerule list.booleancom.helger.commons.collection.impl.ICommonsList<CSSImportRule>com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule>getImportRuleAtIndex(int nIndex) Get the@importrule at the specified index.intgetNamespaceRuleAtIndex(int nIndex) Get the@namespacerule at the specified index.intfinal CSSSourceLocationinthashCode()booleanbooleancom.helger.commons.state.EChangeRemove all@importrules.com.helger.commons.state.EChangeRemove all@namespacerules.com.helger.commons.state.EChangeremoveImportRule(int nImportRuleIndex) Remove the@importrule at the specified index.com.helger.commons.state.EChangeremoveImportRule(CSSImportRule aImportRule) Remove the specified@importrule.com.helger.commons.state.EChangeremoveNamespaceRule(int nNamespaceRuleIndex) Remove the@namespacerule at the specified index.com.helger.commons.state.EChangeremoveNamespaceRule(CSSNamespaceRule aNamespaceRule) Remove the specified@namespacerule.final voidsetSourceLocation(CSSSourceLocation aSourceLocation) Set the source location of the object, determined while parsing.toString()Methods inherited from class com.helger.css.decl.AbstractHasTopLevelRules
addRule, addRule, getAllFontFaceRules, getAllKeyframesRules, getAllMediaRules, getAllPageRules, getAllRules, getAllRules, getAllStyleRules, getAllSupportsRules, getAllUnknownRules, getAllViewportRules, getFontFaceRuleAtIndex, getFontFaceRuleCount, getKeyframesRuleAtIndex, getKeyframesRuleCount, getMediaRuleAtIndex, getMediaRuleCount, getPageRuleAtIndex, getPageRuleCount, getRule, getRuleAtIndex, getRuleCount, getStyleRuleAtIndex, getStyleRuleCount, getSupportsRuleAtIndex, getSupportsRuleCount, getUnknownRuleAtIndex, getUnknownRuleCount, getViewportRuleAtIndex, getViewportRuleCount, hasFontFaceRules, hasKeyframesRules, hasMediaRules, hasPageRules, hasRules, hasStyleRules, hasSupportsRules, hasUnknownRules, hasViewportRules, removeAllRules, removeRule, removeRule, removeRules
-
Constructor Details
-
CascadingStyleSheet
public CascadingStyleSheet()
-
-
Method Details
-
hasImportRules
public boolean hasImportRules()- Returns:
trueif at least one@importrule is present,falseotherwise.
-
getImportRuleCount
- Returns:
- The number of contained
@importrules. Always ≥ 0.
-
getImportRuleAtIndex
Get the@importrule at the specified index.- Parameters:
nIndex- The index to be resolved. Should be ≥ 0 and <getImportRuleCount().- Returns:
nullif an invalid index was specified.- Since:
- 3.7.4
-
addImportRule
Add a new@importrule at the end of the@importrule list.- Parameters:
aImportRule- The import rule to add. May not benull.- Returns:
- this
-
addImportRule
@Nonnull public CascadingStyleSheet addImportRule(@Nonnegative int nIndex, @Nonnull CSSImportRule aImportRule) Add a new@importrule at a specified index of the@importrule list.- Parameters:
nIndex- The index where the rule should be added. Must be ≥ 0.aImportRule- The import rule to add. May not benull.- Returns:
- this
- Throws:
ArrayIndexOutOfBoundsException- if the index is invalid
-
removeImportRule
@Nonnull public com.helger.commons.state.EChange removeImportRule(@Nullable CSSImportRule aImportRule) Remove the specified@importrule.- Parameters:
aImportRule- The import rule to be removed. May benull.- Returns:
EChange.CHANGEDif removal was successful,EChange.UNCHANGEDotherwise. Nevernull.
-
removeImportRule
@Nonnull public com.helger.commons.state.EChange removeImportRule(@Nonnegative int nImportRuleIndex) Remove the@importrule at the specified index.- Parameters:
nImportRuleIndex- The index to be removed. Should be ≥ 0.- Returns:
EChange.CHANGEDif removal was successful,EChange.UNCHANGEDotherwise. Nevernull.
-
removeAllImportRules
Remove all@importrules.- Returns:
EChange.CHANGEDif any rule was removed,EChange.UNCHANGEDotherwise. Nevernull.- Since:
- 3.7.3
-
getAllImportRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSImportRule> getAllImportRules()- Returns:
- A copy of all contained
@importrules. Nevernull.
-
hasNamespaceRules
public boolean hasNamespaceRules()- Returns:
trueif at least one@namespacerule is present,falseotherwise.
-
getNamespaceRuleCount
- Returns:
- The number of contained
@namespacerules. Always ≥ 0.
-
getNamespaceRuleAtIndex
Get the@namespacerule at the specified index.- Parameters:
nIndex- The index to be resolved. Should be ≥ 0 and <getNamespaceRuleCount().- Returns:
nullif an invalid index was specified.- Since:
- 3.7.4
-
addNamespaceRule
Add a new@namespacerule at the end of the@namespacerule list.- Parameters:
aNamespaceRule- The namespace rule to be added. May not benull.- Returns:
- this
-
addNamespaceRule
@Nonnull public CascadingStyleSheet addNamespaceRule(@Nonnegative int nIndex, @Nonnull CSSNamespaceRule aNamespaceRule) Add a new@namespacerule at the specified index of the@namespacerule list.- Parameters:
nIndex- The index where the rule should be added. Must be ≥ 0.aNamespaceRule- The namespace rule to be added. May not benull.- Returns:
- this
-
removeNamespaceRule
@Nonnull public com.helger.commons.state.EChange removeNamespaceRule(@Nullable CSSNamespaceRule aNamespaceRule) Remove the specified@namespacerule.- Parameters:
aNamespaceRule- The namespace rule to be removed. May benull.- Returns:
EChange.CHANGEDif the namespace rule was successfully removed,EChange.UNCHANGEDotherwise. Nevernull.
-
removeNamespaceRule
@Nonnull public com.helger.commons.state.EChange removeNamespaceRule(@Nonnegative int nNamespaceRuleIndex) Remove the@namespacerule at the specified index.- Parameters:
nNamespaceRuleIndex- The index to be removed. Should be ≥ 0.- Returns:
EChange.CHANGEDif the namespace rule was successfully removed,EChange.UNCHANGEDotherwise. Nevernull.
-
removeAllNamespaceRules
Remove all@namespacerules.- Returns:
EChange.CHANGEDif any rule was removed,EChange.UNCHANGEDotherwise. Nevernull.- Since:
- 3.7.3
-
getAllNamespaceRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule> getAllNamespaceRules()- Returns:
- A copy of all
@namespacerules. Nevernull.
-
getSourceLocation
- Specified by:
getSourceLocationin interfaceICSSSourceLocationAware- Returns:
- The source location of this object when it was read by the parser.
May be
nullif an object was not read but manually created.
-
setSourceLocation
Description copied from interface:ICSSSourceLocationAwareSet the source location of the object, determined while parsing.- Specified by:
setSourceLocationin interfaceICSSSourceLocationAware- Parameters:
aSourceLocation- The source location to use. May benull.
-
equals
-
hashCode
public int hashCode() -
toString
-