net.sf.vex.css
Class Rule

java.lang.Object
  |
  +--net.sf.vex.css.Rule

public class Rule
extends java.lang.Object

Represents a pairing of a selector with a list of styles. This does not exactly correspond to a rule in a style sheet; there is only one selector associated with an instance of this class, whereas multiple selectors may be associated with a style sheet rule. Note: Rule implements the Comparable interface in order to be sorted by "specificity" as defined by the CSS spec. However, this ordering is not consistent with equals (rules with the same specificity may not be equal). Therefore, Rule objects should not be used with sorted collections or maps in the java.util package, unless a suitable Comparator is also used.


Constructor Summary
Rule(byte source, Selector selector)
          Class constructor.
 
Method Summary
 void add(PropertyDecl decl)
          Adds a property declaration to the rule.
 PropertyDecl[] getPropertyDecls()
          Returns an array of the property declarations in this rule.
 Selector getSelector()
          Returns the selector for the rule.
 byte getSource()
          Returns the source of this rule.
 int getSpecificity()
          Calculates the specificity for the selector associated with this rule.
 boolean matches(Element element)
          Returns true if the given element matches this rule's selector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rule

public Rule(byte source,
            Selector selector)
Class constructor.

Parameters:
source - Source of the rule.
selector - Selector for the rule.
Method Detail

add

public void add(PropertyDecl decl)
Adds a property declaration to the rule.

Parameters:
decl - new property declaration to add

getSelector

public Selector getSelector()
Returns the selector for the rule.


getSource

public byte getSource()
Returns the source of this rule.

Returns:
one of StyleSheet.SOURCE_DEFAULT, StyleSheet.SOURCE_AUTHOR, or StyleSheet.SOURCE_USER.

getPropertyDecls

public PropertyDecl[] getPropertyDecls()
Returns an array of the property declarations in this rule.


getSpecificity

public int getSpecificity()
Calculates the specificity for the selector associated with this rule. The specificity is represented as an integer whose base-10 representation, xxxyyyzzz, can be decomposed into the number of "id" selectors (xxx), "class" selectors (yyy), and "element" selectors (zzz). Composite selectors result in a recursive call.


matches

public boolean matches(Element element)
Returns true if the given element matches this rule's selector.

Parameters:
element - Element to check.