1 /* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package transform; 25 26 import java.io.ByteArrayInputStream; 27 import java.io.ByteArrayOutputStream; 28 import java.io.File; 29 import java.io.FileReader; 30 import java.io.InputStream; 31 32 import javax.xml.transform.Result; 33 import javax.xml.transform.Source; 34 import javax.xml.transform.Transformer; 35 import javax.xml.transform.TransformerFactory; 36 import javax.xml.transform.stream.StreamResult; 37 import javax.xml.transform.stream.StreamSource; 38 39 import org.testng.Assert; 40 import org.testng.annotations.Test; 41 42 /* 43 * @bug 6401137 44 * @summary Test transform certain xsl. 45 */ 46 public class CR6401137Test { 47 48 @Test 49 public final void testTransform() { 50 51 try { 52 String str = new String(); 53 ByteArrayOutputStream byte_stream = new ByteArrayOutputStream(); 54 File inputFile = new File(getClass().getResource("CR6401137.xml").getPath()); 55 FileReader in = new FileReader(inputFile); 56 int c; 57 58 while ((c = in.read()) != -1) { 59 str = str + new Character((char) c).toString(); 60 } 61 62 in.close(); 63 64 System.out.println(str); 65 byte buf[] = str.getBytes(); 66 byte_stream.write(buf); 67 String style_sheet_uri = "CR6401137.xsl"; 68 byte[] xml_byte_array = byte_stream.toByteArray(); 69 InputStream xml_input_stream = new ByteArrayInputStream(xml_byte_array); 70 71 Source xml_source = new StreamSource(xml_input_stream); 72 73 TransformerFactory tFactory = TransformerFactory.newInstance(); 74 Transformer transformer = tFactory.newTransformer(); 75 StreamSource source = new StreamSource(getClass().getResourceAsStream(style_sheet_uri)); 76 transformer = tFactory.newTransformer(source); 77 78 ByteArrayOutputStream result_output_stream = new ByteArrayOutputStream(); 79 Result result = new StreamResult(result_output_stream); 80 transformer.transform(xml_source, result); 81 result_output_stream.close(); 82 83 // expected success 84 } catch (Exception e) { 85 // unexpected failure 86 e.printStackTrace(); 87 Assert.fail(e.toString()); 88 } 89 } 90 }