1 30 31 package com.steadystate.css.parser; 32 33 import java.io.*; 34 import org.w3c.css.sac.*; 35 import org.w3c.dom.css.*; 36 37 42 public class CSSOMParseTest extends Object { 43 44 45 public CSSOMParseTest() { 46 try { 47 Reader r = new StringReader("blah { margin-top: -1.5in; }"); 50 InputSource is = new InputSource(r); 51 CSSOMParser parser = new CSSOMParser(); 52 CSSStyleSheet ss = parser.parseStyleSheet(is); 53 System.out.println(ss.toString()); 54 55 CSSRuleList rl = ss.getCssRules(); 56 for (int i = 0; i < rl.getLength(); i++) { 57 CSSRule rule = rl.item(i); 58 if (rule.getType() == CSSRule.STYLE_RULE) { 59 CSSStyleRule sr = (CSSStyleRule) rule; 60 CSSStyleDeclaration style = sr.getStyle(); 61 for (int j = 0; j < style.getLength(); j++) { 62 CSSValue value = style.getPropertyCSSValue(style.item(j)); 63 if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { 64 CSSPrimitiveValue pv = (CSSPrimitiveValue) value; 65 System.out.println(">> " + pv.toString()); 66 if (pv.getPrimitiveType() == CSSPrimitiveValue.CSS_COUNTER) { 67 System.out.println("CSS_COUNTER(" + pv.toString() + ")"); 68 } 69 } 70 } 71 } 72 } 73 } catch (Exception e) { 74 System.err.println("Exception: " + e.getMessage()); 75 e.printStackTrace(System.err); 76 } 77 } 78 79 public static void main(String [] args) { 80 new CSSOMParseTest(); 81 } 82 } | Popular Tags |