com.inet.html.css
Class Selector

java.lang.Object
  extended by com.inet.html.css.Selector
All Implemented Interfaces:
java.lang.Comparable<Selector>

public class Selector
extends java.lang.Object
implements java.lang.Comparable<Selector>

Combines all Information about a selector and provides a comparator to compare separator priorities.

See Also:
level 1: http://www.w3.org/TR/REC-CSS1, level 2: http://www.w3.org/TR/REC-CSS2

Field Summary
static com.inet.html.css.Selector.Comparator COMPARATOR
           
 
Constructor Summary
Selector(java.lang.String selectorString, javax.swing.text.AttributeSet rule, int index)
          Creates a selector object from a single selector string
 
Method Summary
 int compareTo(Selector o)
          
 int getIndex()
          Returns the index which was set in the constructor
 int getLevelTotal()
          This value is the calculated weight of this selector in a base 256 numeric value
 HTML.Tag getMatchedTag()
          Get the tag if this selector has only a single HTML tag
 HTML.Tag getPrimaryTag()
          Returns the tag matched by the highest tag part of the selector.
 javax.swing.text.AttributeSet getRule()
          Returns the rule referenced by this selector
 boolean isAbsolutByElement()
          Returns true, if the match of this selector can be decided by only the toplevel element
 boolean isAbsolutByTag()
          Returns true, if the match of this selector can be decided by only the tag of the toplevel element
 boolean isUnversalTagOnly()
          Check if the selector is "*".
 boolean matches(javax.swing.text.Element targetElement)
          Performes the selector matching.
 void setSourceClass(java.lang.Object className)
          Modifies the class selector of the highest selector part to require a certain class as well.
 java.lang.String toExternal()
          Creates a CSS conform string of this selector
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMPARATOR

public static final com.inet.html.css.Selector.Comparator COMPARATOR
Constructor Detail

Selector

public Selector(java.lang.String selectorString,
                javax.swing.text.AttributeSet rule,
                int index)
Creates a selector object from a single selector string

Parameters:
selectorString - input string
rule - Attributes referenced by this selector
index - the index of this selector. The index has to be unique throughout the whole document!
Method Detail

getLevelTotal

public int getLevelTotal()
This value is the calculated weight of this selector in a base 256 numeric value

Returns:
= 65536 * IDs + 256 * classes + tags

getIndex

public int getIndex()
Returns the index which was set in the constructor

Returns:
index value

getMatchedTag

public HTML.Tag getMatchedTag()
Get the tag if this selector has only a single HTML tag

Returns:
the tag or null.

isUnversalTagOnly

public boolean isUnversalTagOnly()
Check if the selector is "*".

Returns:
true, only if it a universal selector

matches

public boolean matches(javax.swing.text.Element targetElement)
Performes the selector matching.

Parameters:
targetElement - the current Elment that should match
Returns:
true if this selector can be applied to the node

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

toExternal

public java.lang.String toExternal()
Creates a CSS conform string of this selector

Returns:
a CSS conform string of this selector

getRule

public javax.swing.text.AttributeSet getRule()
Returns the rule referenced by this selector

Returns:
CSS rule set

isAbsolutByElement

public boolean isAbsolutByElement()
Returns true, if the match of this selector can be decided by only the toplevel element

Returns:
Returns true, if the match of this selector can be decided by only the toplevel element

isAbsolutByTag

public boolean isAbsolutByTag()
Returns true, if the match of this selector can be decided by only the tag of the toplevel element

Returns:
Returns true, if the match of this selector can be decided by only the tag of the toplevel element

compareTo

public int compareTo(Selector o)

Specified by:
compareTo in interface java.lang.Comparable<Selector>

setSourceClass

public void setSourceClass(java.lang.Object className)
Modifies the class selector of the highest selector part to require a certain class as well. This is useful to bind all selectors of one source to a namespace defined by a class.

Parameters:
className - the class name

getPrimaryTag

public HTML.Tag getPrimaryTag()
Returns the tag matched by the highest tag part of the selector. If there is no tag specified in the highest part or the tag is unknown, null will be returned. Other than the getMatchedTag() method, this method will always return the tag name, even if the part has a class or ID etc. So it can be used to group selectors.

Returns:
the match tag or null.