- All Implemented Interfaces:
CSSStyleSheet<AbstractCSSRule>,NamespacePrefixMap,Parser.NamespaceMap,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
ConstructorsModifierConstructorDescriptionprotectedBaseCSSStyleSheet(String title, MediaQueryList media, AbstractCSSRule ownerRule, int origin) Constructs a style sheet. -
Method Summary
Modifier and TypeMethodDescriptionvoidAccept a declaration rule visitor.voidAccept a descriptor rule visitor.voidacceptStyleRuleVisitor(Visitor<CSSStyleRule> visitor) Accept a style rule visitor.protected voidaddLocalRule(CSSRule cssrule) Inserts a local rule in the current insertion point (generally after the last rule).voidaddRule(AbstractCSSRule cssrule) Inserts a rule in the current insertion point (generally after the last rule).voidAdds the rules contained by the supplied style sheet, if that sheet is not disabled.protected voidcopyAllTo(BaseCSSStyleSheet myCopy) protected voidcopyFieldsTo(BaseCSSStyleSheet myCopy) protected voidcopyRulesTo(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.createImportRule(String layerName, BooleanCondition supportsCondition, MediaQueryList mediaList, String defaultNamespaceURI, 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 BaseCSSStyleDeclarationCreate 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.voiddeleteRule(int index) Deletes a rule from the style sheet.booleanGets the collection of all CSS rules contained within the style sheet.booleanprotected ErrorHandlerGets 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.getNamespaceURI(String nsPrefix) Gets the namespace URI associated to the given prefix.intGet 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 BaseCSSStyleSheetFactoryGet the stylesheet factory used to produce this sheet.protected StringgetType()booleanHas this style sheet defined a default namespace ?inthashCode()booleanCheck whether this sheet contains rules that have errors or warnings reported to their handlers.intinsertRule(String rule, int index) Used to insert a new rule into the style sheet.booleanloadStyleSheet(URL url, String referrerPolicy) Load the styles fromurlinto this style sheet.booleanparseStyleSheet(Reader reader, short commentMode) Parses a style sheet.protected voidregisterNamespace(CSSNamespaceRule nsrule) Register the namespace from the given namespace rule.voidregisterNamespacePrefix(String prefix, String namespaceURI) Register a namespace prefix - URI pair.voidsetDisabled(boolean disabled) voidsetErrorHandler(SheetErrorHandler sheetErrorHandler) voidprotected voidsetMedia(MediaQueryList media) Set the destination media for this sheet.protected voidSets 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 aSTYLEelement with its attributes and content.protected voidunregisterNamespace(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, parseStyleSheetMethods inherited from class io.sf.carte.doc.style.css.om.AbstractStyleSheet
getTitle, setTitleMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.sf.carte.doc.style.css.CSSStyleSheet
createViewportRuleMethods inherited from interface org.w3c.dom.stylesheets.StyleSheet
getTitle
-
Constructor Details
-
BaseCSSStyleSheet
protected BaseCSSStyleSheet(String title, MediaQueryList media, AbstractCSSRule ownerRule, int 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:
getStyleSheetFactoryin interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
getStyleSheetFactoryin classAbstractCSSStyleSheet- Returns:
- the stylesheet factory.
-
getOwnerRule
- Specified by:
getOwnerRulein interfaceCSSStyleSheet- Specified by:
getOwnerRulein classAbstractCSSStyleSheet
-
getOwnerNode
-
getMedia
Description copied from interface:CSSStyleSheetGet the destination media for this sheet.- Returns:
- the media query list.
-
setMedia
Description copied from class:AbstractStyleSheetSet the destination media for this sheet.- Specified by:
setMediain classAbstractStyleSheet- Parameters:
media- the destination media.- Throws:
DOMException- if themediais invalid.
-
getOrigin
public int getOrigin()Description copied from class:AbstractCSSStyleSheetGet the origin of this sheet.- Specified by:
getOriginin classAbstractCSSStyleSheet- Returns:
- the origin of this sheet.
-
getCssRules
Description copied from interface:CSSStyleSheetGets the collection of all CSS rules contained within the style sheet.- Specified by:
getCssRulesin interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
getCssRulesin interfaceCSSStyleSheet- Specified by:
getCssRulesin 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@importrule 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).- Specified by:
addRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
addRulein classAbstractCSSStyleSheet- Parameters:
cssrule- the rule to be inserted.- Throws:
DOMException- NAMESPACE_ERR if the rule could not be added due to a namespace-related error.
-
registerNamespacePrefix
Description copied from interface:NamespacePrefixMapRegister a namespace prefix - URI pair.- Parameters:
prefix- the namespace prefix.namespaceURI- the namespace URI.
-
registerNamespace
Description copied from class:AbstractCSSStyleSheetRegister the namespace from the given namespace rule.- Specified by:
registerNamespacein classAbstractCSSStyleSheet- Parameters:
nsrule- the namespace rule.
-
unregisterNamespace
Description copied from class:AbstractCSSStyleSheetUnregister the namespace corresponding to the given namespace URI.- Specified by:
unregisterNamespacein 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:
addStyleSheetin interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
addStyleSheetin classAbstractCSSStyleSheet- Parameters:
sheet- the sheet whose rules are to be added.
-
createCounterStyleRule
Description copied from interface:CSSStyleSheetCreate 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:CSSStyleSheetCreate a CSS Font Face rule compatible with this implementation.- Specified by:
createFontFaceRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createFontFaceRulein classAbstractCSSStyleSheet- Returns:
- a CSS Font Face rule object.
-
createFontFeatureValuesRule
Description copied from interface:CSSStyleSheetCreate a CSSFontFeatureValuesRule compatible with this implementation.- Parameters:
fontFamily- the font family.- Returns:
- a CSSFontFeatureValuesRule object.
-
createImportRule
Description copied from interface:CSSStyleSheetCreate a CSS import rule compatible with this implementation.- Specified by:
createImportRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createImportRulein 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.
-
createImportRule
public ImportRule createImportRule(String layerName, BooleanCondition supportsCondition, MediaQueryList mediaList, String defaultNamespaceURI, String href) Description copied from interface:CSSStyleSheetCreate a CSS import rule compatible with this implementation.- Specified by:
createImportRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createImportRulein classAbstractCSSStyleSheet- Parameters:
layerName- the layer name declared in the at-rule itself, or an empty string if the layer is anonymous, ornullif the at-rule does not declare a layer.supportsCondition- the supports condition, ornullif none.mediaList- a list of media types for which the new import rule may be used.defaultNamespaceURI- the default namespace URI for the imported style sheet.href- the URI from which to import the sheet.- Returns:
- a CSS import rule.
-
createKeyframesRule
Description copied from interface:CSSStyleSheetCreate a CSSKeyframesRule compatible with this implementation.- Parameters:
keyframesName- the name of the keyframes.- Returns:
- a CSSKeyframesRule object.
-
createMarginRule
Description copied from interface:CSSStyleSheetCreate a CSS margin rule compatible with this implementation.- Parameters:
name- the margin rule name.- Returns:
- a CSS margin rule.
-
createMediaRule
Description copied from interface:CSSStyleSheetCreate a CSS media rule.- Specified by:
createMediaRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createMediaRulein classAbstractCSSStyleSheet- Parameters:
mediaList- a list of media types for the new rule.- Returns:
- a CSS media rule.
-
createNamespaceRule
Description copied from interface:CSSStyleSheetCreate 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:CSSStyleSheetCreate a CSS page rule compatible with this implementation.- Specified by:
createPageRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createPageRulein classAbstractCSSStyleSheet- Returns:
- a CSS page rule.
-
createPropertyRule
Description copied from interface:CSSStyleSheetCreate a CSS property rule compatible with this implementation.- Parameters:
name- the (unescaped) property name.- Returns:
- a CSS property rule.
-
createStyleRule
Description copied from interface:CSSStyleSheetCreate a CSS style rule.- Specified by:
createStyleRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createStyleRulein classAbstractCSSStyleSheet- Returns:
- a CSS style rule.
-
createSupportsRule
Description copied from interface:CSSStyleSheetCreate a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createSupportsRulein classAbstractCSSStyleSheet- Parameters:
condition- the@supportscondition.- Returns:
- a CSSSupportsRule object.
-
createSupportsRule
Description copied from interface:CSSStyleSheetCreate a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createSupportsRulein classAbstractCSSStyleSheet- Parameters:
conditionText- a serialization of the@supportscondition.- Returns:
- a CSSSupportsRule object.
- Throws:
DOMException- if the condition text could not be parsed.
-
createSupportsRule
Deprecated.Description copied from interface:CSSStyleSheetCreate a CSSSupportsRule compatible with this implementation.- Specified by:
createSupportsRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createSupportsRulein classAbstractCSSStyleSheet- Returns:
- a CSSSupportsRule object.
-
createUnknownRule
Description copied from interface:CSSStyleSheetCreate 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:
createUnknownRulein interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createUnknownRulein classAbstractCSSStyleSheet- Returns:
- a CSS unknown rule.
-
createStyleDeclaration
Description copied from class:AbstractCSSStyleSheetCreate a style declaration from the given declaration rule.- Specified by:
createStyleDeclarationin classAbstractCSSStyleSheet- Parameters:
rule- the declaration rule.- Returns:
- the style declaration.
-
createStyleDeclaration
Description copied from interface:CSSStyleSheetCreate a CSS style declaration compatible with this implementation.- Specified by:
createStyleDeclarationin interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
createStyleDeclarationin classAbstractCSSStyleSheet- Returns:
- a CSS style declaration.
-
hasRuleErrorsOrWarnings
public boolean hasRuleErrorsOrWarnings()Description copied from interface:CSSStyleSheetCheck whether this sheet contains rules that have errors or warnings reported to their handlers.- Returns:
trueif this sheet contains rules that have errors or warnings.
-
getErrorHandler
Description copied from interface:CSSStyleSheetGets the error handler for this style sheet.- Returns:
- the error handler.
-
setErrorHandler
- Specified by:
setErrorHandlerin classAbstractCSSStyleSheet
-
getDocumentErrorHandler
- Specified by:
getDocumentErrorHandlerin classAbstractStyleSheet
-
getType
-
getNamespacePrefix
Gets the namespace prefix associated to the given URI.- Specified by:
getNamespacePrefixin interfaceNamespacePrefixMap- Specified by:
getNamespacePrefixin classAbstractCSSStyleSheet- Parameters:
uri- the namespace URI string.- Returns:
- the namespace prefix.
-
getNamespaceURI
Description copied from interface:Parser.NamespaceMapGets the namespace URI associated to the given prefix.- Parameters:
nsPrefix- the namespace prefix.- Returns:
- the namespace URI string.
-
hasDefaultNamespace
public boolean hasDefaultNamespace()Has this style sheet defined a default namespace ?- Specified by:
hasDefaultNamespacein interfaceNamespacePrefixMap- Specified by:
hasDefaultNamespacein classAbstractCSSStyleSheet- Returns:
trueif a default namespace was defined,falseotherwise.
-
getDisabled
public boolean getDisabled() -
setDisabled
public void setDisabled(boolean disabled) -
getParentStyleSheet
- Specified by:
getParentStyleSheetin interfaceStyleSheet- Specified by:
getParentStyleSheetin classAbstractCSSStyleSheet
-
setParentStyleSheet
Description copied from class:AbstractCSSStyleSheetSets the parent style sheet.- Specified by:
setParentStyleSheetin classAbstractCSSStyleSheet- Parameters:
parent- the parent style sheet. Cannot benull.
-
getHref
-
setHref
- Specified by:
setHrefin classAbstractCSSStyleSheet
-
loadStyleSheet
Load the styles fromurlinto this style sheet.- Specified by:
loadStyleSheetin classAbstractCSSStyleSheet- Parameters:
url- the url to load the style sheet from.referrerPolicy- the content of thereferrerpolicycontent attribute, if any, or the empty string.- Returns:
trueif the NSAC parser reported no errors or fatal errors,falseotherwise.- 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
nullif 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
nullif 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
nullif 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:
getFirstStyleRulein classAbstractCSSStyleSheet- Parameters:
selectorList- the selector list.- Returns:
- the first style rule that matches, or
nullif none.
-
getStyleRules
Get the list of style rules that match the given selector.Rules inside grouping rules are also searched.
- Specified by:
getStyleRulesin classAbstractCSSStyleSheet- Parameters:
selector- the selector.- Returns:
- the list of style rule that match, or
nullif none.
-
acceptStyleRuleVisitor
Accept a style rule visitor.- Specified by:
acceptStyleRuleVisitorin classAbstractCSSStyleSheet- Parameters:
visitor- the visitor.
-
acceptDeclarationRuleVisitor
Accept a declaration rule visitor.- Specified by:
acceptDeclarationRuleVisitorin classAbstractCSSStyleSheet- Parameters:
visitor- the visitor.
-
acceptDescriptorRuleVisitor
Description copied from class:AbstractCSSStyleSheetAccept a descriptor rule visitor.This method scans for declaration rules that declare descriptors.
- Specified by:
acceptDescriptorRuleVisitorin classAbstractCSSStyleSheet- Parameters:
visitor- the visitor.
-
getTargetMedium
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractStyleSheet
-
equals
- Overrides:
equalsin classAbstractStyleSheet
-
toMinifiedString
Returns a minified parsable representation of the rule list of this sheet.Equivalent to
getCssRules().toMinifiedString().- Specified by:
toMinifiedStringin classAbstractStyleSheet- Returns:
- a minified parsable representation of the rule list of this sheet.
-
toString
-
toStyleString
Description copied from class:AbstractStyleSheetReturns a serialization of this style sheet in the form of aSTYLEelement with its attributes and content.- Specified by:
toStyleStringin classAbstractStyleSheet- Returns:
- an HTML
STYLEelement 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.
If
commentModeis notCOMMENTS_IGNORE, the comments preceding a rule shall be available throughCSSRule.getPrecedingComments(), and ifCOMMENTS_AUTOwas 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:
parseStyleSheetin interfaceCSSStyleSheet<AbstractCSSRule>- Specified by:
parseStyleSheetin classAbstractCSSStyleSheet- Parameters:
reader- the character stream containing the CSS sheet.commentMode-0if comments have to be ignored,1if all comments are considered as preceding a rule,2if the parser should try to figure out which comments are preceding and trailing a rule (auto mode).- Returns:
trueif 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.
-