Updated .cvsignore to be more minimalist, and only excludes the bin dir
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / xml / XStreamManager.java
1 package net.sourceforge.phpeclipse.wiki.xml;
2
3 import java.io.InputStream;
4 import java.io.InputStreamReader;
5 import java.io.Reader;
6
7 import com.thoughtworks.xstream.XStream;
8 import com.thoughtworks.xstream.io.xml.DomDriver;
9
10 public class XStreamManager {
11
12   public static String toXML(Page page) {
13     XStream xstream = new XStream(new DomDriver());
14     xstream.alias("page", Page.class);
15     xstream.changeDefaultConverter(new PageConverter(xstream.getClassMapper(), "revision"));
16     xstream.alias("revision", Revision.class);
17     return xstream.toXML(page);
18   }
19   
20   public static Page fromXML(String xmlString) {
21     XStream xstream = new XStream(new DomDriver());
22     xstream.alias("page", Page.class);
23     xstream.changeDefaultConverter(new PageConverter(xstream.getClassMapper(), "revision"));
24     xstream.alias("revision", Revision.class);
25     return (Page) xstream.fromXML(xmlString);
26   }
27   
28   public static Page fromXML(Reader xmlReader) {
29     XStream xstream = new XStream(new DomDriver());
30     xstream.alias("page", Page.class);
31     xstream.changeDefaultConverter(new PageConverter(xstream.getClassMapper(), "revision"));
32     xstream.alias("revision", Revision.class);
33     return (Page) xstream.fromXML(xmlReader);
34   }
35   
36   public static Page fromXML(InputStream iStream) {
37     InputStreamReader sReader = new InputStreamReader(iStream);
38     return fromXML(sReader);
39   }
40
41   public static void main(String[] args) {
42     Page page = new Page("20050129", "title", "body1");
43     page.add(new Revision("20050130", "body2", "Joe"));
44     page.add(new Revision("20050131", "body3"));
45     String xml = toXML(page);
46     System.out.println(xml);
47
48     Page newXML = (Page) fromXML(xml);
49     System.out.println(newXML);
50   }
51 }