org.apache.batik.css.engine

Class CSSEngine

public abstract class CSSEngine extends Object

This is the base class for all the CSS engines.
Nested Class Summary
protected classCSSEngine.CSSNavigableDocumentHandler
To handle mutations of a CSSNavigableDocument.
protected static classCSSEngine.DocumentAdapter
Provides an (empty) adapter for the DocumentHandler interface.
protected classCSSEngine.DOMAttrModifiedListener
To handle the element attributes modification in the associated document.
protected classCSSEngine.DOMCharacterDataModifiedListener
To handle the modification of a CSSStyleSheetNode.
protected classCSSEngine.DOMNodeInsertedListener
To handle the insertion of a CSSStyleSheetNode in the associated document.
protected classCSSEngine.DOMNodeRemovedListener
To handle the removal of a CSSStyleSheetNode from the associated document.
protected classCSSEngine.DOMSubtreeModifiedListener
To handle the removal of a CSSStyleSheetNode from the associated document.
interfaceCSSEngine.MainPropertyReceiver
Interface for people interesting in having 'primary' properties set.
protected classCSSEngine.StyleDeclarationBuilder
To build a StyleDeclaration object.
protected classCSSEngine.StyleDeclarationDocumentHandler
To parse a style declaration.
protected classCSSEngine.StyleDeclarationUpdateHandler
To parse a style declaration and update a StyleMap.
protected classCSSEngine.StyleSheetDocumentHandler
To parse a style sheet.
Field Summary
protected int[]ALL_PROPERTIES
Used to fire a change event for all the properties.
protected StringalternateStyleSheet
The alternate stylesheet title.
protected StringclassLocalName
The class attribute local name.
protected StringclassNamespaceURI
The class attribute namespace URI.
protected intcolorIndex
The color property index.
protected ParsedURLcssBaseURI
The current base URI.
protected CSSConditionFactorycssConditionFactory
The CSS condition factory.
protected CSSContextcssContext
The CSS context.
protected CSSEngine.CSSNavigableDocumentHandlercssNavigableDocumentListener
Listener for CSSNavigableDocument events.
protected Documentdocument
The associated document.
protected ParsedURLdocumentURI
The document URI.
protected EventListenerdomAttrModifiedListener
The DOMAttrModified event listener.
protected EventListenerdomCharacterDataModifiedListener
The DOMCharacterDataModified event listener.
protected EventListenerdomNodeInsertedListener
The DOMNodeInserted event listener.
protected EventListenerdomNodeRemovedListener
The DOMNodeRemoved event listener.
protected EventListenerdomSubtreeModifiedListener
The DOMSubtreeModified event listener.
protected CSSStylableElementelement
The current element.
protected ListfontFaces
List of StyleMap objects, one for each @font-face rule encountered by this CSSEngine.
protected intfontSizeIndex
The font-size property index.
protected StringIntMapindexes
The property/int mappings.
protected booleanisCSSNavigableDocument
Whether the document is a CSSNavigableDocument.
protected intlineHeightIndex
The line-height property index.
protected Listlisteners
The listeners.
protected static CSSEngineListener[]LISTENER_ARRAY
protected SACMediaListmedia
The media to use to cascade properties.
protected SetnonCSSPresentationalHints
The non CSS presentational hints.
protected StringnonCSSPresentationalHintsNamespaceURI
The non CSS presentational hints namespace URI.
protected ExtendedParserparser
The CSS parser.
protected String[]pseudoElementNames
The pseudo-element names.
protected NoderemovedStylableElementSibling
The right sibling of the last removed node.
protected SetselectorAttributes
The attributes found in stylesheets selectors.
protected StringIntMapshorthandIndexes
The shorthand-property/int mappings.
protected ShorthandManager[]shorthandManagers
The shorthand managers.
protected CSSEngine.StyleDeclarationBuilderstyleDeclarationBuilder
The style declaration document handler used to build a StyleDeclaration object.
protected CSSEngine.StyleDeclarationDocumentHandlerstyleDeclarationDocumentHandler
The style declaration document handler.
protected CSSEngine.StyleDeclarationUpdateHandlerstyleDeclarationUpdateHandler
The style declaration update handler.
protected StringstyleLocalName
The style attribute local name.
protected StringstyleNamespaceURI
The style attribute namespace URI.
protected CSSEngine.StyleSheetDocumentHandlerstyleSheetDocumentHandler
The style sheet document handler.
protected ListstyleSheetNodes
The DOM nodes which contains StyleSheets.
protected booleanstyleSheetRemoved
Whether a style sheet as been removed from the document.
protected CSSEngineUserAgentuserAgent
The user agent used for showing error messages.
protected StyleSheetuserAgentStyleSheet
The user-agent style-sheet.
protected StyleSheetuserStyleSheet
The user style-sheet.
protected ValueManager[]valueManagers
The value managers.
Constructor Summary
protected CSSEngine(Document doc, ParsedURL uri, ExtendedParser p, ValueManager[] vm, ShorthandManager[] sm, String[] pe, String sns, String sln, String cns, String cln, boolean hints, String hintsNS, CSSContext ctx)
Creates a new CSSEngine.
Method Summary
voidaddCSSEngineListener(CSSEngineListener l)
Adds a CSS engine listener.
protected voidaddEventListeners(EventTarget doc)
Adds event listeners to the document to track CSS changes.
protected voidaddMatchingRules(List rules, StyleSheet ss, Element elt, String pseudo)
Adds the rules matching the element/pseudo-element of given style sheet to the list.
protected voidaddRules(Element elt, String pseudo, StyleMap sm, ArrayList rules, short origin)
Adds the rules contained in the given list to a stylemap.
voiddispose()
Disposes the CSSEngine and all the attached resources.
protected voiddisposeStyleMaps(Node node)
Removes the style maps from each CSSStylableElement in the document.
protected voidfindSelectorAttributes(Set attrs, StyleSheet ss)
Finds the selector attributes in the given stylesheet.
protected voidfindStyleSheetNodes(Node n)
An auxiliary method for getStyleSheets().
protected voidfirePropertiesChangedEvent(Element target, int[] props)
Fires a CSSEngineEvent, given a list of modified properties.
StyleMapgetCascadedStyleMap(CSSStylableElement elt, String pseudo)
Returns the cascaded style of the given element/pseudo-element.
intgetColorIndex()
Returns the color property index.
ValuegetComputedStyle(CSSStylableElement elt, String pseudo, int propidx)
Returns the computed style of the given element/pseudo for the property corresponding to the given index.
ParsedURLgetCSSBaseURI()
Returns the current base-url.
CSSContextgetCSSContext()
Returns the CSS context.
CSSEngineUserAgentgetCSSEngineUserAgent()
protected static NodegetCSSFirstChild(Node n)
Returns the CSS first child node of the given node.
protected static NodegetCSSNextSibling(Node n)
Returns the CSS next sibling node of the given node.
static NodegetCSSParentNode(Node n)
Returns the CSS parent node of the given node.
protected static NodegetCSSPreviousSibling(Node n)
Returns the CSS previous sibling node of the given node.
DocumentgetDocument()
Returns the document associated with this engine.
ListgetFontFaces()
Gets the StyleMaps generated by @font-face rules encountered by this CSSEngine thus far.
intgetFontSizeIndex()
Returns the font-size property index.
intgetLineHeightIndex()
Returns the line-height property index.
intgetNumberOfProperties()
Returns the number of properties.
static CSSStylableElementgetParentCSSStylableElement(Element elt)
Returns the next stylable parent of the given element.
intgetPropertyIndex(String name)
Returns the property index, or -1.
StringgetPropertyName(int idx)
Returns the name of the property at the given index.
intgetShorthandIndex(String name)
Returns the shorthand property index, or -1.
ShorthandManager[]getShorthandManagers()
Returns the ShorthandManagers.
ListgetStyleSheetNodes()
Returns the document CSSStyleSheetNodes in a list.
ValueManager[]getValueManagers()
Returns the ValueManagers.
protected voidhandleAttrModified(Element e, Attr attr, short attrChange, String prevValue, String newValue)
Handles an attribute change in the document.
protected voidhandleCharacterDataModified(Node n)
Handles a character data modification in the document.
protected voidhandleNodeInserted(Node n)
Handles a node insertion in the document.
protected voidhandleNodeRemoved(Node n)
Handles a node removal from the document.
protected voidhandleSubtreeModified(Node ignored)
Handles a subtree modification in the document. todo the incoming Node is actually ignored (not used) here, but it seems caller-sites assume that it is used - is this done right?
protected booleanhasStyleSheetNode(Node n)
Returns whether the DOM subtree rooted at the specified node contains a CSSStyleSheetNode.
voidimportCascadedStyleMaps(Element src, CSSEngine srceng, Element dest)
Recursively imports the cascaded style from a source element to an element of the current document.
protected voidinlineStyleAttributeUpdated(CSSStylableElement elt, StyleMap style, short attrChange, String prevValue, String newValue)
Called when the inline style of the given element has been updated.
protected voidinvalidateProperties(Node node, int[] properties, boolean[] updated, boolean recascade)
Invalidates all the properties of the given node.
protected booleanmediaMatch(SACMediaList ml)
Whether the given media list matches the media list of this CSSEngine object.
protected voidnonCSSPresentationalHintUpdated(CSSStylableElement elt, StyleMap style, String property, short attrChange, String newValue)
Called when a non-CSS presentational hint has been updated.
ValueparsePropertyValue(CSSStylableElement elt, String prop, String value)
Parses and creates a property value from elt.
StyleDeclarationparseStyleDeclaration(CSSStylableElement elt, String value)
Parses and creates a style declaration.
StyleSheetparseStyleSheet(ParsedURL uri, String media)
Parses and creates a new style-sheet.
StyleSheetparseStyleSheet(InputSource is, ParsedURL uri, String media)
Parses and creates a new style-sheet.
voidparseStyleSheet(StyleSheet ss, ParsedURL uri)
Parses and fills the given style-sheet.
StyleSheetparseStyleSheet(String rules, ParsedURL uri, String media)
Parses and creates a new style-sheet.
voidparseStyleSheet(StyleSheet ss, String rules, ParsedURL uri)
Parses and fills the given style-sheet.
protected voidparseStyleSheet(StyleSheet ss, InputSource is, ParsedURL uri)
Parses and fills the given style-sheet.
protected voidpropagateChanges(Node node, int[] props, boolean recascade)
Propagates the changes that occurs on the parent of the given node.
protected voidputAuthorProperty(StyleMap dest, int idx, Value sval, boolean imp, short origin)
Puts an author property from a style-map in another style-map, if possible.
voidremoveCSSEngineListener(CSSEngineListener l)
Removes a CSS engine listener.
protected voidremoveEventListeners(EventTarget doc)
Removes the event listeners from the document.
voidsetAlternateStyleSheet(String str)
Sets the alternate style-sheet title.
voidsetCSSEngineUserAgent(CSSEngineUserAgent userAgent)
voidsetMainProperties(CSSStylableElement elt, CSSEngine.MainPropertyReceiver dst, String pname, String value, boolean important)
voidsetMedia(String str)
Sets the media to use to compute the styles.
voidsetUserAgentStyleSheet(StyleSheet ss)
Sets the user agent style-sheet.
voidsetUserStyleSheet(StyleSheet ss)
Sets the user style-sheet.
protected voidsortRules(ArrayList rules, Element elt, String pseudo)
Sorts the rules matching the element/pseudo-element of given style sheet to the list.

