1 /* 2 * Copyright (c) 2003, 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 javax.xml.transform.ptests; 25 26 import java.io.BufferedWriter; 27 import java.io.FileWriter; 28 import java.io.IOException; 29 import javax.xml.transform.TransformerFactory; 30 import javax.xml.transform.dom.DOMResult; 31 import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; 32 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 33 import javax.xml.transform.sax.SAXSource; 34 import javax.xml.transform.sax.SAXTransformerFactory; 35 import javax.xml.transform.sax.TransformerHandler; 36 import jaxp.library.JAXPFileBaseTest; 37 import static jaxp.library.JAXPTestUtilities.USER_DIR; 38 import static jaxp.library.JAXPTestUtilities.compareWithGold; 39 import static org.testng.Assert.assertTrue; 40 import org.testng.annotations.Test; 41 import org.w3c.dom.Attr; 42 import org.w3c.dom.NamedNodeMap; 43 import org.w3c.dom.Node; 44 import org.w3c.dom.NodeList; 45 import org.xml.sax.InputSource; 46 import org.xml.sax.XMLReader; 47 import org.xml.sax.helpers.XMLReaderFactory; 48 49 /** 50 * DOM parse on test file to be compared with golden output file. No Exception 51 * is expected. 52 */ 53 public class DOMResultTest extends JAXPFileBaseTest { 54 /** 55 * Unit test for simple DOM parsing. 56 * @throws Exception If any errors occur. 57 */ 58 @Test 59 public void testcase01() throws Exception { 60 String resultFile = USER_DIR + "domresult01.out"; 61 String goldFile = GOLDEN_DIR + "domresult01GF.out"; 62 String xsltFile = XML_DIR + "cities.xsl"; 63 String xmlFile = XML_DIR + "cities.xml"; 64 65 XMLReader reader = XMLReaderFactory.createXMLReader(); 66 SAXTransformerFactory saxTFactory 67 = (SAXTransformerFactory) TransformerFactory.newInstance(); 68 SAXSource saxSource = new SAXSource(new InputSource(xsltFile)); 69 TransformerHandler handler 70 = saxTFactory.newTransformerHandler(saxSource); 71 72 DOMResult result = new DOMResult(); 73 | 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 24 package javax.xml.transform.ptests; 25 26 import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; 27 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 28 import static jaxp.library.JAXPTestUtilities.USER_DIR; 29 import static jaxp.library.JAXPTestUtilities.compareWithGold; 30 import static org.testng.Assert.assertTrue; 31 32 import java.io.BufferedWriter; 33 import java.io.FileWriter; 34 import java.io.IOException; 35 36 import javax.xml.transform.TransformerFactory; 37 import javax.xml.transform.dom.DOMResult; 38 import javax.xml.transform.sax.SAXSource; 39 import javax.xml.transform.sax.SAXTransformerFactory; 40 import javax.xml.transform.sax.TransformerHandler; 41 42 import org.testng.annotations.Listeners; 43 import org.testng.annotations.Test; 44 import org.w3c.dom.Attr; 45 import org.w3c.dom.NamedNodeMap; 46 import org.w3c.dom.Node; 47 import org.w3c.dom.NodeList; 48 import org.xml.sax.InputSource; 49 import org.xml.sax.XMLReader; 50 import org.xml.sax.helpers.XMLReaderFactory; 51 52 /** 53 * DOM parse on test file to be compared with golden output file. No Exception 54 * is expected. 55 */ 56 @Listeners({jaxp.library.FilePolicy.class}) 57 public class DOMResultTest { 58 /** 59 * Unit test for simple DOM parsing. 60 * @throws Exception If any errors occur. 61 */ 62 @Test 63 public void testcase01() throws Exception { 64 String resultFile = USER_DIR + "domresult01.out"; 65 String goldFile = GOLDEN_DIR + "domresult01GF.out"; 66 String xsltFile = XML_DIR + "cities.xsl"; 67 String xmlFile = XML_DIR + "cities.xml"; 68 69 XMLReader reader = XMLReaderFactory.createXMLReader(); 70 SAXTransformerFactory saxTFactory 71 = (SAXTransformerFactory) TransformerFactory.newInstance(); 72 SAXSource saxSource = new SAXSource(new InputSource(xsltFile)); 73 TransformerHandler handler 74 = saxTFactory.newTransformerHandler(saxSource); 75 76 DOMResult result = new DOMResult(); 77 |