| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.mslinn.JBrowCaps.StyleSheet
The StyleSheet class breaks down a CSS style sheet into equivalent HTML for older browsers and stores the style sheet rules as a HashMap of HashMaps. For any given browser capability, this class builds a separate HashMap (e.g. cssTrue is the HashMap containing markup for browsers that support CSS1, cssFalse is the HashMap containing markup for browsers that don't support CSS).
Each HashMap contains keys who's associated values are themselves HashMaps. In this way an entire set of rules for how to render HTML markup is associated with the tags defined in the stylesheet represented by this class.
For each entry in a rule's HashMap, this class translates it to equivalent HTML and accumulates three strings; one string to turn on formatting, one to turn off formatting, and one to provide for inline CSS formatting via the style tag.
This means that in order to support browsers that don't undertand CSS, browsers that do, and WML or i-mode browsers, the HashMap corresponding to each browser capability will have three key/value entries stored (one to turn formatting on, one to turn formatting off, and one for inline formatting).
This class is an application-level object (like all classes in the package save
 BrowserDetector); only one is required for a servlet
 application.
| Field Summary | |
|  HashMap | cssFalseContains map of format strings for browsers that don't support CSS. Add more HashMaps for each targeted type of browser (such as i-mode or WML). | 
|  HashMap | cssTrueContains map of css-compatible format strings. | 
|  boolean | debugControls debug output sent to System.out. | 
| Constructor Summary | |
| StyleSheet()Default constructor, requires subsequent initialization by calls to load(String)andbuildTargetMaps()before the HashMaps have useful
  values.  Should only be called during servlet initialization. | |
| StyleSheet(String cssFileName,
           HttpServletRequest request)One-step constructor, reads from default CSS style sheet in cssFileName. 
  Should only be called during servlet initialization. | |
| Method Summary | |
| protected  void | addCssRule(CssRule cssRule)Merge CssRule rule into a StyleSheet. Should only be called during servlet initialization. Declared as protected for debugging purposes; should actually be private. | 
| protected  void | addCssRule(String ruleString)Merge CssRule into a StyleSheet. Should only be called during servlet initialization. | 
|  boolean | browserSupportsCss()Detect browser capability. Should only be called at the start of each user session. | 
|  void | buildTargetMaps()Create cssTrueandcssFalse, which define all the formatting strings
  for JSP pages that want to use the stylesheet.  Should only be called during servlet
  initialization. | 
|  boolean | getError()Used to discover if there is an error condition in this class. | 
|  String | getErrorMsg()Used to obtain the error message. | 
|  Set | getSelectors()Used to discover the selectors defined in a stylesheet with a minimum of overhead. | 
|  HashMap | getStylesheetMap()Call after load(String)andbuildTargetMaps()have executed. | 
|  StyleSheet | load(String id)Read style sheet file and return a StyleSheet. | 
| static void | main(String[] args)For testing only, runs from command line. | 
| protected  String | read(String id,
     boolean removeComments)Read style sheet from file and return as String (including any error message). Should only be called during servlet initialization. Declared as protected for debugging purposes; should actually be private. | 
| protected  String | ruleToString(HashMap rule)Print the rule Hashmap so it conforms to css formatting. Duplicated in CssRule because I'm tired. | 
| protected  void | storeHtml(String selector,
          HashMap rule,
          HashMap targetMap)This method break down CSS formatting into equivalent HTML for older browsers. | 
|  void | test()Just for testing. | 
|  String | toString()Format StyleSheet for printing, not useful for serializing. Definitions are printed in sorted order. | 
| Methods inherited from class java.lang.Object | 
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
public HashMap cssTrue
public HashMap cssFalse
public boolean debug
System.out.| Constructor Detail | 
public StyleSheet()
Default constructor, requires subsequent initialization by calls to
  load(String) and
  buildTargetMaps() before the HashMaps have useful
  values.  Should only be called during servlet initialization.
public StyleSheet(String cssFileName,
                  HttpServletRequest request)
One-step constructor, reads from default CSS style sheet in cssFileName. 
  Should only be called during servlet initialization.
| Method Detail | 
protected void addCssRule(CssRule cssRule)
Merge CssRule rule into a StyleSheet. Should only be called during servlet initialization. Declared as protected for debugging purposes; should actually be private.
cssRule - CssRule containing the HashMap of selectors to add.
protected void addCssRule(String ruleString)
                   throws JspException
Merge CssRule into a StyleSheet. Should only be called during servlet initialization.
ruleString - String containing textual version of rule, which will be parsed prior to
  adding to the HashMap.  Declared as protected for debugging purposes; should actually be
  private.JspException - if there is a problem parsing the rule or adding the rule to the
  HashMap.public boolean browserSupportsCss()
Detect browser capability. Should only be called at the start of each user session.
public void buildTargetMaps()
Create cssTrue and cssFalse, which define all the formatting strings
  for JSP pages that want to use the stylesheet.  Should only be called during servlet
  initialization.
  Call after  Used to discover if there is an error condition in this class. Used to obtain the error message. Used to discover the selectors defined in a stylesheet with a minimum of overhead. Read style sheet file and return a StyleSheet. For testing only, runs from command line. Read style sheet from file and return as String (including any error message). 
  Should only be called during servlet initialization.   Declared as protected for debugging
  purposes; should actually be private. Print the rule Hashmap so it conforms to css formatting.  Duplicated in CssRule
  because I'm tired.  Declared as protected for debugging purposes; should actually be private. This method break down CSS formatting into equivalent HTML for older browsers.  Recall that a
 stylesheet is a HashMap of HashMaps.  For any given browser capability, this routine is called
 once for every selector (e.g.  For each entry in a rule's HashMap, this method translates it to equivalent HTML and accumulates
 three strings; one string to turn on formatting, one to turn off formatting, and one to provide for
 inline CSS formatting via the style tag. For example, to support browsers that don't undertand CSS, browsers that do, and i-mode or WML
 browsers, this method will be called once for each type of browser, with three different
  The method is declared as protected for debugging purposes; should actually be private. Format StyleSheet for printing, not useful for serializing.  Definitions are printed in
  sorted order.this stylesheet should have the default HTML 2.0 rules merged before calling
 buildTargetMaps() so that display:block is set for all block mode tags.
 If display:block is not set, then  tags are always emitted instead of 
getStylesheetMap
public HashMap getStylesheetMap()
load(String) and
  buildTargetMaps() have executed.
getError
public boolean getError()
getErrorMsg
public String getErrorMsg()
getSelectors
public Set getSelectors()
load
public StyleSheet load(String id)
                throws JspException
id - String containing name of stylesheet to read.JspException - if any error was encountered.
main
public static void main(String[] args)
                 throws JspException
read
protected String read(String id,
                      boolean removeComments)
               throws JspException
boolean - removeComments controls whether comments are to be removed or not.id - String containing name of stylesheet to read.JspException - if any error was encountered.
ruleToString
protected String ruleToString(HashMap rule)
rule - HashMap to print.
storeHtml
protected void storeHtml(String selector,
                         HashMap rule,
                         HashMap targetMap)
<h1>, <tt> or
 <tag class=myclass>). 
 Each selector has an associated HashMap containing a collection of definitions stored as a HashMap.
 This method walks the HashMap of definitions.targetMaps (one for each browser type), times the number of selectors in the
 stylesheet.
selector - String containing name of rule.rule - HashMap containing collection of definitions.targetMap - HashMap that will receive three new entries.
test
public void test()
          throws JspException
JspException - if uncommented.
toString
public String toString()
 
 
  
   
    Overview  
      Package  
    Class  
      Use  
      Tree  
      Deprecated  
      Index  
      Help  
  
 
 
 PREV CLASS 
 NEXT CLASS 
  FRAMES   
 NO FRAMES 
 
  SUMMARY:  INNER | FIELD | CONSTR | METHOD 
DETAIL:  FIELD | CONSTR | METHOD 
4230 Wooster Ave, San Mateo, CA 94403.
Tel: 650-571-8436   www.mslinn.com