Package com.openhtmltopdf.css.newmatch
Class Selector
- java.lang.Object
-
- com.openhtmltopdf.css.newmatch.Selector
-
public class Selector extends java.lang.ObjectA Selector is really a chain of CSS selectors that all need to be valid for the selector to match.
-
-
Field Summary
Fields Modifier and Type Field Description private Selector_ancestorSelectorprivate int_axisprivate java.lang.String_nameprivate java.lang.String_namespaceURIprivate Ruleset_parentprivate int_pcprivate java.lang.String_peprivate int_posprivate int_specificityBprivate int_specificityCprivate int_specificityDstatic intACTIVE_PSEUDOCLASSprivate SelectorchainedSelectorstatic intCHILD_AXISprivate java.util.List<Condition>conditionsstatic intDESCENDANT_AXISstatic intFOCUS_PSEUDOCLASSstatic intHOVER_PSEUDOCLASSstatic intIMMEDIATE_SIBLING_AXISprivate static intselectorCountprivate intselectorIDGive each a unique ID to be able to create a key to internalize Matcher.Mappersprivate SelectorsiblingSelectorstatic intVISITED_PSEUDOCLASS
-
Constructor Summary
Constructors Constructor Description Selector()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttributeEqualsCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute=value]voidaddAttributeExistsCondition(java.lang.String namespaceURI, java.lang.String name)the CSS condition [attribute]voidaddAttributeMatchesFirstPartCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute|=value]voidaddAttributeMatchesListCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute~=value]voidaddAttributePrefixCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute^=value]voidaddAttributeSubstringCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute*=value]voidaddAttributeSuffixCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute$=value]voidaddClassCondition(java.lang.String className)the CSS condition .classprivate voidaddCondition(Condition c)Adds a feature to the Condition attribute of the Selector objectvoidaddEvenChildCondition()the CSS condition that element has pseudo-class :evenvoidaddFirstChildCondition()the CSS condition that element has pseudo-class :first-childvoidaddIDCondition(java.lang.String id)the CSS condition #IDvoidaddLangCondition(java.lang.String lang)the CSS condition :lang(Xx)voidaddLastChildCondition()the CSS condition that element has pseudo-class :last-childvoidaddLinkCondition()the CSS condition that element has pseudo-class :linkvoidaddNthChildCondition(java.lang.String number)the CSS condition that element has pseudo-class :nth-child(an+b)voidaddOddChildCondition()the CSS condition that element has pseudo-class :oddvoidaddUnsupportedCondition()for unsupported or invalid CSSSelectorgetAncestorSelector()(package private) java.lang.ObjectgetAppropriateSibling(java.lang.Object e, TreeResolver treeRes)Gets the appropriateSibling attribute of the Selector objectintgetAxis()get the axis that this selector should be evaluated onSelectorgetChainedSelector()get the next selector in the chain, for matching against elements along the appropriate axis(package private) static java.lang.StringgetElementStylingOrder()Gets the elementStylingOrder attribute of the Selector class(package private) java.lang.StringgetOrder()returns "a number in a large base" with specificity and specification order of selectorjava.lang.StringgetPseudoElement()Gets the pseudoElement attribute of the Selector objectRulesetgetRuleset()get the Ruleset that this Selector is part ofintgetSelectorID()intgetSpecificityB()The correct specificity value for this selector and its sibling-axis selectorsintgetSpecificityC()The correct specificity value for this selector and its sibling-axis selectorsintgetSpecificityD()The correct specificity value for this selector and its sibling-axis selectorsbooleanisPseudoClass(int pc)query if a pseudoclass must apply for this selectorbooleanmatches(java.lang.Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector.booleanmatchesDynamic(java.lang.Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector's dynamic properties.voidsetAncestorSelector(Selector ancestor)voidsetAxis(int axis)voidsetChainedSelector(Selector selector)voidsetName(java.lang.String name)voidsetNamespaceURI(java.lang.String namespaceURI)voidsetParent(Ruleset ruleset)voidsetPos(int pos)voidsetPseudoClass(int pc)set which pseudoclasses must apply for this selectorvoidsetPseudoElement(java.lang.String pseudoElement)check if selector queries for dynamic propertiesvoidsetSiblingSelector(Selector selector)voidsetSpecificityB(int b)voidsetSpecificityC(int c)voidsetSpecificityD(int d)voidtoCSS(java.lang.StringBuilder sb, java.util.Set<Selector> stopAt)Prints the selector chain to a StringBuilder, stopping when it hits a selector in the stopAt set.java.lang.StringtoString()For debugging, prints the entire selector chain.
-
-
-
Field Detail
-
_parent
private Ruleset _parent
-
chainedSelector
private Selector chainedSelector
-
siblingSelector
private Selector siblingSelector
-
_axis
private int _axis
-
_name
private java.lang.String _name
-
_namespaceURI
private java.lang.String _namespaceURI
-
_pc
private int _pc
-
_pe
private java.lang.String _pe
-
_specificityB
private int _specificityB
-
_specificityC
private int _specificityC
-
_specificityD
private int _specificityD
-
_pos
private int _pos
-
conditions
private java.util.List<Condition> conditions
-
DESCENDANT_AXIS
public static final int DESCENDANT_AXIS
- See Also:
- Constant Field Values
-
CHILD_AXIS
public static final int CHILD_AXIS
- See Also:
- Constant Field Values
-
IMMEDIATE_SIBLING_AXIS
public static final int IMMEDIATE_SIBLING_AXIS
- See Also:
- Constant Field Values
-
VISITED_PSEUDOCLASS
public static final int VISITED_PSEUDOCLASS
- See Also:
- Constant Field Values
-
HOVER_PSEUDOCLASS
public static final int HOVER_PSEUDOCLASS
- See Also:
- Constant Field Values
-
ACTIVE_PSEUDOCLASS
public static final int ACTIVE_PSEUDOCLASS
- See Also:
- Constant Field Values
-
FOCUS_PSEUDOCLASS
public static final int FOCUS_PSEUDOCLASS
- See Also:
- Constant Field Values
-
selectorID
private int selectorID
Give each a unique ID to be able to create a key to internalize Matcher.Mappers
-
_ancestorSelector
private Selector _ancestorSelector
-
selectorCount
private static int selectorCount
-
-
Method Detail
-
matches
public boolean matches(java.lang.Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector. Note: the parser should give all class
-
matchesDynamic
public boolean matchesDynamic(java.lang.Object e, AttributeResolver attRes, TreeResolver treeRes)Check if the given Element matches this selector's dynamic properties. Note: the parser should give all class
-
addUnsupportedCondition
public void addUnsupportedCondition()
for unsupported or invalid CSS
-
addLinkCondition
public void addLinkCondition()
the CSS condition that element has pseudo-class :link
-
addFirstChildCondition
public void addFirstChildCondition()
the CSS condition that element has pseudo-class :first-child
-
addLastChildCondition
public void addLastChildCondition()
the CSS condition that element has pseudo-class :last-child
-
addNthChildCondition
public void addNthChildCondition(java.lang.String number)
the CSS condition that element has pseudo-class :nth-child(an+b)
-
addEvenChildCondition
public void addEvenChildCondition()
the CSS condition that element has pseudo-class :even
-
addOddChildCondition
public void addOddChildCondition()
the CSS condition that element has pseudo-class :odd
-
addLangCondition
public void addLangCondition(java.lang.String lang)
the CSS condition :lang(Xx)
-
addIDCondition
public void addIDCondition(java.lang.String id)
the CSS condition #ID
-
addClassCondition
public void addClassCondition(java.lang.String className)
the CSS condition .class
-
addAttributeExistsCondition
public void addAttributeExistsCondition(java.lang.String namespaceURI, java.lang.String name)the CSS condition [attribute]
-
addAttributeEqualsCondition
public void addAttributeEqualsCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute=value]
-
addAttributePrefixCondition
public void addAttributePrefixCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute^=value]
-
addAttributeSuffixCondition
public void addAttributeSuffixCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute$=value]
-
addAttributeSubstringCondition
public void addAttributeSubstringCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute*=value]
-
addAttributeMatchesListCondition
public void addAttributeMatchesListCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute~=value]
-
addAttributeMatchesFirstPartCondition
public void addAttributeMatchesFirstPartCondition(java.lang.String namespaceURI, java.lang.String name, java.lang.String value)the CSS condition [attribute|=value]
-
setPseudoClass
public void setPseudoClass(int pc)
set which pseudoclasses must apply for this selector- Parameters:
pc- the values from AttributeResolver should be used. Once set they cannot be unset. Note that the pseudo-classes should be set one at a time, otherwise specificity of declaration becomes wrong.
-
setPseudoElement
public void setPseudoElement(java.lang.String pseudoElement)
check if selector queries for dynamic properties- Parameters:
pseudoElement- The new pseudoElement value
-
isPseudoClass
public boolean isPseudoClass(int pc)
query if a pseudoclass must apply for this selector- Parameters:
pc- the values from AttributeResolver should be used.- Returns:
- The pseudoClass value
-
getPseudoElement
public java.lang.String getPseudoElement()
Gets the pseudoElement attribute of the Selector object- Returns:
- The pseudoElement value
-
getChainedSelector
public Selector getChainedSelector()
get the next selector in the chain, for matching against elements along the appropriate axis- Returns:
- The chainedSelector value
-
getRuleset
public Ruleset getRuleset()
get the Ruleset that this Selector is part of- Returns:
- The ruleset value
-
getAxis
public int getAxis()
get the axis that this selector should be evaluated on- Returns:
- The axis value
-
getSpecificityB
public int getSpecificityB()
The correct specificity value for this selector and its sibling-axis selectors
-
getSpecificityD
public int getSpecificityD()
The correct specificity value for this selector and its sibling-axis selectors
-
getSpecificityC
public int getSpecificityC()
The correct specificity value for this selector and its sibling-axis selectors
-
getOrder
java.lang.String getOrder()
returns "a number in a large base" with specificity and specification order of selector- Returns:
- The order value
-
getAppropriateSibling
java.lang.Object getAppropriateSibling(java.lang.Object e, TreeResolver treeRes)Gets the appropriateSibling attribute of the Selector object- Parameters:
e- PARAMtreeRes-- Returns:
- The appropriateSibling value
-
addCondition
private void addCondition(Condition c)
Adds a feature to the Condition attribute of the Selector object- Parameters:
c- The feature to be added to the Condition attribute
-
toCSS
public void toCSS(java.lang.StringBuilder sb, java.util.Set<Selector> stopAt)Prints the selector chain to a StringBuilder, stopping when it hits a selector in the stopAt set. For example, given the selector 'body svg rect' and the stop set contains 'svg' then this will print 'rect' to the builder. This method is used to recreate CSS selectors to pass to SVG or other plugins. FIXME: Does not handle sibling selector.
-
getElementStylingOrder
static java.lang.String getElementStylingOrder()
Gets the elementStylingOrder attribute of the Selector class- Returns:
- The elementStylingOrder value
-
getSelectorID
public int getSelectorID()
-
setName
public void setName(java.lang.String name)
-
setPos
public void setPos(int pos)
-
setParent
public void setParent(Ruleset ruleset)
-
setAxis
public void setAxis(int axis)
-
setSpecificityB
public void setSpecificityB(int b)
-
setSpecificityC
public void setSpecificityC(int c)
-
setSpecificityD
public void setSpecificityD(int d)
-
setChainedSelector
public void setChainedSelector(Selector selector)
-
setSiblingSelector
public void setSiblingSelector(Selector selector)
-
setNamespaceURI
public void setNamespaceURI(java.lang.String namespaceURI)
-
setAncestorSelector
public void setAncestorSelector(Selector ancestor)
-
getAncestorSelector
public Selector getAncestorSelector()
-
toString
public java.lang.String toString()
For debugging, prints the entire selector chain. FIXME: Does not handle sibling selectors.- Overrides:
toStringin classjava.lang.Object
-
-