Field Detail

ALL_PROPERTIES

protected final int[] ALL_PROPERTIES
Used to fire a change event for all the properties.

alternateStyleSheet

protected String alternateStyleSheet
The alternate stylesheet title.

classLocalName

protected String classLocalName
The class attribute local name.

classNamespaceURI

protected String classNamespaceURI
The class attribute namespace URI.

colorIndex

protected int colorIndex
The color property index.

cssBaseURI

protected ParsedURL cssBaseURI
The current base URI.

cssConditionFactory

protected CSSConditionFactory cssConditionFactory
The CSS condition factory.

cssContext

protected CSSContext cssContext
The CSS context.

cssNavigableDocumentListener

protected CSSEngine.CSSNavigableDocumentHandler cssNavigableDocumentListener
Listener for CSSNavigableDocument events.

document

protected Document document
The associated document.

documentURI

protected ParsedURL documentURI
The document URI.

domAttrModifiedListener

protected EventListener domAttrModifiedListener
The DOMAttrModified event listener.

domCharacterDataModifiedListener

protected EventListener domCharacterDataModifiedListener
The DOMCharacterDataModified event listener.

domNodeInsertedListener

protected EventListener domNodeInsertedListener
The DOMNodeInserted event listener.

domNodeRemovedListener

protected EventListener domNodeRemovedListener
The DOMNodeRemoved event listener.

