1 /*
2 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 *
4 * This software is open source.
5 * See the bottom of this file for the licence.
6 */
7
8 package org.dom4j.io;
9
10 import junit.textui.TestRunner;
11
12 import java.io.ByteArrayOutputStream;
13 import java.io.File;
14 import java.io.StringWriter;
15
16 import org.dom4j.AbstractTestCase;
17 import org.dom4j.Document;
18 import org.dom4j.Element;
19
20 /***
21 * Test class for the XPP3Reader. This is based on the TestSaxReader class.
22 *
23 * @author <a href="mailto:pelle@neubia.com">Pelle Braendgaard </a>
24 * @author <a href="mailto:maartenc@sourceforge.net">Maarten Coene </a>
25 */
26 public class XPP3ReaderTest extends AbstractTestCase {
27 public static void main(String[] args) {
28 TestRunner.run(XPP3ReaderTest.class);
29 }
30
31 // Test case(s)
32 // -------------------------------------------------------------------------
33 public void testRussian() throws Exception {
34 File file = getFile("/xml/russArticle.xml");
35 XPP3Reader xmlReader = new XPP3Reader();
36 Document doc = xmlReader.read(file);
37 Element el = doc.getRootElement();
38
39 StringWriter writer = new StringWriter();
40 XMLWriter xmlWriter = new XMLWriter(writer);
41 OutputFormat format = OutputFormat.createPrettyPrint();
42 format.setEncoding("koi8-r");
43 xmlWriter.write(doc);
44 log(writer.toString());
45 }
46
47 public void testRussian2() throws Exception {
48 File file = getFile("/xml/russArticle.xml");
49 XPP3Reader xmlReader = new XPP3Reader();
50 Document doc = xmlReader.read(file);
51 XMLWriter xmlWriter = new XMLWriter(new OutputFormat("", false,
52 "koi8-r"));
53 ByteArrayOutputStream out = new ByteArrayOutputStream();
54 xmlWriter.setOutputStream(out);
55 xmlWriter.write(doc);
56 xmlWriter.flush();
57 xmlWriter.close();
58 log(out.toString());
59 }
60 }
61
62 /*
63 * Redistribution and use of this software and associated documentation
64 * ("Software"), with or without modification, are permitted provided that the
65 * following conditions are met:
66 *
67 * 1. Redistributions of source code must retain copyright statements and
68 * notices. Redistributions must also contain a copy of this document.
69 *
70 * 2. Redistributions in binary form must reproduce the above copyright notice,
71 * this list of conditions and the following disclaimer in the documentation
72 * and/or other materials provided with the distribution.
73 *
74 * 3. The name "DOM4J" must not be used to endorse or promote products derived
75 * from this Software without prior written permission of MetaStuff, Ltd. For
76 * written permission, please contact dom4j-info@metastuff.com.
77 *
78 * 4. Products derived from this Software may not be called "DOM4J" nor may
79 * "DOM4J" appear in their names without prior written permission of MetaStuff,
80 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
81 *
82 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
83 *
84 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
85 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
88 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
89 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
90 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
91 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
92 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
93 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
94 * POSSIBILITY OF SUCH DAMAGE.
95 *
96 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
97 */