KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > steadystate > css > parser > CSSOMParseTest


1 /*
2  * CSSOMParseTest.java
3  *
4  * Steady State CSS2 Parser
5  *
6  * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * To contact the authors of the library, write to Steady State Software Ltd.,
23  * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England
24  *
25  * http://www.steadystate.com/css/
26  * mailto:css@steadystate.co.uk
27  *
28  * $Id: CSSOMParseTest.java,v 1.1.1.1 2003/12/28 21:23:04 davidsch Exp $
29  */

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 /**
38  *
39  * @author David Schweinsberg
40  * @version $Release$
41  */

42 public class CSSOMParseTest extends Object JavaDoc {
43
44     /** Creates new CSSOMParseTest */
45     public CSSOMParseTest() {
46         try {
47             // Reader r = new FileReader("c:\\working\\css2parser\\stylesheets\\page_test.css");
48
// Reader r = new StringReader("FOO { color: rgb(1,2,3) }");
49
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 JavaDoc e) {
74             System.err.println("Exception: " + e.getMessage());
75             e.printStackTrace(System.err);
76         }
77     }
78
79     public static void main(String JavaDoc[] args) {
80         new CSSOMParseTest();
81     }
82 }
Popular Tags