domSubtreeModifiedListener

protected EventListener domSubtreeModifiedListener
The DOMSubtreeModified event listener.

element

protected CSSStylableElement element
The current element.

fontFaces

protected List fontFaces
List of StyleMap objects, one for each @font-face rule encountered by this CSSEngine.

fontSizeIndex

protected int fontSizeIndex
The font-size property index.

indexes

protected StringIntMap indexes
The property/int mappings.

isCSSNavigableDocument

protected boolean isCSSNavigableDocument
Whether the document is a CSSNavigableDocument.

lineHeightIndex

protected int lineHeightIndex
The line-height property index.

listeners

protected List listeners
The listeners.

LISTENER_ARRAY

protected static final CSSEngineListener[] LISTENER_ARRAY

media

protected SACMediaList media
The media to use to cascade properties.

nonCSSPresentationalHints

protected Set nonCSSPresentationalHints
The non CSS presentational hints.

nonCSSPresentationalHintsNamespaceURI

protected String nonCSSPresentationalHintsNamespaceURI
The non CSS presentational hints namespace URI.

parser

protected ExtendedParser parser
The CSS parser.

pseudoElementNames

protected String[] pseudoElementNames
The pseudo-element names.

removedStylableElementSibling

protected Node removedStylableElementSibling
The right sibling of the last removed node.

