Top Description Fields Constructors Methods
com.openhtmltopdf.css.newmatch

public Class CascadedStyle

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collections, .Iterator, .List, .Map, .TreeMap, com.openhtmltopdf.css.constants.CSSName, .IdentValue, com.openhtmltopdf.css.parser.CSSPrimitiveValue, .PropertyValue, com.openhtmltopdf.css.sheet.PropertyDeclaration, .StylesheetInfo

Holds a set of com.openhtmltopdf.css.sheet.PropertyDeclarations for each unique CSS property name. What properties belong in the set is not determined, except that multiple entries are resolved into a single set using cascading rules. The set is cascaded during instantiation, so once you have a CascadedStyle, the PropertyDeclarations you retrieve from it will have been resolved following the CSS cascading rules. Note that this class knows nothing about CSS selector-matching rules. Before creating a CascadedStyle, you will need to determine which PropertyDeclarations belong in the set--for example, by matching com.openhtmltopdf.css.sheet.Rulesets to org.w3c.dom.Document org.w3c.dom.Elements via their selectors. You can get individual properties by using propertyByName(CSSName) or an java.util.Iterator of properties with getCascadedPropertyDeclarations(). Check for individual property assignments using hasProperty(CSSName). A CascadedStyle is immutable, as properties can not be added or removed from it once instantiated.
Authors
Torbjoern Gannholm, Patrick Wright

Field Summary

Modifier and TypeField and Description
private final Map<CSSName, PropertyDeclaration>
cascadedProperties

Map of PropertyDeclarations, keyed by CSSName

public static final CascadedStyle
emptyCascadedStyle

Get an empty singleton, used to negate inheritance of properties

private String

Constructor Summary

AccessConstructor and Description
pack-priv
CascadedStyle(Iterator<PropertyDeclaration>
An Iterator containing PropertyDeclarations in order of specificity.
iter
)

Constructs a new CascadedStyle, given an java.util.Iterator of com.openhtmltopdf.css.sheet.PropertyDeclarations already sorted by specificity of the CSS selector they came from.

private
private
CascadedStyle()

Default constructor with no initialization.

Method Summary

Modifier and TypeMethod and Description
private void
public int
public static CascadedStyle
createAnonymousStyle(IdentValue display)

Creates an otherwise empty CascadedStyle, setting the display property to the value of the display parameter.

public static PropertyDeclaration
public static CascadedStyle
createLayoutStyle(PropertyDeclaration[]
An array of PropertyDeclaration objects created with createLayoutPropertyDeclaration(CSSName, IdentValue)
decls
)

Creates a CascadedStyle using the provided property declarations.

public static CascadedStyle
public static CascadedStyle
createLayoutStyle(CascadedStyle startingPoint, PropertyDeclaration[]
An array of PropertyDeclaration objects created with createLayoutPropertyDeclaration(CSSName, IdentValue)
decls
)

Creates a CascadedStyle using style information from startingPoint and then adding the property declarations from decls.

public Collection<PropertyDeclaration>

Returns:

Iterator over a set of properly cascaded PropertyDeclarations.
getCascadedPropertyDeclarations
()

Returns an java.util.Iterator over the set of com.openhtmltopdf.css.sheet.PropertyDeclarations already matched in this CascadedStyle.

public String
public IdentValue

Returns:

The ident value
getIdent
(CSSName
PARAM
cssName
)

Gets the ident attribute of the CascadedStyle object

public boolean

Returns:

True if the property is defined in this set.
hasProperty
(CSSName
The CSS property name, e.g. "font-family".
cssName
)

Returns true if property has been defined in this style.

public PropertyDeclaration

Returns:

The PropertyDeclaration, if declared in this set, or null if not found.
propertyByName
(CSSName
The CSS property name, e.g. "font-family".
cssName
)

Returns a com.openhtmltopdf.css.sheet.PropertyDeclaration by CSS property name, e.g. "font-family".

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cascadedPropertiesback to summary
private final Map<CSSName, PropertyDeclaration> cascadedProperties

Map of PropertyDeclarations, keyed by CSSName

emptyCascadedStyleback to summary
public static final CascadedStyle emptyCascadedStyle

Get an empty singleton, used to negate inheritance of properties

