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