1 /* 2 * Copyright (c) 2014, 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 javax.xml.transform; 25 26 import java.io.File; 27 28 import javax.xml.parsers.DocumentBuilder; 29 import javax.xml.parsers.DocumentBuilderFactory; 30 import javax.xml.transform.dom.DOMSource; 31 import javax.xml.transform.stream.StreamResult; 32 33 import org.testng.Assert; 34 import org.testng.annotations.Test; 35 import org.w3c.dom.Document; 36 import org.w3c.dom.Element; 37 38 /* 39 * @bug 6551600 40 * @summary Test using UNC path as StreamResult. 41 */ 42 public class CR6551600Test { 43 44 @Test 45 public final void testUNCPath() { 46 String hostName = ""; 47 try { 48 hostName = java.net.InetAddress.getLocalHost().getHostName(); 49 } catch (java.net.UnknownHostException e) { 50 // falls through 51 } 52 53 String path = "\\\\" + hostName + "\\C$\\xslt_unc_test.xml"; 54 String os = System.getProperty("os.name"); 55 if (os.indexOf("Windows") < 0) { 56 path = "///tmp/test.xml"; 57 } 58 else { 59 policy.PolicyUtil.changePolicy(getClass().getResource("CR6551600.policy").getFile()); 60 } 61 62 try { 63 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 64 DocumentBuilder builder = factory.newDocumentBuilder(); 65 Document doc = builder.newDocument(); 66 Element root = doc.createElement("test"); 67 doc.appendChild(root); 68 // create an identity transform 69 Transformer t = TransformerFactory.newInstance().newTransformer(); 70 File f = new File(path); 71 StreamResult result = new StreamResult(f); 72 DOMSource source = new DOMSource(doc); 73 System.out.println("Writing to " + f); 74 t.transform(source, result); 75 } catch (Exception e) { 76 // unexpected failure 77 e.printStackTrace(); 78 Assert.fail(e.toString()); 79 } 80 81 File file = new File(path); 82 if (file.exists()) { 83 file.deleteOnExit(); 84 } 85 } 86 }