fingerprintback to summary
private String fingerprint

Constructor Detail

CascadedStyleback to summary
pack-priv CascadedStyle(Iterator<PropertyDeclaration> iter)

Constructs a new CascadedStyle, given an java.util.Iterator of com.openhtmltopdf.css.sheet.PropertyDeclarations already sorted by specificity of the CSS selector they came from. The Iterator can have multiple PropertyDeclarations with the same name; the property cascade will be resolved during instantiation, resulting in a set of PropertyDeclarations. Once instantiated, properties may be retrieved using the normal API for the class.

Parameters
iter:Iterator<PropertyDeclaration>

An Iterator containing PropertyDeclarations in order of specificity.

CascadedStyleback to summary
private CascadedStyle(CascadedStyle startingPoint, Iterator<PropertyDeclaration> props)
CascadedStyleback to summary
private CascadedStyle()

Default constructor with no initialization. Don't use this to instantiate the class, as the class is immutable and this will leave it without any properties.

Method Detail

addPropertiesback to summary
private void addProperties(Iterator<PropertyDeclaration> iter)
countAssignedback to summary
public int countAssigned()
createAnonymousStyleback to summary
public static CascadedStyle createAnonymousStyle(IdentValue display)

Creates an otherwise empty CascadedStyle, setting the display property to the value of the display parameter.

createLayoutPropertyDeclarationback to summary
public static PropertyDeclaration createLayoutPropertyDeclaration(CSSName cssName, IdentValue display)

Creates a PropertyDeclaration suitable for passing to createLayoutStyle(PropertyDeclaration[]) or createLayoutStyle(CascadedStyle, PropertyDeclaration[])

createLayoutStyleback to summary
public static CascadedStyle createLayoutStyle(PropertyDeclaration[] decls)

Creates a CascadedStyle using the provided property declarations. It is used when a box requires a style that does not correspond to anything in the parsed stylesheets.

Parameters
decls:PropertyDeclaration[]

An array of PropertyDeclaration objects created with createLayoutPropertyDeclaration(CSSName, IdentValue)

See Also
createLayoutPropertyDeclaration(CSSName, IdentValue)
createLayoutStyleback to summary
public static CascadedStyle createLayoutStyle(List<PropertyDeclaration> decls)
createLayoutStyleback to summary
public static CascadedStyle createLayoutStyle(CascadedStyle startingPoint, PropertyDeclaration[] decls)

Creates a CascadedStyle using style information from startingPoint and then adding the property declarations from decls.

Parameters
decls:PropertyDeclaration[]

An array of PropertyDeclaration objects created with createLayoutPropertyDeclaration(CSSName, IdentValue)

See Also
createLayoutPropertyDeclaration(CSSName, IdentValue)
getCascadedPropertyDeclarationsback to summary
public Collection<PropertyDeclaration> getCascadedPropertyDeclarations()

Returns an java.util.Iterator over the set of com.openhtmltopdf.css.sheet.PropertyDeclarations already matched in this CascadedStyle. For a given property name, there may be no match, in which case there will be no PropertyDeclaration for that property name in the Iterator.

Returns:Collection<PropertyDeclaration>

Iterator over a set of properly cascaded PropertyDeclarations.

getFingerprintback to summary
public String getFingerprint()
getIdentback to summary
public IdentValue getIdent(CSSName cssName)

Gets the ident attribute of the CascadedStyle object

Parameters
cssName:CSSName

PARAM

Returns:IdentValue

The ident value

hasPropertyback to summary
public boolean hasProperty(CSSName cssName)

Returns true if property has been defined in this style.

Parameters
cssName:CSSName

The CSS property name, e.g. "font-family".

Returns:boolean

True if the property is defined in this set.

propertyByNameback to summary
public PropertyDeclaration propertyByName(CSSName cssName)

Returns a com.openhtmltopdf.css.sheet.PropertyDeclaration by CSS property name, e.g. "font-family". Properties are already cascaded during instantiation, so this will return the actual property (and corresponding value) to use for CSS-based layout and rendering.

Parameters
cssName:CSSName

The CSS property name, e.g. "font-family".

Returns:PropertyDeclaration

The PropertyDeclaration, if declared in this set, or null if not found.