KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joshy > html > css > CSSTest


1 package org.joshy.html.css;
2
3 import org.joshy.*;
4 import java.io.*;
5
6 import com.steadystate.css.*;
7 import com.steadystate.css.parser.*;
8 import org.w3c.dom.*;
9 import org.w3c.dom.css.*;
10 import org.w3c.css.sac.*;
11
12 public class CSSTest {
13
14     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
15         Reader r = new FileReader("test.css");
16         //CSS2Parser parser = new CSS2Parser(r);
17
CSSOMParser parser = new CSSOMParser();
18         InputSource is = new InputSource(r);
19         CSSStyleSheet stylesheet = parser.parseStyleSheet(is);
20         //u.p("stylesheet = " + stylesheet);
21

22         String JavaDoc css_text = "p { color: #f0f0f0; }";
23         stylesheet.insertRule(css_text,stylesheet.getCssRules().getLength());
24         stylesheet.insertRule("@import \"second.css\";",0);
25         u.p("stylesheet = " + stylesheet);
26         u.p("title = " + stylesheet.getTitle());
27         u.p("type = " + stylesheet.getType());
28         CSSRule rule = stylesheet.getCssRules().item(0);
29         u.p("first rule = " + rule);
30         CSSImportRule impru = (CSSImportRule)rule;
31         u.p("sub sheet = " + impru.getStyleSheet());
32         
33         /*
34         CSSRuleList list = stylesheet.getCssRules();
35         for(int i=0; i<list.getLength(); i++) {
36             CSSRule rule = list.item(i);
37             u.p("rule = " + rule);
38             if(rule.getType() == rule.STYLE_RULE) {
39                 CSSStyleRule style = (CSSStyleRule)rule;
40                 u.p("selector = " + style.getSelectorText());
41                 CSSStyleDeclaration decl = style.getStyle();
42                 u.p("decl = " + decl);
43                 for(int j=0; j<decl.getLength(); j++) {
44                     u.p("item = " + decl.item(j));
45                     u.p("value = " + decl.getPropertyCSSValue("color"));
46                 }
47             }
48         }
49         */

50     }
51
52 }
53
Popular Tags