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 CascadingStyleSheet
addImportRule(int nIndex, CSSImportRule aImportRule)
Add a new@import
rule at a specified index of the@import
rule list.CascadingStyleSheet
addImportRule(CSSImportRule aImportRule)
Add a new@import
rule at the end of the@import
rule list.CascadingStyleSheet
addNamespaceRule(int nIndex, CSSNamespaceRule aNamespaceRule)
Add a new@namespace
rule at the specified index of the@namespace
rule list.CascadingStyleSheet
addNamespaceRule(CSSNamespaceRule aNamespaceRule)
Add a new@namespace
rule at the end of the@namespace
rule list.boolean
equals(Object o)
com.helger.commons.collection.impl.ICommonsList<CSSImportRule>
getAllImportRules()
com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule>
getAllNamespaceRules()
CSSImportRule
getImportRuleAtIndex(int nIndex)
Get the@import
rule at the specified index.int
getImportRuleCount()
CSSNamespaceRule
getNamespaceRuleAtIndex(int nIndex)
Get the@namespace
rule at the specified index.int
getNamespaceRuleCount()
CSSSourceLocation
getSourceLocation()
int
hashCode()
boolean
hasImportRules()
boolean
hasNamespaceRules()
com.helger.commons.state.EChange
removeAllImportRules()
Remove all@import
rules.com.helger.commons.state.EChange
removeAllNamespaceRules()
Remove all@namespace
rules.com.helger.commons.state.EChange
removeImportRule(int nImportRuleIndex)
Remove the@import
rule at the specified index.com.helger.commons.state.EChange
removeImportRule(CSSImportRule aImportRule)
Remove the specified@import
rule.com.helger.commons.state.EChange
removeNamespaceRule(int nNamespaceRuleIndex)
Remove the@namespace
rule at the specified index.com.helger.commons.state.EChange
removeNamespaceRule(CSSNamespaceRule aNamespaceRule)
Remove the specified@namespace
rule.void
setSourceLocation(CSSSourceLocation aSourceLocation)
Set the source location of the object, determined while parsing.String
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
-
-
-
-
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 benull
.- Returns:
- this
-
addImportRule
@Nonnull public CascadingStyleSheet addImportRule(@Nonnegative int nIndex, @Nonnull CSSImportRule aImportRule)
Add a new@import
rule at a specified index of the@import
rule 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@import
rule.- Parameters:
aImportRule
- The import rule to be removed. May benull
.- Returns:
EChange.CHANGED
if removal was successful,EChange.UNCHANGED
otherwise. Nevernull
.
-
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. Nevernull
.
-
removeAllImportRules
@Nonnull public com.helger.commons.state.EChange removeAllImportRules()
Remove all@import
rules.- Returns:
EChange.CHANGED
if any rule was removed,EChange.UNCHANGED
otherwise. Nevernull
.- Since:
- 3.7.3
-
getAllImportRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSImportRule> getAllImportRules()
- Returns:
- A copy of all contained
@import
rules. Nevernull
.
-
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 benull
.- 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 benull
.- 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 benull
.- Returns:
EChange.CHANGED
if the namespace rule was successfully removed,EChange.UNCHANGED
otherwise. Nevernull
.
-
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. Nevernull
.
-
removeAllNamespaceRules
@Nonnull public com.helger.commons.state.EChange removeAllNamespaceRules()
Remove all@namespace
rules.- Returns:
EChange.CHANGED
if any rule was removed,EChange.UNCHANGED
otherwise. Nevernull
.- Since:
- 3.7.3
-
getAllNamespaceRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSNamespaceRule> getAllNamespaceRules()
- Returns:
- A copy of all
@namespace
rules. Nevernull
.
-
getSourceLocation
@Nullable public final CSSSourceLocation getSourceLocation()
- Specified by:
getSourceLocation
in interfaceICSSSourceLocationAware
- Returns:
- The source location of this object when it was read by the parser.
May be
null
if an object was not read but manually created.
-
setSourceLocation
public final void setSourceLocation(@Nullable CSSSourceLocation aSourceLocation)
Description copied from interface:ICSSSourceLocationAware
Set the source location of the object, determined while parsing.- Specified by:
setSourceLocation
in interfaceICSSSourceLocationAware
- Parameters:
aSourceLocation
- The source location to use. May benull
.
-
-