selectorAttributes

protected Set selectorAttributes
The attributes found in stylesheets selectors.

shorthandIndexes

protected StringIntMap shorthandIndexes
The shorthand-property/int mappings.

shorthandManagers

protected ShorthandManager[] shorthandManagers
The shorthand managers.

styleDeclarationBuilder

protected CSSEngine.StyleDeclarationBuilder styleDeclarationBuilder
The style declaration document handler used to build a StyleDeclaration object.

styleDeclarationDocumentHandler

protected CSSEngine.StyleDeclarationDocumentHandler styleDeclarationDocumentHandler
The style declaration document handler.

styleDeclarationUpdateHandler

protected CSSEngine.StyleDeclarationUpdateHandler styleDeclarationUpdateHandler
The style declaration update handler.

styleLocalName

protected String styleLocalName
The style attribute local name.

styleNamespaceURI

protected String styleNamespaceURI
The style attribute namespace URI.

styleSheetDocumentHandler

protected CSSEngine.StyleSheetDocumentHandler styleSheetDocumentHandler
The style sheet document handler.

styleSheetNodes

protected List styleSheetNodes
The DOM nodes which contains StyleSheets.

styleSheetRemoved

protected boolean styleSheetRemoved
Whether a style sheet as been removed from the document.

userAgent

protected CSSEngineUserAgent userAgent
The user agent used for showing error messages.

userAgentStyleSheet

protected StyleSheet userAgentStyleSheet
The user-agent style-sheet.

userStyleSheet

protected StyleSheet userStyleSheet
The user style-sheet.

valueManagers

protected ValueManager[] valueManagers
The value managers.

Constructor Detail

CSSEngine

protected CSSEngine(Document doc, ParsedURL uri, ExtendedParser p, ValueManager[] vm, ShorthandManager[] sm, String[] pe, String sns, String sln, String cns, String cln, boolean hints, String hintsNS, CSSContext ctx)
Creates a new CSSEngine.

Parameters: doc The associated document. uri The document URI. p The CSS parser. vm The property value managers. sm The shorthand properties managers. pe The pseudo-element names supported by the associated XML dialect. Must be null if no support for pseudo- elements is required. sns The namespace URI of the style attribute. sln The local name of the style attribute. cns The namespace URI of the class attribute. cln The local name of the class attribute. hints Whether the CSS engine should support non CSS presentational hints. hintsNS The hints namespace URI. ctx The CSS context.

Method Detail

addCSSEngineListener

public void addCSSEngineListener(CSSEngineListener l)
Adds a CSS engine listener.

addEventListeners

protected void addEventListeners(EventTarget doc)
Adds event listeners to the document to track CSS changes.

