KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > TestException


1 /*
2  * TestException.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: TestException.java,v 1.1.1.1 2003/12/28 21:22:42 davidsch Exp $
29  */

30
31 package test;
32
33 import java.io.*;
34 import com.steadystate.css.*;
35 import org.w3c.dom.*;
36 import org.w3c.dom.css.*;
37
38 /**
39  * Attempts to perform some illegal operations to ensure the correct exceptions
40  * are thrown.
41  *
42  * @author David Schweinsberg
43  * @version $Release$
44  */

45 public class TestException {
46
47     public static void main(String JavaDoc[] args) throws ParseException {
48         CSS2Parser parser = new CSS2Parser(System.in);
49
50         try {
51             CSSStyleSheet stylesheet = parser.styleSheet();
52
53             stylesheet.insertRule("P { color: blue }", 1);
54             stylesheet.insertRule("@import url(http://www.steadystate.com/primary.css);", 0);
55             stylesheet.insertRule("@charset \"US-ASCII\";", 0);
56             stylesheet.deleteRule(1);
57
58             CSSRuleList rules = stylesheet.getCssRules();
59             CSSRule rule = rules.item(1);
60             // rule.setCssText("@import url(bogus.css);");
61
rule.setCssText("H2 { smell: strong }");
62
63             int n = stylesheet.insertRule("@media speech { H1 { voice: male } }", 1);
64             rule = rules.item(n);
65             ((CSSMediaRule)rule).insertRule("P { voice: female }", 1);
66
67             System.out.println(((CSSMediaRule)rule).getMedia().getMediaText());
68             ((CSSMediaRule)rule).getMedia().setMediaText("speech, signlanguage");
69             System.out.println(((CSSMediaRule)rule).getMedia().getMediaText());
70             ((CSSMediaRule)rule).getMedia().deleteMedium("signlanguage");
71             System.out.println(((CSSMediaRule)rule).getMedia().getMediaText());
72             ((CSSMediaRule)rule).getMedia().appendMedium("semaphore");
73             // ((CSSMediaRule)rule).getMedia().delete("signlanguage");
74

75             // Print it out
76
for (int i = 0; i < rules.getLength(); i++) {
77                 rule = rules.item(i);
78                 System.out.println(rule.getCssText());
79             }
80         } catch(Exception JavaDoc e) {
81             System.out.println("Error.");
82             System.out.println(e.getMessage());
83             e.printStackTrace();
84         }
85     }
86 }
87
Popular Tags