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.StringWriter;
13
14 import org.dom4j.AbstractTestCase;
15
16 import org.w3c.dom.NamedNodeMap;
17
18 /***
19 * DOCUMENT ME!
20 *
21 * @author Maarten
22 */
23 public class DOMWriterTest extends AbstractTestCase {
24 public static void main(String[] args) {
25 TestRunner.run(DOMWriterTest.class);
26 }
27
28 public void testNamespaceBug() throws Exception {
29 org.dom4j.Document doc = getDocument("/xml/namespaces.xml");
30 DOMWriter writer = new DOMWriter(org.dom4j.dom.DOMDocument.class);
31 org.w3c.dom.Document result = writer.write(doc);
32
33 NamedNodeMap atts = result.getDocumentElement().getAttributes();
34 assertEquals(4, atts.getLength());
35
36 XMLWriter wr = new XMLWriter();
37 wr.setOutputStream(System.out);
38 wr.write((org.dom4j.Document) result);
39 }
40
41 public void testBug905745() throws Exception {
42 org.dom4j.Document doc = getDocument("/xml/namespaces.xml");
43 DOMWriter writer = new DOMWriter();
44 org.w3c.dom.Document result = writer.write(doc);
45
46 NamedNodeMap atts = result.getDocumentElement().getAttributes();
47 org.w3c.dom.Node versionAttr = atts.getNamedItem("version");
48 assertNotNull(versionAttr);
49 assertNotNull(versionAttr.getLocalName());
50 assertEquals("version", versionAttr.getLocalName());
51 assertEquals("version", versionAttr.getNodeName());
52 }
53
54 public void testBug926752() throws Exception {
55 org.dom4j.Document doc = getDocument("/xml/test/defaultNamespace.xml");
56 DOMWriter writer = new DOMWriter(org.dom4j.dom.DOMDocument.class);
57 org.w3c.dom.Document result = writer.write(doc);
58
59 NamedNodeMap atts = result.getDocumentElement().getAttributes();
60 assertEquals(1, atts.getLength());
61
62 OutputFormat format = OutputFormat.createCompactFormat();
63 format.setSuppressDeclaration(true);
64
65 XMLWriter wr = new XMLWriter(format);
66 StringWriter strWriter = new StringWriter();
67 wr.setWriter(strWriter);
68 wr.write((org.dom4j.Document) result);
69 assertEquals("<a xmlns=\"dummyNamespace\"><b><c>Hello</c></b></a>",
70 strWriter.toString());
71 }
72 }
73
74 /*
75 * Redistribution and use of this software and associated documentation
76 * ("Software"), with or without modification, are permitted provided that the
77 * following conditions are met:
78 *
79 * 1. Redistributions of source code must retain copyright statements and
80 * notices. Redistributions must also contain a copy of this document.
81 *
82 * 2. Redistributions in binary form must reproduce the above copyright notice,
83 * this list of conditions and the following disclaimer in the documentation
84 * and/or other materials provided with the distribution.
85 *
86 * 3. The name "DOM4J" must not be used to endorse or promote products derived
87 * from this Software without prior written permission of MetaStuff, Ltd. For
88 * written permission, please contact dom4j-info@metastuff.com.
89 *
90 * 4. Products derived from this Software may not be called "DOM4J" nor may
91 * "DOM4J" appear in their names without prior written permission of MetaStuff,
92 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
93 *
94 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
95 *
96 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
97 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
100 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
101 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
102 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
103 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
105 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106 * POSSIBILITY OF SUCH DAMAGE.
107 *
108 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
109 */