1/* 2 * Copyright (c) 2003, 2016, 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 24package test.gaptest; 25 26import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 27import static jaxp.library.JAXPTestUtilities.USER_DIR; 28import static jaxp.library.JAXPTestUtilities.compareDocumentWithGold; 29import static org.testng.Assert.assertTrue; 30import static test.gaptest.GapTestConst.GOLDEN_DIR; 31import static test.gaptest.GapTestConst.XML_DIR; 32 33import java.io.File; 34import java.io.IOException; 35import java.nio.file.Files; 36import java.nio.file.Paths; 37 38import javax.xml.parsers.ParserConfigurationException; 39import javax.xml.transform.Transformer; 40import javax.xml.transform.TransformerException; 41import javax.xml.transform.TransformerFactory; 42import javax.xml.transform.stream.StreamResult; 43import javax.xml.transform.stream.StreamSource; 44 45import org.testng.annotations.Listeners; 46import org.testng.annotations.Test; 47import org.xml.sax.SAXException; 48 49/* 50 * @test 51 * @bug 4693341 52 * @library /javax/xml/jaxp/libs 53 * @run testng/othervm -DrunSecMngr=true test.gaptest.Bug4693341 54 * @run testng/othervm test.gaptest.Bug4693341 55 * @summary test transforming to stream with external dtd 56 */ 57 58@Listeners({jaxp.library.FilePolicy.class}) 59public class Bug4693341 { 60 61 @Test 62 public void test() throws TransformerException, ParserConfigurationException, SAXException, IOException { 63 64 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 65 66 String out = USER_DIR + "Bug4693341.out"; 67 StreamResult result = new StreamResult(new File(out)); 68 69 String in = XML_DIR + "Bug4693341.xml"; 70 String golden = GOLDEN_DIR + "Bug4693341.xml"; 71 File file = new File(in); 72 StreamSource source = new StreamSource(file); 73 System.out.println(source.getSystemId()); 74 75 Files.copy(Paths.get(XML_DIR + "Bug4693341.dtd"), 76 Paths.get(USER_DIR + "Bug4693341.dtd"), REPLACE_EXISTING); 77 78 transformer.transform(source, result); 79 80 assertTrue(compareDocumentWithGold(golden, out)); 81 } 82 83} 84