addMatchingRules

protected void addMatchingRules(List rules, StyleSheet ss, Element elt, String pseudo)
Adds the rules matching the element/pseudo-element of given style sheet to the list.

addRules

protected void addRules(Element elt, String pseudo, StyleMap sm, ArrayList rules, short origin)
Adds the rules contained in the given list to a stylemap.

dispose

public void dispose()
Disposes the CSSEngine and all the attached resources.

disposeStyleMaps

protected void disposeStyleMaps(Node node)
Removes the style maps from each CSSStylableElement in the document.

findSelectorAttributes

protected void findSelectorAttributes(Set attrs, StyleSheet ss)
Finds the selector attributes in the given stylesheet.

findStyleSheetNodes

protected void findStyleSheetNodes(Node n)
An auxiliary method for getStyleSheets().

firePropertiesChangedEvent

protected void firePropertiesChangedEvent(Element target, int[] props)
Fires a CSSEngineEvent, given a list of modified properties.

getCascadedStyleMap

public StyleMap getCascadedStyleMap(CSSStylableElement elt, String pseudo)
Returns the cascaded style of the given element/pseudo-element.

Parameters: elt The stylable element. pseudo Optional pseudo-element string (null if none).

getColorIndex

public int getColorIndex()
Returns the color property index.

getComputedStyle

public Value getComputedStyle(CSSStylableElement elt, String pseudo, int propidx)
Returns the computed style of the given element/pseudo for the property corresponding to the given index.

getCSSBaseURI

public ParsedURL getCSSBaseURI()
Returns the current base-url.

getCSSContext

public CSSContext getCSSContext()
Returns the CSS context.

getCSSEngineUserAgent

public CSSEngineUserAgent getCSSEngineUserAgent()

getCSSFirstChild

protected static Node getCSSFirstChild(Node n)
Returns the CSS first child node of the given node.

getCSSNextSibling

protected static Node getCSSNextSibling(Node n)
Returns the CSS next sibling node of the given node.

getCSSParentNode

public static Node getCSSParentNode(Node n)
Returns the CSS parent node of the given node.

getCSSPreviousSibling

protected static Node getCSSPreviousSibling(Node n)
Returns the CSS previous sibling node of the given node.

getDocument

public Document getDocument()
Returns the document associated with this engine.

getFontFaces

public List getFontFaces()
Gets the StyleMaps generated by @font-face rules encountered by this CSSEngine thus far.

getFontSizeIndex

public int getFontSizeIndex()
Returns the font-size property index.

getLineHeightIndex

public int getLineHeightIndex()
Returns the line-height property index.

getNumberOfProperties

public int getNumberOfProperties()
Returns the number of properties.

getParentCSSStylableElement

public static CSSStylableElement getParentCSSStylableElement(Element elt)
Returns the next stylable parent of the given element.

getPropertyIndex

public int getPropertyIndex(String name)
Returns the property index, or -1.

getPropertyName

public String getPropertyName(int idx)
Returns the name of the property at the given index.

getShorthandIndex

public int getShorthandIndex(String name)
Returns the shorthand property index, or -1.

getShorthandManagers

public ShorthandManager[] getShorthandManagers()
Returns the ShorthandManagers.

getStyleSheetNodes

public List getStyleSheetNodes()
Returns the document CSSStyleSheetNodes in a list. This list is updated as the document is modified.

getValueManagers

public ValueManager[] getValueManagers()
Returns the ValueManagers.

handleAttrModified

protected void handleAttrModified(Element e, Attr attr, short attrChange, String prevValue, String newValue)
Handles an attribute change in the document.

handleCharacterDataModified

protected void handleCharacterDataModified(Node n)
Handles a character data modification in the document.

handleNodeInserted

protected void handleNodeInserted(Node n)
Handles a node insertion in the document.

handleNodeRemoved

protected void handleNodeRemoved(Node n)
Handles a node removal from the document.

handleSubtreeModified

protected void handleSubtreeModified(Node ignored)
Handles a subtree modification in the document. todo the incoming Node is actually ignored (not used) here, but it seems caller-sites assume that it is used - is this done right??

hasStyleSheetNode

protected boolean hasStyleSheetNode(Node n)
Returns whether the DOM subtree rooted at the specified node contains a CSSStyleSheetNode.

