1   /*
2    * Copyright 2001-2004 (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    * $Id: TestDocumentSource.java,v 1.3 2004/06/25 08:03:50 maartenc Exp $
8    */
9   
10  package org.dom4j.io;
11  
12  import java.io.ByteArrayOutputStream;
13  import java.io.File;
14  import java.io.FileOutputStream;
15  import java.io.StringReader;
16  import java.io.StringWriter;
17  import java.net.URL;
18  import java.util.List;
19  import javax.xml.transform.Transformer;
20  import javax.xml.transform.TransformerFactory;
21  import javax.xml.transform.stream.StreamResult;
22  
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import junit.framework.TestSuite;
26  import junit.textui.TestRunner;
27  import org.dom4j.Document;
28  import org.dom4j.DocumentHelper;
29  import org.dom4j.Element;
30  import org.dom4j.io.XMLWriter;
31  import org.xml.sax.EntityResolver;
32  import org.xml.sax.InputSource;
33  
34  /*** 
35    *
36    * @author <a href="mailto:maartenc@sourceforge.net">Maarten Coene</a>
37    */
38  public class TestDocumentSource extends TestCase {
39  
40      public static void main( String[] args ) {
41          TestRunner.run( suite() );
42      }
43      
44      public static Test suite() {
45          return new TestSuite( TestDocumentSource.class );
46      }
47      
48      public TestDocumentSource(String name) {
49          super(name);
50      }
51  
52      // Test case(s)
53      //-------------------------------------------------------------------------
54      public void testBug555549() throws Exception {
55          // simulate <cr><lf>
56          String xml = "<field id='Description' type='textarea'>line1" + (char) 13 + (char) 10 +
57                       "line2</field>";
58          Document doc = DocumentHelper.parseText(xml);
59          TransformerFactory tf = TransformerFactory.newInstance();
60          Transformer txml = tf.newTransformer();
61          StringWriter writer = new StringWriter();
62          txml.transform(new DocumentSource(doc), new StreamResult(writer));
63          
64          System.out.println(writer.toString());
65          assertTrue(writer.toString().indexOf("&#13") == -1);
66      }
67      
68  }
69  
70  
71  
72  
73  /*
74   * Redistribution and use of this software and associated documentation
75   * ("Software"), with or without modification, are permitted provided
76   * that the following conditions are met:
77   *
78   * 1. Redistributions of source code must retain copyright
79   *    statements and notices.  Redistributions must also contain a
80   *    copy of this document.
81   *
82   * 2. Redistributions in binary form must reproduce the
83   *    above copyright notice, this list of conditions and the
84   *    following disclaimer in the documentation and/or other
85   *    materials provided with the distribution.
86   *
87   * 3. The name "DOM4J" must not be used to endorse or promote
88   *    products derived from this Software without prior written
89   *    permission of MetaStuff, Ltd.  For written permission,
90   *    please contact dom4j-info@metastuff.com.
91   *
92   * 4. Products derived from this Software may not be called "DOM4J"
93   *    nor may "DOM4J" appear in their names without prior written
94   *    permission of MetaStuff, Ltd. DOM4J is a registered
95   *    trademark of MetaStuff, Ltd.
96   *
97   * 5. Due credit should be given to the DOM4J Project - 
98   *    http://www.dom4j.org
99   *
100  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
101  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
102  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
103  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
104  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
105  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
106  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
107  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
108  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
109  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
110  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
111  * OF THE POSSIBILITY OF SUCH DAMAGE.
112  *
113  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
114  *
115  * $Id: TestDocumentSource.java,v 1.3 2004/06/25 08:03:50 maartenc Exp $
116  */