- All Implemented Interfaces:
CSSStyleSheet<AbstractCSSRule>
,SheetContext
,Serializable
,Cloneable
,CSSStyleSheet
,StyleSheet
- Direct Known Subclasses:
BaseDocumentCSSStyleSheet
,DOMCSSStyleSheet
- See Also:
-
Field Summary
Fields inherited from interface io.sf.carte.doc.style.css.CSSStyleSheet
COMMENTS_AUTO, COMMENTS_IGNORE, COMMENTS_PRECEDING
-
Constructor Summary
ModifierConstructorDescriptionprotected
BaseCSSStyleSheet
(String title, MediaQueryList media, AbstractCSSRule ownerRule, byte origin) Constructs a style sheet. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Accept a declaration rule visitor.void
Accept a descriptor rule visitor.void
acceptStyleRuleVisitor
(Visitor<CSSStyleRule> visitor) Accept a style rule visitor.protected 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.createPropertyRule
(String name) Create a CSS property rule compatible with this implementation.Create a CSS style declaration compatible with this implementation.protected BaseCSSStyleDeclaration
Create a style declaration from the given declaration rule.Create a CSS style rule.Deprecated.createSupportsRule
(BooleanCondition condition) Create a CSSSupportsRule compatible with this implementation.createSupportsRule
(String conditionText) 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.getFirstStyleRule
(SelectorList selectorList) Get the first style rule that exactly matches the given selector list, if any.getHref()
getMedia()
Get the destination media for this sheet.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.getStyleRules
(Selector selector) Get the list of style rules that match the given selector.abstract BaseCSSStyleSheetFactory
Get the stylesheet factory used to produce this sheet.protected String
getType()
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
(Reader reader) Parses a style sheet.boolean
parseStyleSheet
(Reader reader, short commentMode) Parses a style sheet.protected void
registerNamespace
(CSSNamespaceRule nsrule) Register the namespace from the given namespace rule.void
setDisabled
(boolean disabled) void
protected void
setMedia
(MediaQueryList media) Set the destination media for this sheet.protected void
Sets the parent style sheet.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) Unregister the namespace corresponding to the given namespace URI.Methods inherited from class io.sf.carte.doc.style.css.om.AbstractCSSStyleSheet
clone, hasFactoryFlag, 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 interfaceCSSStyleSheet<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:CSSStyleSheet
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:CSSStyleSheet
Gets the collection of all CSS rules contained within the style sheet.- Specified by:
getCssRules
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
getCssRules
in interfaceCSSStyleSheet
- 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
Description copied from class:AbstractCSSStyleSheet
Register the namespace from the given namespace rule.- Specified by:
registerNamespace
in classAbstractCSSStyleSheet
- Parameters:
nsrule
- the namespace rule.
-
unregisterNamespace
Description copied from class:AbstractCSSStyleSheet
Unregister the namespace corresponding to the given namespace URI.- Specified by:
unregisterNamespace
in classAbstractCSSStyleSheet
- Parameters:
namespaceURI
- the namespace URI.
-
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 interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
addStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
sheet
- the sheet whose rules are to be added.
-
createCounterStyleRule
Description copied from interface:CSSStyleSheet
Create a CSSCounterStyleRule compatible with this implementation.- Parameters:
name
- the counter-style name.- Returns:
- a CSSCounterStyleRule object.
- Throws:
DOMException
- if the name is invalid.
-
createFontFaceRule
Description copied from interface:CSSStyleSheet
Create a CSS Font Face rule compatible with this implementation.- Specified by:
createFontFaceRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createFontFaceRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS Font Face rule object.
-
createFontFeatureValuesRule
Description copied from interface:CSSStyleSheet
Create a CSSFontFeatureValuesRule compatible with this implementation.- Parameters:
fontFamily
- the font family.- Returns:
- a CSSFontFeatureValuesRule object.
-
createImportRule
Description copied from interface:CSSStyleSheet
Create a CSS import rule compatible with this implementation.- Specified by:
createImportRule
in interfaceCSSStyleSheet<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:CSSStyleSheet
Create a CSSKeyframesRule compatible with this implementation.- Parameters:
keyframesName
- the name of the keyframes.- Returns:
- a CSSKeyframesRule object.
-
createMarginRule
Description copied from interface:CSSStyleSheet
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:CSSStyleSheet
Create a CSS media rule.- Specified by:
createMediaRule
in interfaceCSSStyleSheet<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:CSSStyleSheet
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:CSSStyleSheet
Create a CSS page rule compatible with this implementation.- Specified by:
createPageRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createPageRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS page rule.
-
createPropertyRule
Description copied from interface:CSSStyleSheet
Create a CSS property rule compatible with this implementation.- Parameters:
name
- the (unescaped) property name.- Returns:
- a CSS property rule.
-
createStyleRule
Description copied from interface:CSSStyleSheet
Create a CSS style rule.- Specified by:
createStyleRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createStyleRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS style rule.
-
createSupportsRule
Description copied from interface:CSSStyleSheet
Create a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createSupportsRule
in classAbstractCSSStyleSheet
- Parameters:
condition
- the@supports
condition.- Returns:
- a CSSSupportsRule object.
-
createSupportsRule
Description copied from interface:CSSStyleSheet
Create a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createSupportsRule
in classAbstractCSSStyleSheet
- Parameters:
conditionText
- a serialization of the@supports
condition.- Returns:
- a CSSSupportsRule object.
- Throws:
DOMException
- if the condition text could not be parsed.
-
createSupportsRule
Deprecated.Description copied from interface:CSSStyleSheet
Create a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createSupportsRule
in classAbstractCSSStyleSheet
- Returns:
- a CSSSupportsRule object.
-
createViewportRule
Description copied from interface:CSSStyleSheet
Create a CSSViewportRule compatible with this implementation.- Specified by:
createViewportRule
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createViewportRule
in classAbstractCSSStyleSheet
- Returns:
- a CSSViewportRule object.
-
createUnknownRule
Description copied from interface:CSSStyleSheet
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 interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createUnknownRule
in classAbstractCSSStyleSheet
- Returns:
- a CSS unknown rule.
-
createStyleDeclaration
Description copied from class:AbstractCSSStyleSheet
Create a style declaration from the given declaration rule.- Specified by:
createStyleDeclaration
in classAbstractCSSStyleSheet
- Parameters:
rule
- the declaration rule.- Returns:
- the style declaration.
-
createStyleDeclaration
Description copied from interface:CSSStyleSheet
Create a CSS style declaration compatible with this implementation.- Specified by:
createStyleDeclaration
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
createStyleDeclaration
in classAbstractCSSStyleSheet
- Returns:
- a CSS style declaration.
-
hasRuleErrorsOrWarnings
public boolean hasRuleErrorsOrWarnings()Description copied from interface:CSSStyleSheet
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:CSSStyleSheet
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 interfaceSheetContext
- Specified by:
getNamespacePrefix
in classAbstractCSSStyleSheet
- Parameters:
uri
- the namespace URI string.- Returns:
- the namespace prefix.
-
hasDefaultNamespace
public boolean hasDefaultNamespace()Has this style sheet defined a default namespace ?- Specified by:
hasDefaultNamespace
in interfaceSheetContext
- 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
Description copied from class:AbstractCSSStyleSheet
Sets the parent style sheet.- Specified by:
setParentStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
parent
- the parent style sheet. Cannot benull
.
-
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 NSAC parser reported no errors or fatal errors,false
otherwise.- Throws:
DOMPolicyException
- if the style sheet was served with an invalid content type.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.
-
getFirstStyleRule
Get the first style rule that exactly matches the given selector list, if any.Rules inside grouping rules are also searched.
- Specified by:
getFirstStyleRule
in classAbstractCSSStyleSheet
- Parameters:
selectorList
- the selector list.- Returns:
- the first style rule that matches, or
null
if none.
-
getStyleRules
Get the list of style rules that match the given selector.Rules inside grouping rules are also searched.
- Specified by:
getStyleRules
in classAbstractCSSStyleSheet
- Parameters:
selector
- the selector.- Returns:
- the list of style rule that match, or
null
if none.
-
acceptStyleRuleVisitor
Accept a style rule visitor.- Specified by:
acceptStyleRuleVisitor
in classAbstractCSSStyleSheet
- Parameters:
visitor
- the visitor.
-
acceptDeclarationRuleVisitor
Accept a declaration rule visitor.- Specified by:
acceptDeclarationRuleVisitor
in classAbstractCSSStyleSheet
- Parameters:
visitor
- the visitor.
-
acceptDescriptorRuleVisitor
Description copied from class:AbstractCSSStyleSheet
Accept a descriptor rule visitor.This method scans for declaration rules that declare descriptors.
- Specified by:
acceptDescriptorRuleVisitor
in classAbstractCSSStyleSheet
- Parameters:
visitor
- the visitor.
-
getTargetMedium
-
toMinifiedString
Returns a minified parsable representation of the rule list of this sheet.Equivalent to
getCssRules().toMinifiedString()
.- 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
Description copied from class:AbstractCSSStyleSheet
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.
Even if a specific media is set at the
InputSource
, this method does not alter the sheet's current media attribute.The comments shall be processed according to
CSSStyleSheet.COMMENTS_AUTO
.To create a sheet, see
CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)
- Specified by:
parseStyleSheet
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
parseStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
reader
- the character stream containing the CSS sheet.- Returns:
true
if the NSAC parser reported no errors or fatal errors, false otherwise.- Throws:
DOMException
- if raised by the error handler.IOException
- if a problem is found reading the 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.
If
commentMode
is notCOMMENTS_IGNORE
, the comments preceding a rule shall be available throughCSSRule.getPrecedingComments()
, and ifCOMMENTS_AUTO
was set also the trailing ones, through the methodCSSRule.getTrailingComments()
.This method resets the state of this sheet's error handler.
To create a sheet, see
CSSStyleSheetFactory.createStyleSheet(String,MediaQueryList)
- Specified by:
parseStyleSheet
in interfaceCSSStyleSheet<AbstractCSSRule>
- Specified by:
parseStyleSheet
in classAbstractCSSStyleSheet
- Parameters:
reader
- the character stream containing the CSS sheet.commentMode
-0
if comments have to be ignored,1
if all comments are considered as preceding a rule,2
if the parser should try to figure out which comments are preceding and trailing a rule (auto mode).- Returns:
true
if the SAC parser reported no errors or fatal errors, false otherwise.- Throws:
DOMException
- if raised by the error handler.IOException
- if a problem is found reading the sheet.
-