1 package com.thoughtworks.xstream.io.xml;2 3 import java.io.Reader ;4 import java.io.IOException ;5 import java.io.Writer ;6 7 import org.jdom.Document;8 import org.jdom.JDOMException;9 import org.jdom.input.SAXBuilder;10 11 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;13 import com.thoughtworks.xstream.io.StreamException;14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;15 16 /**17 * @author Laurent Bihanic18 */19 public class JDomDriver implements HierarchicalStreamDriver {20 21 public HierarchicalStreamReader createReader(Reader reader) {22 try {23 SAXBuilder builder = new SAXBuilder();24 Document document = builder.build(reader);25 return new JDomReader(document);26 } catch (IOException e) {27 throw new StreamException(e);28 } catch (JDOMException e) {29 throw new StreamException(e);30 }31 }32 33 public HierarchicalStreamWriter createWriter(Writer out) {34 return new PrettyPrintWriter(out);35 }36 37 }38 39