importCascadedStyleMaps

public void importCascadedStyleMaps(Element src, CSSEngine srceng, Element dest)
Recursively imports the cascaded style from a source element to an element of the current document.

inlineStyleAttributeUpdated

protected void inlineStyleAttributeUpdated(CSSStylableElement elt, StyleMap style, short attrChange, String prevValue, String newValue)
Called when the inline style of the given element has been updated.

invalidateProperties

protected void invalidateProperties(Node node, int[] properties, boolean[] updated, boolean recascade)
Invalidates all the properties of the given node.

mediaMatch

protected boolean mediaMatch(SACMediaList ml)
Whether the given media list matches the media list of this CSSEngine object.

nonCSSPresentationalHintUpdated

protected void nonCSSPresentationalHintUpdated(CSSStylableElement elt, StyleMap style, String property, short attrChange, String newValue)
Called when a non-CSS presentational hint has been updated.

parsePropertyValue

public Value parsePropertyValue(CSSStylableElement elt, String prop, String value)
Parses and creates a property value from elt.

Parameters: elt The element property is from. prop The property name. value The property value.

parseStyleDeclaration

public StyleDeclaration parseStyleDeclaration(CSSStylableElement elt, String value)
Parses and creates a style declaration.

Parameters: value The style declaration text.

parseStyleSheet

public StyleSheet parseStyleSheet(ParsedURL uri, String media)
Parses and creates a new style-sheet.

Parameters: uri The style-sheet URI. media The target media of the style-sheet.

parseStyleSheet

public StyleSheet parseStyleSheet(InputSource is, ParsedURL uri, String media)
Parses and creates a new style-sheet.

Parameters: is The input source used to read the document. uri The base URI. media The target media of the style-sheet.

parseStyleSheet

public void parseStyleSheet(StyleSheet ss, ParsedURL uri)
Parses and fills the given style-sheet.

Parameters: ss The stylesheet to fill. uri The base URI.

parseStyleSheet

public StyleSheet parseStyleSheet(String rules, ParsedURL uri, String media)
Parses and creates a new style-sheet.

Parameters: rules The style-sheet rules to parse. uri The style-sheet URI. media The target media of the style-sheet.

parseStyleSheet

public void parseStyleSheet(StyleSheet ss, String rules, ParsedURL uri)
Parses and fills the given style-sheet.

Parameters: ss The stylesheet to fill. rules The style-sheet rules to parse. uri The base URI.

parseStyleSheet

protected void parseStyleSheet(StyleSheet ss, InputSource is, ParsedURL uri)
Parses and fills the given style-sheet.

Parameters: ss The stylesheet to fill. uri The base URI.

propagateChanges

protected void propagateChanges(Node node, int[] props, boolean recascade)
Propagates the changes that occurs on the parent of the given node. Props is a list of known 'changed' properties. If recascade is true then the stylesheets will be applied again to see if the any new rules apply (or old rules don't apply).

putAuthorProperty

protected void putAuthorProperty(StyleMap dest, int idx, Value sval, boolean imp, short origin)
Puts an author property from a style-map in another style-map, if possible.

removeCSSEngineListener

public void removeCSSEngineListener(CSSEngineListener l)
Removes a CSS engine listener.

removeEventListeners

protected void removeEventListeners(EventTarget doc)
Removes the event listeners from the document.

setAlternateStyleSheet

public void setAlternateStyleSheet(String str)
Sets the alternate style-sheet title.

setCSSEngineUserAgent

public void setCSSEngineUserAgent(CSSEngineUserAgent userAgent)

setMainProperties

public void setMainProperties(CSSStylableElement elt, CSSEngine.MainPropertyReceiver dst, String pname, String value, boolean important)

setMedia

public void setMedia(String str)
Sets the media to use to compute the styles.

setUserAgentStyleSheet

public void setUserAgentStyleSheet(StyleSheet ss)
Sets the user agent style-sheet.

setUserStyleSheet

public void setUserStyleSheet(StyleSheet ss)
Sets the user style-sheet.

sortRules

protected void sortRules(ArrayList rules, Element elt, String pseudo)
Sorts the rules matching the element/pseudo-element of given style sheet to the list.
Copyright B) 2008 Apache Software Foundation. All Rights Reserved.