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 implementingICSSTopLevelRule) 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 Constructor Description CascadingStyleSheet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CascadingStyleSheetaddImportRule(int nIndex, CSSImportRule aImportRule)Add a new@importrule at a specified index of the@importrule list.CascadingStyleSheetaddImportRule(CSSImportRule aImportRule)Add a new@importrule at the end of the@importrule list.CascadingStyleSheetaddNamespaceRule(int nIndex, CSSNamespaceRule aNamespaceRule)Add a new@namespacerule at the specified index of the@namespacerule list.CascadingStyleSheetaddNamespaceRule(CSSNamespaceRule aNamespaceRule)Add a new@namespacerule at the end of the@namespacerule list.booleanequals(Object o)com.helger.commons.collection.impl.ICommonsList<CSSImportRule>getAllImportRules()com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule>getAllNamespaceRules()CSSImportRulegetImportRuleAtIndex(int nIndex)Get the@importrule at the specified index.intgetImportRuleCount()CSSNamespaceRulegetNamespaceRuleAtIndex(int nIndex)Get the@namespacerule at the specified index.intgetNamespaceRuleCount()CSSSourceLocationgetSourceLocation()inthashCode()booleanhasImportRules()booleanhasNamespaceRules()com.helger.commons.state.EChangeremoveAllImportRules()Remove all@importrules.com.helger.commons.state.EChangeremoveAllNamespaceRules()Remove 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.voidsetSourceLocation(CSSSourceLocation aSourceLocation)Set the source location of the object, determined while parsing.StringtoString()-
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
-
-
-
-
Method Detail
-
hasImportRules
public boolean hasImportRules()
- Returns:
trueif at least one@importrule is present,falseotherwise.
-
getImportRuleCount
@Nonnegative public int getImportRuleCount()
- Returns:
- The number of contained
@importrules. Always ≥ 0.
-
getImportRuleAtIndex
@Nullable public CSSImportRule getImportRuleAtIndex(@Nonnegative int nIndex)
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
@Nonnull public CascadingStyleSheet addImportRule(@Nonnull CSSImportRule aImportRule)
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
@Nonnull public com.helger.commons.state.EChange 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
@Nonnegative public int getNamespaceRuleCount()
- Returns:
- The number of contained
@namespacerules. Always ≥ 0.
-
getNamespaceRuleAtIndex
@Nullable public CSSNamespaceRule getNamespaceRuleAtIndex(@Nonnegative int nIndex)
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
@Nonnull public CascadingStyleSheet addNamespaceRule(@Nonnull CSSNamespaceRule aNamespaceRule)
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
@Nonnull public com.helger.commons.state.EChange 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
@Nullable public final CSSSourceLocation 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
public final void setSourceLocation(@Nullable CSSSourceLocation aSourceLocation)
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.
-
-