- All Implemented Interfaces:
ExtendedCSSStyleSheet<AbstractCSSRule>
,Cloneable
,CSSStyleSheet
,StyleSheet
- Direct Known Subclasses:
BaseDocumentCSSStyleSheet
,DOMCSSStyleSheet
-
Constructor Summary
ModifierConstructorDescriptionprotected
BaseCSSStyleSheet
(String title, MediaQueryList media, AbstractCSSRule ownerRule, byte origin) Constructs a style sheet. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addLocalRule
(CSSRule cssrule) Inserts a local rule in the current insertion point (generally after the last rule).void
addRule
(AbstractCSSRule cssrule) Inserts a rule in the current insertion point (generally after the last rule).void
Adds the rules contained by the supplied style sheet, if that sheet is not disabled.protected void
copyAllTo
(BaseCSSStyleSheet myCopy) protected void
copyFieldsTo
(BaseCSSStyleSheet myCopy) protected void
copyRulesTo
(BaseCSSStyleSheet myCopy) createCounterStyleRule
(String name) Create a CSSCounterStyleRule compatible with this implementation.Create a CSS Font Face rule compatible with this implementation.createFontFeatureValuesRule
(String[] fontFamily) Create a CSSFontFeatureValuesRule compatible with this implementation.createImportRule
(MediaQueryList mediaList, String href) Create a CSS import rule compatible with this implementation.createKeyframesRule
(String keyframesName) Create a CSSKeyframesRule compatible with this implementation.createMarginRule
(String name) Create a CSS margin rule compatible with this implementation.createMediaRule
(MediaQueryList mediaList) Create a CSS media rule.createNamespaceRule
(String prefix, String namespaceUri) Create a CSS namespace rule compatible with this implementation.Create a CSS page rule compatible with this implementation.Create a CSS style declaration compatible with this implementation.protected BaseCSSStyleDeclaration
Create a CSS style rule.Create a CSSSupportsRule compatible with this implementation.Create a CSS unknown rule.Create a CSSViewportRule compatible with this implementation.void
deleteRule
(int index) Deletes a rule from the style sheet.Gets the collection of all CSS rules contained within the style sheet.boolean
protected ErrorHandler
Gets the error handler for this style sheet.getHref()
getMedia()
Get the destination media for this sheet.protected String
getNamespacePrefix
(String uri) Gets the namespace prefix associated to the given URI.byte
Get the origin of this sheet.getRulesForProperty
(String longhandPropertyName) Returns a list of rules that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Selector[]
getSelectorsForProperty
(String longhandPropertyName) Returns an array of selectors that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Selector[]
getSelectorsForPropertyValue
(String propertyName, String declaredValue) Returns an array of selectors that apply to a style where the given property was explicitly set to the given declared value.abstract BaseCSSStyleSheetFactory
Get the stylesheet factory used to produce this sheet.protected String
getType()
protected boolean
Has this style sheet defined a default namespace ?boolean
Check whether this sheet contains rules that have errors or warnings reported to their handlers.int
insertRule
(String rule, int index) Used to insert a new rule into the style sheet.boolean
loadStyleSheet
(URL url, String referrerPolicy) Load the styles fromurl
into this style sheet.boolean
parseStyleSheet
(InputSource source) Parses a style sheet.boolean
parseStyleSheet
(InputSource source, boolean ignoreComments) Parses a style sheet.protected void
registerNamespace
(CSSNamespaceRule nsrule) void
setDisabled
(boolean disabled) void
protected void
setMedia
(MediaQueryList media) Set the destination media for this sheet.protected void
Returns a minified parsable representation of the rule list of this sheet.toString()
Returns a serialization of this style sheet in the form of aSTYLE
element with its attributes and content.protected void
unregisterNamespace
(String namespaceURI) Methods inherited from class io.sf.carte.doc.style.css.om.AbstractCSSStyleSheet
clone, openConnection, parseRelAttribute
Methods inherited from class io.sf.carte.doc.style.css.om.AbstractStyleSheet
getTitle, setTitle
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.w3c.dom.stylesheets.StyleSheet
getTitle
-
Constructor Details
-
BaseCSSStyleSheet
protected BaseCSSStyleSheet(String title, MediaQueryList media, AbstractCSSRule ownerRule, byte origin) Constructs a style sheet.- Parameters:
title
- the advisory title.media
- the media this sheet is for.ownerRule
- the owner rule.origin
- the sheet origin.
-
-
Method Details
-
copyAllTo
-
copyFieldsTo
-
copyRulesTo
-
getStyleSheetFactory
Get the stylesheet factory used to produce this sheet.- Specified by:
getStyleSheetFactory
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
getStyleSheetFactory
in classAbstractCSSStyleSheet
- Returns:
- the stylesheet factory.
-
getOwnerRule
- Specified by:
getOwnerRule
in interfaceCSSStyleSheet
- Specified by:
getOwnerRule
in classAbstractCSSStyleSheet
-
getOwnerNode
-
getMedia
Description copied from interface:ExtendedCSSStyleSheet
Get the destination media for this sheet.- Returns:
- the media query list.
-
setMedia
Description copied from class:AbstractStyleSheet
Set the destination media for this sheet.- Specified by:
setMedia
in classAbstractStyleSheet
- Parameters:
media
- the destination media.- Throws:
DOMException
- if themedia
is invalid.
-
getOrigin
public byte getOrigin()Description copied from class:AbstractCSSStyleSheet
Get the origin of this sheet.- Specified by:
getOrigin
in classAbstractCSSStyleSheet
- Returns:
- the origin of this sheet.
-
getCssRules
Description copied from interface:ExtendedCSSStyleSheet
Gets the collection of all CSS rules contained within the style sheet.- Specified by:
getCssRules
in interfaceCSSStyleSheet
- Specified by:
getCssRules
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
getCssRules
in classAbstractCSSStyleSheet
- Returns:
- the list of all CSS rules contained within the style sheet.
-
insertRule
Used to insert a new rule into the style sheet. The new rule now becomes part of the cascade.- Parameters:
rule
- The parsable text representing the rule. For rule sets this contains both the selector and the style declaration. For at-rules, this specifies both the at-identifier and the rule content.index
- The index within the style sheet's rule list of the rule before which to insert the specified rule. If the specified index is equal to the length of the style sheet's rule collection, the rule will be added to the end of the style sheet.- Returns:
- The index within the style sheet's rule collection of the newly inserted rule.
- Throws:
DOMException
- HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified index e.g. if an@import
rule is inserted after a standard rule set or other at-rule.
INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point.
NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is readonly.
SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
-
addRule
Inserts a rule in the current insertion point (generally after the last rule).- Parameters:
cssrule
- the rule to be inserted.- Throws:
DOMException
- NAMESPACE_ERR if the rule could not be added due to a namespace-related error.
-
registerNamespace
- Specified by:
registerNamespace
in classAbstractCSSStyleSheet
-
unregisterNamespace
- Specified by:
unregisterNamespace
in classAbstractCSSStyleSheet
-
addLocalRule
Inserts a local rule in the current insertion point (generally after the last rule).- Parameters:
cssrule
- the rule to be inserted.
-
deleteRule
Deletes a rule from the style sheet.- Parameters:
index
- The index within the style sheet's rule list of the rule to remove.- Throws:
DOMException
- INDEX_SIZE_ERR: Raised if the specified index does not correspond to a rule in the style sheet's rule list.
NAMESPACE_ERR: Raised if the rule is a namespace rule and this style sheet contains style rules with that namespace.
-
addStyleSheet
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 interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
addStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
sheet
- the sheet whose rules are to be added.
-
createCounterStyleRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSSCounterStyleRule compatible with this implementation.- Parameters:
name
- the counter-style name.- Returns:
- a CSSCounterStyleRule object.
-
createFontFaceRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS Font Face rule compatible with this implementation.- Specified by:
createFontFaceRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createFontFaceRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS Font Face rule object.
-
createFontFeatureValuesRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSSFontFeatureValuesRule compatible with this implementation.- Parameters:
fontFamily
- the font family.- Returns:
- a CSSFontFeatureValuesRule object.
-
createImportRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS import rule compatible with this implementation.- Specified by:
createImportRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createImportRule
in classAbstractCSSStyleSheet
- 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.
-
createKeyframesRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSSKeyframesRule compatible with this implementation.- Parameters:
keyframesName
- the name of the keyframes.- Returns:
- a CSSKeyframesRule object.
-
createMarginRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS margin rule compatible with this implementation.- Parameters:
name
- the margin rule name.- Returns:
- a CSS margin rule.
-
createMediaRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS media rule.- Specified by:
createMediaRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createMediaRule
in classAbstractCSSStyleSheet
- Parameters:
mediaList
- a list of media types for the new rule.- Returns:
- a CSS media rule.
-
createNamespaceRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS namespace rule compatible with this implementation.- Parameters:
prefix
- the namespace prefix.namespaceUri
- the namespace URI.- Returns:
- a CSS namespace rule.
-
createPageRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS page rule compatible with this implementation.- Specified by:
createPageRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createPageRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS page rule.
-
createStyleRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS style rule.- Specified by:
createStyleRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createStyleRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS style rule.
-
createSupportsRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createSupportsRule
in classAbstractCSSStyleSheet
- Returns:
- a CSSSupportsRule object.
-
createViewportRule
Description copied from interface:ExtendedCSSStyleSheet
Create a CSSViewportRule compatible with this implementation.- Specified by:
createViewportRule
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createViewportRule
in classAbstractCSSStyleSheet
- Returns:
- a CSSViewportRule object.
-
createUnknownRule
Description copied from interface:ExtendedCSSStyleSheet
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 interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createUnknownRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS unknown rule.
-
createStyleDeclaration
- Specified by:
createStyleDeclaration
in classAbstractCSSStyleSheet
-
createStyleDeclaration
Description copied from interface:ExtendedCSSStyleSheet
Create a CSS style declaration compatible with this implementation.- Specified by:
createStyleDeclaration
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
createStyleDeclaration
in classAbstractCSSStyleSheet
- Returns:
- a CSS style declaration.
-
hasRuleErrorsOrWarnings
public boolean hasRuleErrorsOrWarnings()Description copied from interface:ExtendedCSSStyleSheet
Check whether this sheet contains rules that have errors or warnings reported to their handlers.- Returns:
true
if this sheet contains rules that have errors or warnings.
-
getErrorHandler
Description copied from interface:ExtendedCSSStyleSheet
Gets the error handler for this style sheet.- Returns:
- the error handler.
-
getDocumentErrorHandler
- Specified by:
getDocumentErrorHandler
in classAbstractStyleSheet
-
getType
-
getNamespacePrefix
Gets the namespace prefix associated to the given URI.- Specified by:
getNamespacePrefix
in classAbstractCSSStyleSheet
- Parameters:
uri
- the namespace URI string.- Returns:
- the namespace prefix, or null if the URI is not known.
-
hasDefaultNamespace
protected boolean hasDefaultNamespace()Has this style sheet defined a default namespace ?- Specified by:
hasDefaultNamespace
in classAbstractCSSStyleSheet
- Returns:
true
if a default namespace was defined,false
otherwise.
-
getDisabled
public boolean getDisabled() -
setDisabled
public void setDisabled(boolean disabled) -
getParentStyleSheet
- Specified by:
getParentStyleSheet
in interfaceStyleSheet
- Specified by:
getParentStyleSheet
in classAbstractCSSStyleSheet
-
setParentStyleSheet
- Specified by:
setParentStyleSheet
in classAbstractCSSStyleSheet
-
getHref
-
setHref
- Specified by:
setHref
in classAbstractCSSStyleSheet
-
loadStyleSheet
Load the styles fromurl
into this style sheet.- Specified by:
loadStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
url
- the url to load the style sheet from.referrerPolicy
- the content of thereferrerpolicy
content attribute, if any, or the empty string.- Returns:
true
if the SAC parser reported no errors or fatal errors,false
otherwise.- Throws:
DOMException
- if there is a serious problem parsing the style sheet.IOException
- if a problem appears fetching the url contents.
-
getRulesForProperty
Returns a list of rules that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Grouping rules are scanned too, regardless of the medium or condition.
- Parameters:
longhandPropertyName
- the longhand property name.- Returns:
- the list of rules, or
null
if no rules declare that property, or the property is a shorthand.
-
getSelectorsForProperty
Returns an array of selectors that apply to a style where the given longhand property is set (either explicitly or through a shorthand).Grouping rules are scanned too, regardless of the medium or condition.
- Parameters:
longhandPropertyName
- the longhand property name.- Returns:
- the array of selectors, or
null
if no rules declare that property, or the property is a shorthand.
-
getSelectorsForPropertyValue
Returns an array of selectors that apply to a style where the given property was explicitly set to the given declared value.Media rules are scanned too, regardless of the specific medium.
Beware that using this method with computed instead of declared values may not give the expected results.
- Parameters:
propertyName
- the property name.declaredValue
- the property's declared value.- Returns:
- the array of selectors, or
null
if no rules contain that property-value pair.
-
getTargetMedium
-
toMinifiedString
Description copied from class:AbstractStyleSheet
Returns a minified parsable representation of the rule list of this sheet.- Specified by:
toMinifiedString
in classAbstractStyleSheet
- Returns:
- a minified parsable representation of the rule list of this sheet.
-
toString
-
toStyleString
Description copied from class:AbstractStyleSheet
Returns a serialization of this style sheet in the form of aSTYLE
element with its attributes and content.- Specified by:
toStyleString
in classAbstractStyleSheet
- Returns:
- an HTML
STYLE
element representing this style sheet.
-
parseStyleSheet
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.To create a sheet, see
CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)
- Specified by:
parseStyleSheet
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
parseStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
source
- the SAC input source.- Returns:
true
if the SAC 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 boolean parseStyleSheet(InputSource source, boolean ignoreComments) 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.
If
ignoreComments
is false, the comments preceding a rule will be available throughAbstractCSSRule.getPrecedingComments()
.This method resets the state of this sheet's error handler.
To create a sheet, see
CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)
- Specified by:
parseStyleSheet
in interfaceExtendedCSSStyleSheet<AbstractCSSRule>
- Specified by:
parseStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
source
- the SAC input source.ignoreComments
- true if comments have to be ignored.- Returns:
true
if the SAC 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.
-