01: /*
02: * Copyright (C) 2004, 2005, 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007, 2008 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 07. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.xml;
13:
14: import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader;
15: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17: import com.thoughtworks.xstream.io.StreamException;
18: import com.thoughtworks.xstream.io.xml.xppdom.Xpp3DomBuilder;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.OutputStream;
23: import java.io.OutputStreamWriter;
24: import java.io.Reader;
25: import java.io.UnsupportedEncodingException;
26: import java.io.Writer;
27:
28: public class XppDomDriver extends AbstractXmlDriver {
29:
30: public XppDomDriver() {
31: super (new XmlFriendlyReplacer());
32: }
33:
34: /**
35: * @since 1.2
36: */
37: public XppDomDriver(XmlFriendlyReplacer replacer) {
38: super (replacer);
39: }
40:
41: public HierarchicalStreamReader createReader(Reader xml) {
42: try {
43: return new XppDomReader(Xpp3DomBuilder.build(xml),
44: xmlFriendlyReplacer());
45: } catch (Exception e) {
46: throw new StreamException(e);
47: }
48: }
49:
50: public HierarchicalStreamReader createReader(InputStream in) {
51: try {
52: return createReader(new XmlHeaderAwareReader(in));
53: } catch (UnsupportedEncodingException e) {
54: throw new StreamException(e);
55: } catch (IOException e) {
56: throw new StreamException(e);
57: }
58: }
59:
60: public HierarchicalStreamWriter createWriter(Writer out) {
61: return new PrettyPrintWriter(out, xmlFriendlyReplacer());
62: }
63:
64: public HierarchicalStreamWriter createWriter(OutputStream out) {
65: return createWriter(new OutputStreamWriter(out));
66: }
67: }
|