com.mslinn.JBrowCaps
Class CssRule

java.lang.Object
  |
  +--com.mslinn.JBrowCaps.CssRule

public class CssRule
extends Object

This is a helper class for building a StyleSheet by adding rules to it. Models a collection of rules, which are CSS attributes each mapped to a selector.

Purpose of this class is to build the hashmap of the rule and create a collection of selectors.

Here is an example of a rule with three selectors (h3, .label and .small), and a declaration (font-family:arial,helvetica,sans-serif;).

h3, .label, .small {font-family:arial,helvetica,sans-serif;}

See Also:
parse(String) for a detailed description of allowable syntax for rules. The selector names are case sensitive, even for the built-in HTML 2.0 selectors such as h1 and H1.

This class treats h1 and H1 as two different selectors.


Field Summary
 HashMap rule
          Collection of property / value pairs.
 String[] selectors
          Array of selectors associated with this rule.
 
Constructor Summary
CssRule()
          Default constructor.
CssRule(CssRule oldRules)
          Copy constructor.
 
Method Summary
static void main(String[] args)
          For testing only.
 void parse(String str)
          Parse rule and return hashmap of selectors and declarations.
 String ruleToString()
          Print the rule Hashmap so it conforms to css formatting.
 void test()
          For testing only.
 String toString()
          Format CssRule for printing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rule

public HashMap rule
Collection of property / value pairs.

selectors

public String[] selectors
Array of selectors associated with this rule.
Constructor Detail

CssRule

public CssRule()
Default constructor.

CssRule

public CssRule(CssRule oldRules)
Copy constructor.
Method Detail

main

public static void main(String[] args)
                 throws JspException
For testing only.

parse

public void parse(String str)
           throws JspException
Parse rule and return hashmap of selectors and declarations. More than one selector may share the declarations. Optional whitespace may be used anywhere between tokens. Multiple declarations must be separated by a comma. Declarations consist of pairs of property names and values. All but the last value must be terminated by a semi-colon.

Syntax is:

selector[, selector[, selector]...] { property:value[; property:value]...] }
For example: h1, h2,h3{color:red;font-size:10pt}

Embedded rules are not supported:

  three-dee {
   background-lighting {
     azimuth: 30deg;
     elevation: 190deg;
   }
   H1 { color: red }
 }

ruleToString

public String ruleToString()
Print the rule Hashmap so it conforms to css formatting. Duplicated in StyleSheet because I'm tired.

test

public void test()
          throws JspException
For testing only. Can be called from console.

toString

public String toString()
Format CssRule for printing
Overrides:
toString in class Object


Written 2001 by Mike Slinn.  All rights reserved.
4230 Wooster Ave, San Mateo, CA 94403.
Tel: 650-571-8436   www.mslinn.com