KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > TestSerializable


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

30
31 package test;
32
33 import com.steadystate.css.parser.CSSOMParser;
34 import java.io.FileReader JavaDoc;
35 import java.io.FileInputStream JavaDoc;
36 import java.io.FileOutputStream JavaDoc;
37 import java.io.ObjectInput JavaDoc;
38 import java.io.ObjectOutput JavaDoc;
39 import java.io.ObjectInputStream JavaDoc;
40 import java.io.ObjectOutputStream JavaDoc;
41 import java.io.Reader JavaDoc;
42 import org.w3c.css.sac.InputSource;
43 import org.w3c.dom.css.CSSRule;
44 import org.w3c.dom.css.CSSRuleList;
45 import org.w3c.dom.css.CSSStyleSheet;
46
47 /**
48  *
49  * @author David Schweinsberg
50  * @version $Release$
51  */

52 public class TestSerializable {
53
54     /**
55     * @param args the command line arguments
56     */

57     public static void main (String JavaDoc args[]) {
58         try {
59 // Reader r = new FileReader("c:\\working\\css2parser\\stylesheets\\test.css");
60
Reader JavaDoc r = new FileReader JavaDoc("c:\\working\\css2parser\\stylesheets\\html40.css");
61             CSSOMParser parser = new CSSOMParser();
62             InputSource is = new InputSource(r);
63
64             CSSStyleSheet stylesheet = parser.parseStyleSheet(is);
65             
66             // Serialize the style sheet
67
FileOutputStream JavaDoc fo = new FileOutputStream JavaDoc("c:\\working\\css2parser\\stylesheets\\tmp");
68             ObjectOutput JavaDoc oo = new ObjectOutputStream JavaDoc(fo);
69             oo.writeObject(stylesheet);
70             oo.flush();
71             
72             // Read it back in
73
FileInputStream JavaDoc fi = new FileInputStream JavaDoc("c:\\working\\css2parser\\stylesheets\\tmp");
74             ObjectInput JavaDoc oi = new ObjectInputStream JavaDoc(fi);
75             CSSStyleSheet stylesheet2 = (CSSStyleSheet) oi.readObject();
76             
77             CSSRuleList rules = stylesheet2.getCssRules();
78
79             for (int i = 0; i < rules.getLength(); i++) {
80                 CSSRule rule = rules.item(i);
81                 System.out.println(rule.getCssText());
82             }
83         } catch (Exception JavaDoc e) {
84             System.out.println("Error.");
85             System.out.println(e.getMessage());
86             e.printStackTrace();
87         }
88     }
89
90 }
91
Popular Tags