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; 35 import java.io.FileInputStream; 36 import java.io.FileOutputStream; 37 import java.io.ObjectInput; 38 import java.io.ObjectOutput; 39 import java.io.ObjectInputStream; 40 import java.io.ObjectOutputStream; 41 import java.io.Reader; 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 args[]) { 58 try { 59 // Reader r = new FileReader("c:\\working\\css2parser\\stylesheets\\test.css"); 60 Reader r = new FileReader("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 fo = new FileOutputStream("c:\\working\\css2parser\\stylesheets\\tmp"); 68 ObjectOutput oo = new ObjectOutputStream(fo); 69 oo.writeObject(stylesheet); 70 oo.flush(); 71 72 // Read it back in 73 FileInputStream fi = new FileInputStream("c:\\working\\css2parser\\stylesheets\\tmp"); 74 ObjectInput oi = new ObjectInputStream(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 e) { 84 System.out.println("Error."); 85 System.out.println(e.getMessage()); 86 e.printStackTrace(); 87 } 88 } 89 90 } 91