1 package org.joshy.html; 2 3 import java.util.List ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 import java.io.*; 7 import java.awt.Color ; 8 import org.joshy.u; 9 import org.joshy.x; 10 import org.joshy.html.css.*; 11 12 import com.steadystate.css.*; 13 import com.steadystate.css.parser.*; 14 import org.w3c.dom.*; 15 import org.w3c.dom.css.*; 16 import org.w3c.css.sac.*; 17 18 public class CSSBank extends CSSAccessor { 19 20 21 public List sheets; 22 public List style_nodes; 23 public List styles; 24 CSSParser parser; 25 26 27 public CSSBank() { 28 sheets = new ArrayList (); 29 style_nodes = new ArrayList (); 30 styles = new ArrayList (); 31 parser = new CSSParser(this); 32 } 33 34 35 public void parse(Reader reader) throws IOException { 36 parser.parse(reader); 37 } 38 public void parse(String reader) throws IOException { 39 parser.parse(reader); 40 } 41 42 public void parseInlineStyles(Element elem) throws IOException { 43 parser.parseInlineStyles(elem); 44 } 45 private void pullOutStyles(CSSStyleSheet sheet) throws IOException { 46 parser.pullOutStyles(sheet); 47 } 48 49 50 51 private Object getProperty(Node node, String prop) { 52 if(node.getNodeType() == node.TEXT_NODE) { 53 return getProperty(node.getParentNode(),prop); 54 } 55 if(node.getNodeType() == node.ELEMENT_NODE) { 56 return getProperty((Element)node,prop); 57 } 58 u.p("unknown node type: " + node); 59 u.p("type = " + node.getNodeType()); 60 return null; 61 } 62 63 public CSSValue getProperty(Element elem, String prop, boolean inherit) { 64 RuleFinder rf = new RuleFinder(this.styles); 66 CSSStyleDeclaration style_dec = rf.findRule(elem,prop,inherit); 67 if(style_dec == null) { 69 return null; 72 } 73 CSSValue val = style_dec.getPropertyCSSValue(prop); 74 if(val == null) { 75 if(elem.getParentNode() != null && inherit) { 77 if(elem.getParentNode() instanceof Element) { 79 return getProperty((Element)elem.getParentNode(),prop,inherit); 80 } 81 } 82 return null; 83 } 84 return val; 86 } 87 88 89 90 91 } 92 | Popular Tags |