--- /dev/null 2014-08-20 22:06:49.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/TEST.properties 2014-08-20 22:06:49.000000000 -0700 @@ -0,0 +1,9 @@ +# This file identifies root(s) of the test-ng hierarchy. + +TestNG.dirs = . + +lib.dirs = /javax/xml/jaxp/libs + +# Tests that must run in othervm mode +othervm.dirs= /javax/xml/jaxp/functional + --- /dev/null 2014-08-20 22:06:49.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/DOMResultTest01.java 2014-08-20 22:06:49.000000000 -0700 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.xml.transform.ptests; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import static javax.xml.transform.ptests.TransformerTestConst.CLASS_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * DOM parse on test file to be compared with golden output file. No Exception + * is expected. + */ +public class DOMResultTest01 { + /** + * Unit test for simple DOM parsing. + */ + @Test + public void testcase01() { + String resultFile = CLASS_DIR + "domresult01.out"; + String goldFile = GOLDEN_DIR + "domresult01GF.out"; + String xsltFile = XML_DIR + "cities.xsl"; + String xmlFile = XML_DIR + "cities.xml"; + + try { + XMLReader reader = XMLReaderFactory.createXMLReader(); + SAXTransformerFactory saxTFactory + = (SAXTransformerFactory) TransformerFactory.newInstance(); + SAXSource saxSource = new SAXSource(new InputSource(xsltFile)); + TransformerHandler handler + = saxTFactory.newTransformerHandler(saxSource); + + DOMResult result = new DOMResult(); + + handler.setResult(result); + reader.setContentHandler(handler); + reader.parse(xmlFile); + + Node node = result.getNode(); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile))) { + writeNodes(node, writer); + } + assertTrue(compareWithGold(goldFile, resultFile)); + } catch (SAXException | TransformerConfigurationException + | IllegalArgumentException | IOException ex) { + failUnexpected(ex); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if(Files.exists(resultPath)) + Files.delete(resultPath); + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Prints all node names, attributes to file + * @param node a node that need to be recursively access. + * @param bWriter file writer. + * @throws IOException if writing file failed. + */ + private void writeNodes(Node node, BufferedWriter bWriter) throws IOException { + String str = "Node: " + node.getNodeName(); + bWriter.write( str, 0,str.length()); + bWriter.newLine(); + + NamedNodeMap nnm = node.getAttributes(); + if (nnm != null && nnm.getLength() > 0) + for (int i=0; i { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(xslFile)); + DOMSource domSource = new DOMSource(document); + StreamSource streamSource = new StreamSource(new FileInputStream(xmlFile)); + + File streamResultFile = new File(CLASS_DIR + file); + StreamResult streamResult = new StreamResult(streamResultFile); + + Transformer transformer = TransformerFactory.newInstance().newTransformer(domSource); + transformer.setOutputProperties(transformProperties); + transformer.transform(streamSource, streamResult); + } catch (SAXException | IOException | ParserConfigurationException + | TransformerException ex) { + failUnexpected(ex); + } + }); + } +} --- /dev/null 2014-08-20 22:06:58.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TfClearParamTest.java 2014-08-20 22:06:58.000000000 -0700 @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamSource; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Class containing the test cases for SAXParserFactory API + */ +public class TfClearParamTest { + /** + * Test xslt file. + */ + private final String XSL_FILE = XML_DIR + "cities.xsl"; + + /** + * Long parameter name embedded with a URI. + */ + private final String LONG_PARAM_NAME = "{http://xyz.foo.com/yada/baz.html}foo"; + + /** + * Short parameter name. + */ + private final String SHORT_PARAM_NAME = "foo"; + + /** + * Parameter value. + */ + private final String PARAM_VALUE = "xyz"; + + /** + * Obtains transformer's parameter with the same name that set before. Value + * should be same as set one. + */ + @Test + public void clear01() { + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + assertEquals(transformer.getParameter(LONG_PARAM_NAME).toString(), PARAM_VALUE); + } catch (TransformerConfigurationException ex) { + failUnexpected(ex); + } + + } + + /** + * Obtains transformer's parameter with the a name that wasn't set before. + * Null is expected. + */ + @Test + public void clear02() { + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + transformer.clearParameters(); + assertNull(transformer.getParameter(LONG_PARAM_NAME)); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter whose initiated with a stream source with + * the a name that set before. Value should be same as set one. + */ + @Test + public void clear03() { + try { + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(new StreamSource(new File(XSL_FILE))); + + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter whose initiated with a stream source with + * the a name that wasn't set before. Null is expected. + */ + @Test + public void clear04() { + try { + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(new StreamSource(new File(XSL_FILE))); + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + transformer.clearParameters(); + assertNull(transformer.getParameter(LONG_PARAM_NAME)); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + + } + + /** + * Obtains transformer's parameter whose initiated with a sax source with + * the a name that set before. Value should be same as set one. + */ + @Test + public void clear05() { + try { + InputSource is = new InputSource(new FileInputStream(XSL_FILE)); + SAXSource saxSource = new SAXSource(); + saxSource.setInputSource(is); + + Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource); + + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter whose initiated with a sax source with + * the a name that wasn't set before. Null is expected. + */ + @Test + public void clear06() { + try { + InputSource is = new InputSource(new FileInputStream(XSL_FILE)); + SAXSource saxSource = new SAXSource(); + saxSource.setInputSource(is); + + Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource); + + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + transformer.clearParameters(); + assertNull(transformer.getParameter(LONG_PARAM_NAME)); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter whose initiated with a dom source with + * the a name that set before. Value should be same as set one. + */ + @Test + public void clear07() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(XSL_FILE)); + DOMSource domSource = new DOMSource((Node)document); + + Transformer transformer = tfactory.newTransformer(domSource); + + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE); + } catch (IOException | ParserConfigurationException + | TransformerConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter whose initiated with a dom source with + * the a name that wasn't set before. Null is expected. + */ + @Test + public void clear08() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(XSL_FILE)); + DOMSource domSource = new DOMSource((Node)document); + + Transformer transformer = tfactory.newTransformer(domSource); + transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); + transformer.clearParameters(); + assertNull(transformer.getParameter(LONG_PARAM_NAME)); + } catch (IOException | ParserConfigurationException + | TransformerConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter with a short name that set before. Value + * should be same as set one. + */ + @Test + public void clear09() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + Transformer transformer = tfactory.newTransformer(); + + transformer.setParameter(SHORT_PARAM_NAME, PARAM_VALUE); + assertEquals(transformer.getParameter(SHORT_PARAM_NAME).toString(), PARAM_VALUE); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * Obtains transformer's parameter with a short name that set with an integer + * object before. Value should be same as the set integer object. + */ + @Test + public void clear10() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + Transformer transformer = tfactory.newTransformer(); + + int intObject = 5; + transformer.setParameter(SHORT_PARAM_NAME, intObject); + assertEquals(transformer.getParameter(SHORT_PARAM_NAME), intObject); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:06:59.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerExcpTest.java 2014-08-20 22:06:59.000000000 -0700 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.stream.StreamSource; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; +import org.testng.annotations.Test; + +/** + * Basic test for TransformerException specification. + */ +public class TransformerExcpTest { + /** + * Transform an unformatted xslt file. TransformerException is thrown. + */ + @Test + public void tfexception() { + try { + // invalid.xsl has well-formedness error. Therefore transform throws + // TransformerException + StreamSource streamSource + = new StreamSource(new File(XML_DIR + "invalid.xsl")); + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer transformer = tFactory.newTransformer(streamSource); + transformer.transform( + new StreamSource(new File(XML_DIR + "cities.xml")), + new SAXResult()); + fail("TransformerException is not thrown as expected"); + } catch (TransformerException e) { + assertNotNull(e.getCause()); + assertNotNull(e.getException()); + assertNull(e.getLocationAsString()); + assertEquals(e.getMessageAndLocation(),e.getMessage()); + } + } + + + /** + * Spec says, "if the throwable was created with + * TransformerException(Throwable), initCause should throw + * IllegalStateException + */ + @Test(expectedExceptions = IllegalStateException.class) + public void tfexception06() { + TransformerException te = new TransformerException(new Throwable()); + te.initCause(null); + } + + /** + * Spec says, "if the throwable was created with TransformerException(String, + * Throwable), initCause should throw IllegalStateException + */ + @Test(expectedExceptions = IllegalStateException.class) + public void tfexception07() { + TransformerException te = new TransformerException("MyMessage", new Throwable()); + te.initCause(null); + } + + /** + * Tests if initCause(null) is allowed in other case. + */ + @Test + public void tfexception08() { + TransformerException te = new TransformerException("My Message"); + assertNotNull(te.initCause(null)); + } +} --- /dev/null 2014-08-20 22:06:59.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java 2014-08-20 22:06:59.000000000 -0700 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.*; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.*; +import javax.xml.transform.*; +import javax.xml.transform.dom.*; +import static javax.xml.transform.ptests.TransformerTestConst.CLASS_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.stream.*; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.w3c.dom.*; +import org.xml.sax.SAXException; + +/** + * Class containing the test cases for TransformerFactory API's + * getAssociatedStyleSheet method. + */ +public class TransformerFactoryTest { + /** + * This test case checks for the getAssociatedStylesheet method + * of TransformerFactory. + * The style sheet returned is then copied to an tfactory01.out + * It will then be verified to see if it matches the golden files + */ + @Test + public void tfactory01() { + String outputFile = CLASS_DIR + "tfactory01.out"; + String goldFile = GOLDEN_DIR + "tfactory01GF.out"; + String xmlFile = XML_DIR + "TransformerFactoryTest.xml"; + String xmlURI = "file:///" + XML_DIR; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new FileInputStream(xmlFile), xmlURI); + DOMSource domSource = new DOMSource(doc); + domSource.setSystemId(xmlURI); + StreamResult streamResult =new StreamResult( + new FileOutputStream(outputFile)); + TransformerFactory tFactory = TransformerFactory.newInstance(); + + Source s = tFactory.getAssociatedStylesheet(domSource,"screen", + "Modern",null); + Transformer t = tFactory.newTransformer(); + t.transform(s,streamResult); + assertTrue(compareWithGold(goldFile, outputFile)); + }catch (IOException | ParserConfigurationException + | TransformerException | SAXException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:00.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest.java 2014-08-20 22:07:00.000000000 -0700 @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.ErrorListener; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamSource; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Basic test cases for Transformer API + */ +public class TransformerTest { + /** + * XSLT file serves every test method. + */ + private final static String TEST_XSL = XML_DIR + "cities.xsl"; + + /** + * This tests if newTransformer(StreamSource) method returns Transformer + */ + @Test + public void transformer01() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + StreamSource streamSource = new StreamSource( + new File(TEST_XSL)); + Transformer transformer = tfactory.newTransformer(streamSource); + assertNotNull(transformer); + } catch (TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * This tests if newTransformer(SAXSource) method returns Transformer + */ + @Test + public void transformer02() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + InputSource is = new InputSource( + new FileInputStream(TEST_XSL)); + SAXSource saxSource = new SAXSource(is); + Transformer transformer = tfactory.newTransformer(saxSource); + assertNotNull(transformer); + } catch (TransformerConfigurationException | FileNotFoundException ex){ + failUnexpected(ex); + } + } + + /** + * This tests if newTransformer(DOMSource) method returns Transformer + */ + @Test + public void transformer03() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = tfactory.newTransformer(domSource); + assertNotNull(transformer); + } catch (TransformerConfigurationException | IOException + | ParserConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } + + /** + * This tests set/get ErrorListener methods of Transformer + */ + @Test + public void transformer04() { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(domSource); + transformer.setErrorListener(new MyErrorListener()); + assertNotNull(transformer.getErrorListener()); + assertTrue(transformer.getErrorListener() instanceof MyErrorListener); + } catch (IOException | IllegalArgumentException | ParserConfigurationException + | TransformerConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } + + /** + * This tests getOutputProperties() method of Transformer + */ + @Test + public void transformer05() { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(domSource); + Properties prop = transformer.getOutputProperties(); + + assertEquals(prop.getProperty("indent"), "yes"); + assertEquals(prop.getProperty("method"), "xml"); + assertEquals(prop.getProperty("encoding"), "UTF-8"); + assertEquals(prop.getProperty("standalone"), "no"); + assertEquals(prop.getProperty("version"), "1.0"); + assertEquals(prop.getProperty("omit-xml-declaration"), "no"); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * This tests getOutputProperty() method of Transformer + */ + @Test + public void transformer06() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = tfactory.newTransformer(domSource); + assertEquals(transformer.getOutputProperty("method"), "xml"); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerConfigurationException | IllegalArgumentException ex){ + failUnexpected(ex); + } + } +} + +/** + * Simple ErrorListener print out all exception. + */ +class MyErrorListener implements ErrorListener { + /** + * Prints exception when notification of a recoverable error. + * @param e exception of a recoverable error. + */ + @Override + public void error (TransformerException e) { + System.out.println(" In error" + e); + } + + /** + * Prints exception when notification of a warning. + * @param e exception of a warning. + */ + @Override + public void warning (TransformerException e) { + System.out.println(" In warning"); + } + + /** + * Prints exception when notification of a fatal error. + * @param e exception of a fatal error. + */ + @Override + public void fatalError (TransformerException e) throws + TransformerException { + System.out.println(" In fatal"); + } +} --- /dev/null 2014-08-20 22:07:00.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest02.java 2014-08-20 22:07:00.000000000 -0700 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import static javax.xml.transform.ptests.TransformerTestConst.CLASS_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + + +/** + * Here a transformer is created using DOMSource. Some specific output property + * is set on transformer. Then transform(StreamSource, StreamResult) is tested. + */ +public class TransformerTest02 { + /** + * Unit test for transform(StreamSource, StreamResult). + */ + @Test + public void testcase01() { + String outputFile = CLASS_DIR + "transformer02.out"; + String goldFile = GOLDEN_DIR + "transformer02GF.out"; + String xsltFile = XML_DIR + "cities.xsl"; + String xmlFile = XML_DIR + "cities.xml"; + + try (FileInputStream fis = new FileInputStream(xmlFile); + FileOutputStream fos = new FileOutputStream(outputFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(xsltFile)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(domSource); + StreamSource streamSource = new StreamSource(fis); + StreamResult streamResult = new StreamResult(fos); + + transformer.setOutputProperty("indent", "no"); + transformer.transform( streamSource, streamResult); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException | IllegalArgumentException + | ParserConfigurationException | TransformerException + | SAXException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:01.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest03.java 2014-08-20 22:07:01.000000000 -0700 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import static javax.xml.transform.ptests.TransformerTestConst.CLASS_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/** + * Here Properties Object is populated with required properties.A transformer + * is created using DOMSource. Using setOutputProperties(), Properties are set + * for transformer. Then transform(StreamSource, StreamResult) is used for + * transformation. This tests the setOutputProperties() method. + */ +public class TransformerTest03 { + /** + * Test for Transformer.setOutputProperties method. + */ + @Test + public void testcase01() { + String outputFile = CLASS_DIR + "transformer03.out"; + String goldFile = GOLDEN_DIR + "transformer03GF.out"; + String xsltFile = XML_DIR + "cities.xsl"; + String xmlFile = XML_DIR + "cities.xml"; + + try (FileInputStream fis = new FileInputStream(xmlFile); + FileOutputStream fos = new FileOutputStream(outputFile)) { + Properties properties = new Properties(); + properties.put("method", "xml"); + properties.put("encoding", "UTF-8"); + properties.put("omit-xml-declaration", "yes"); + properties.put("{http://xml.apache.org/xslt}indent-amount", "0"); + properties.put("indent", "no"); + properties.put("standalone", "no"); + properties.put("version", "1.0"); + properties.put("media-type", "text/xml"); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(xsltFile)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(domSource); + StreamSource streamSource = new StreamSource(fis); + StreamResult streamResult = new StreamResult(fos); + + transformer.setOutputProperties(properties); + transformer.transform( streamSource, streamResult); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException + | IOException | TransformerException ex){ + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:01.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/URIResolverTest.java 2014-08-20 22:07:01.000000000 -0700 @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import static jaxp.library.JAXPTestUtilities.FILE_SEP; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * URIResolver should be invoked when transform happens. + */ +public class URIResolverTest implements URIResolver { + /** + * System ID constant. + */ + private final static String SYSTEM_ID = "file:///" + XML_DIR; + + /** + * XML file include link file. + */ + private final static String XSL_INCLUDE_FILE = XML_DIR + "citiesinclude.xsl"; + + /** + * XML file import link file. + */ + private final static String XSL_IMPORT_FILE = XML_DIR + "citiesimport.xsl"; + + /** + * TEMP XML file. + */ + private final static String XSL_TEMP_FILE = "temp/cities.xsl"; + + + /** + * expected Href. + */ + private final String validateHref; + + /** + * expected Base URI. + */ + private final String validateBase; + + /** + * Constructor for setting expected Href and expected Base URI. + * @param validateHref expected Href + * @param validateBase expected Base URI + */ + public URIResolverTest(String validateHref, String validateBase){ + this.validateHref = validateHref; + this.validateBase = validateBase; + } + + /** + * Called by the processor when it encounters an xsl:include, xsl:import, + * or document() function. + * @param href An href attribute, which may be relative or absolute. + * @param base The base URI against which the first argument will be made + * absolute if the absolute URI is required. + * @return null always. + */ + @Override + public Source resolve(String href, String base) { + assertEquals(href, validateHref); + assertEquals(base, validateBase); + return null; + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using StreamSource. xsl file has xsl:include in it + */ + @Test + public static void resolver01() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + tfactory.setURIResolver(resolver); + + StreamSource streamSource = new StreamSource(new FileInputStream(XSL_INCLUDE_FILE)); + streamSource.setSystemId(SYSTEM_ID); + + Transformer transformer = tfactory.newTransformer(streamSource); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using DOMSource. xsl file has xsl:include in it + */ + @Test + public static void resolver02() { + try { + TransformerFactory tfactory = TransformerFactory.newInstance(); + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + tfactory.setURIResolver(resolver); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(XSL_INCLUDE_FILE); + DOMSource domSource = new DOMSource(document, SYSTEM_ID); + + Transformer transformer = tfactory.newTransformer(domSource); + } catch (IOException | ParserConfigurationException + | TransformerConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using SAXSource. xsl file has xsl:include in it + */ + @Test + public static void resolver03() { + try { + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + TransformerFactory tfactory = TransformerFactory.newInstance(); + tfactory.setURIResolver(resolver); + InputSource is = new InputSource(new FileInputStream(XSL_INCLUDE_FILE)); + is.setSystemId(SYSTEM_ID); + SAXSource saxSource = new SAXSource(is); + + Transformer transformer = tfactory.newTransformer(saxSource); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using StreamSource. xsl file has xsl:import in it + */ + @Test + public static void resolver04() { + try { + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + TransformerFactory tfactory = TransformerFactory.newInstance(); + tfactory.setURIResolver(resolver); + + StreamSource streamSource = new StreamSource(new FileInputStream(XSL_IMPORT_FILE)); + streamSource.setSystemId(SYSTEM_ID); + + Transformer transformer = tfactory.newTransformer(streamSource); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using DOMSource. xsl file has xsl:import in it + */ + @Test + public static void resolver05() { + try { + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + TransformerFactory tfactory = TransformerFactory.newInstance(); + tfactory.setURIResolver(resolver); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(XSL_IMPORT_FILE)); + DOMSource domSource = new DOMSource(document, SYSTEM_ID); + + Transformer transformer = tfactory.newTransformer(domSource); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerConfigurationException ex){ + failUnexpected(ex); + } + + } + + /** + * This is to test the URIResolver.resolve() method when a transformer is + * created using SAXSource. xsl file has xsl:import in it + */ + @Test + public static void resolver06() { + try { + URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); + TransformerFactory tfactory = TransformerFactory.newInstance(); + tfactory.setURIResolver(resolver); + + InputSource is = new InputSource(new FileInputStream(XSL_IMPORT_FILE)); + is.setSystemId(SYSTEM_ID); + SAXSource saxSource = new SAXSource(is); + + Transformer transformer = tfactory.newTransformer(saxSource); + } catch (FileNotFoundException | TransformerConfigurationException ex){ + failUnexpected(ex); + } + + } + + /** + * This is to test the URIResolver.resolve() method when there is an error + * in the file. + */ + @Test + public static void docResolver01() { + try { + URIResolverTest resolver = new URIResolverTest("temp/colors.xml", SYSTEM_ID); + TransformerFactory tfactory = TransformerFactory.newInstance(); + + StreamSource streamSource = new StreamSource( + new FileInputStream(XML_DIR + FILE_SEP + "doctest.xsl")); + streamSource.setSystemId(SYSTEM_ID); + System.err.println(streamSource.getSystemId()); + + Transformer transformer = tfactory.newTransformer(streamSource); + transformer.setURIResolver(resolver); + + File f = new File(XML_DIR + FILE_SEP + "myFake.xml"); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(f); + + // Use a Transformer for output + DOMSource source = new DOMSource(document); + System.err.println("Ignore the following output -- just dumping it here"); + StreamResult result = new StreamResult(System.err); + transformer.transform(source, result); + } catch (IOException | ParserConfigurationException | SAXException + | TransformerException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:02.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/othervm/TFCErrorTest.java 2014-08-20 22:07:02.000000000 -0700 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests.othervm; + +import javax.xml.transform.*; +import org.testng.annotations.Test; + +/** + * Negative test for set invalid TransformerFactory property. + */ +public class TFCErrorTest{ + @Test(expectedExceptions = ClassNotFoundException.class) + public void tfce01() throws Exception { + try{ + System.setProperty("javax.xml.transform.TransformerFactory","xx"); + TransformerFactory tFactory = TransformerFactory.newInstance(); + } catch (TransformerFactoryConfigurationError error) { + throw error.getException(); + } + } +} --- /dev/null 2014-08-20 22:07:03.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/TransformerFactoryTest.xml 2014-08-20 22:07:02.000000000 -0700 @@ -0,0 +1,13 @@ + + + + + Richard Schelunberg reviews the Pasedena Shakesperares Compnay Henry IV + + + + + + + + --- /dev/null 2014-08-20 22:07:03.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/TransformerFactoryTest.xsl 2014-08-20 22:07:03.000000000 -0700 @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + +
+
  • + + + +
  • +
    + +
    +
    +
    --- /dev/null 2014-08-20 22:07:04.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/cities.xml 2014-08-20 22:07:04.000000000 -0700 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + --- /dev/null 2014-08-20 22:07:04.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/cities.xsl 2014-08-20 22:07:04.000000000 -0700 @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + --- /dev/null 2014-08-20 22:07:05.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/citiesimport.xsl 2014-08-20 22:07:05.000000000 -0700 @@ -0,0 +1,5 @@ + + + + + --- /dev/null 2014-08-20 22:07:05.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/citiesinclude.xsl 2014-08-20 22:07:05.000000000 -0700 @@ -0,0 +1,5 @@ + + + + + --- /dev/null 2014-08-20 22:07:06.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/doctest.xsl 2014-08-20 22:07:06.000000000 -0700 @@ -0,0 +1,16 @@ + + + + + + + + +

    Nodes in color

    + + + +
    + +
    + --- /dev/null 2014-08-20 22:07:06.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/invalid.xsl 2014-08-20 22:07:06.000000000 -0700 @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + --- /dev/null 2014-08-20 22:07:07.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/lexical.xml 2014-08-20 22:07:07.000000000 -0700 @@ -0,0 +1,24 @@ + + + + Publishers of the Music of New York Women Composers + The Publishers <![CDATA[<?xml>]]> + + + ACA + info@composers.com + http://www.composers.com/ +
    + 170 West 74th St. + NY + NY + 10023 +
    + 212-362-8900 + 212-874-8605 + + &familytree; +
    +
    + --- /dev/null 2014-08-20 22:07:08.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/myFake.xml 2014-08-20 22:07:07.000000000 -0700 @@ -0,0 +1,4 @@ + + + + --- /dev/null 2014-08-20 22:07:08.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/doctypeGF.out 2014-08-20 22:07:08.000000000 -0700 @@ -0,0 +1,21 @@ + + + + Publishers of the Music of New York Women Composers + The Publishers + + ACA + info@composers.com + http://www.composers.com/ +
    + 170 West 74th St. + NY + NY + 10023 +
    + 212-362-8900 + 212-874-8605 + + +
    +
    --- /dev/null 2014-08-20 22:07:09.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/domresult01GF.out 2014-08-20 22:07:09.000000000 -0700 @@ -0,0 +1,26 @@ +Node: #document +Node: countries +Node: country +AttributeName:name, AttributeValue:France +Node: city +Node: #text +Node: city +Node: #text +Node: city +Node: #text +Node: country +AttributeName:name, AttributeValue:Italia +Node: city +Node: #text +Node: city +Node: #text +Node: city +Node: #text +Node: city +Node: #text +Node: country +AttributeName:name, AttributeValue:Espana +Node: city +Node: #text +Node: city +Node: #text --- /dev/null 2014-08-20 22:07:09.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/lexicalGF.out 2014-08-20 22:07:09.000000000 -0700 @@ -0,0 +1,4 @@ +In startCDATA +In endCDATA +In Comment:This is a comment +In Comment:This comment is for LexicalHandler --- /dev/null 2014-08-20 22:07:10.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf001GF.out 2014-08-20 22:07:10.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:10.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf002GF.out 2014-08-20 22:07:10.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:11.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf003GF.out 2014-08-20 22:07:11.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:12.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf005GF.out 2014-08-20 22:07:11.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:12.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf006GF.out 2014-08-20 22:07:12.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:13.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf008GF.out 2014-08-20 22:07:13.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:13.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf009GF.out 2014-08-20 22:07:13.000000000 -0700 @@ -0,0 +1,17 @@ + + +Paris +Nice +Lyon + + +Roma +Milano +Firenze +Napoli + + +Madrid +Barcelona + + --- /dev/null 2014-08-20 22:07:14.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf010GF.out 2014-08-20 22:07:14.000000000 -0700 @@ -0,0 +1,37 @@ +startDocument +startElement: , , countries +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +endElement: , , countries +endDocument --- /dev/null 2014-08-20 22:07:15.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf011GF.out 2014-08-20 22:07:15.000000000 -0700 @@ -0,0 +1,37 @@ +startDocument +startElement: , , countries +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +endElement: , , countries +endDocument --- /dev/null 2014-08-20 22:07:15.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf012GF.out 2014-08-20 22:07:15.000000000 -0700 @@ -0,0 +1,37 @@ +startDocument +startElement: , , countries +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +endElement: , , countries +endDocument --- /dev/null 2014-08-20 22:07:16.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/saxtf013GF.out 2014-08-20 22:07:16.000000000 -0700 @@ -0,0 +1,37 @@ +startDocument +startElement: , , countries +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +startElement: , , country, name +startElement: , , city +characters +endElement: , , city +startElement: , , city +characters +endElement: , , city +endElement: , , country +endElement: , , countries +endDocument --- /dev/null 2014-08-20 22:07:17.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/tfactory01GF.out 2014-08-20 22:07:16.000000000 -0700 @@ -0,0 +1,24 @@ + + + + + + + + + + + + + +
    +
  • + + + +
  • +
    + +
    +
    +
    \ No newline at end of file --- /dev/null 2014-08-20 22:07:17.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/tfactory02GF.out 2014-08-20 22:07:17.000000000 -0700 @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + +
    +
  • + + + +
  • +
    + +
    +
    +
    \ No newline at end of file --- /dev/null 2014-08-20 22:07:18.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/transformer02GF.out 2014-08-20 22:07:18.000000000 -0700 @@ -0,0 +1 @@ +ParisNiceLyonRomaMilanoFirenzeNapoliMadridBarcelona \ No newline at end of file --- /dev/null 2014-08-20 22:07:18.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/out/transformer03GF.out 2014-08-20 22:07:18.000000000 -0700 @@ -0,0 +1 @@ +ParisNiceLyonRomaMilanoFirenzeNapoliMadridBarcelona \ No newline at end of file --- /dev/null 2014-08-20 22:07:19.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/publish2.xml 2014-08-20 22:07:19.000000000 -0700 @@ -0,0 +1,23 @@ + + + + Publishers of the Music of New York Women Composers + The Publishers + + ACA + info@composers.com + http://www.composers.com/ +
    + 170 West 74th St. + NY + NY + 10023 +
    + 212-362-8900 + 212-874-8605 + + &familytree; +
    +
    + --- /dev/null 2014-08-20 22:07:20.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/temp/cities.xsl 2014-08-20 22:07:19.000000000 -0700 @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + --- /dev/null 2014-08-20 22:07:20.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/temp/colors.xml 2014-08-20 22:07:20.000000000 -0700 @@ -0,0 +1,10 @@ + + + + + 088ea6 + 0839a6 + + + + --- /dev/null 2014-08-20 22:07:21.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/AttrImplTest.java 2014-08-20 22:07:20.000000000 -0700 @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import org.testng.annotations.Test; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Class containing the test cases for AttributesImpl API. + */ +public class AttrImplTest { + private static final String CAR_URI = "http://www.cars.com/xml"; + + private static final String CAR_LOCALNAME = "part"; + + private static final String CAR_QNAME = "p"; + + private static final String CAR_TYPE = "abc"; + + private static final String CAR_VALUE = "Merc"; + + private static final String JEEP_URI = "http://www.jeeps.com/xml"; + + private static final String JEEP_LOCALNAME = "wheel"; + + private static final String JEEP_QNAME = "w"; + + private static final String JEEP_TYPE = "xyz"; + + private static final String JEEP_VALUE = "Mit"; + + /** + * Basic test for getIndex(String). + */ + @Test + public void testcase01() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + assertEquals(attr.getIndex(CAR_QNAME), 0); + assertEquals(attr.getIndex(JEEP_QNAME), 1); + } + + /** + * Basic test for getIndex(String, String). + */ + @Test + public void testcase02() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + assertEquals(attr.getIndex(JEEP_URI, JEEP_LOCALNAME), 1); + } + + /** + * getIndex(String, String) returns -1 if none matches. + */ + @Test + public void testcase03() { + AttributesImpl attr = new AttributesImpl(); + assertEquals(attr.getIndex(JEEP_URI, "whl"), -1); + } + + /** + * Basic test for getType(int) and getType(String). + */ + @Test + public void testcase04() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + assertEquals(attr.getType(1), JEEP_TYPE); + assertEquals(attr.getType(JEEP_QNAME), JEEP_TYPE); + } + + /** + * Basic test for getValue(int), getValue(String) and getValue(String, String). + */ + @Test + public void testcase05() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + assertEquals(attr.getValue(1), JEEP_VALUE); + assertEquals(attr.getValue(attr.getQName(1)), JEEP_VALUE); + assertEquals(attr.getValue(attr.getURI(1), attr.getLocalName(1)), JEEP_VALUE); + } + + /** + * Basic test for getLocalName(int), getQName(int), getType(int), + * getType(String) and getURI(int). + */ + @Test + public void testcase06() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + attr.setAttribute(1, "www.megginson.com", "author", "meg", "s", "SAX2"); + assertEquals(attr.getLocalName(1), "author"); + assertEquals(attr.getQName(1), "meg"); + assertEquals(attr.getType(1), "s"); + assertEquals(attr.getType("meg"), "s"); + assertEquals(attr.getURI(1), "www.megginson.com"); + } + + /** + * Basic test for setLocalName(int, String), setQName(int, String), + * setType(int, String), setValue(int, String) and setURI(int, String). + */ + @Test + public void testcase07() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + attr.setLocalName(1, "speclead"); + attr.setQName(1, "megi"); + attr.setType(1, "sax"); + attr.setValue(1, "SAX01"); + attr.setURI(1, "www.megginson.com/sax/sax01"); + + assertEquals(attr.getLocalName(1), "speclead"); + assertEquals(attr.getQName(1), "megi"); + assertEquals(attr.getType(1), "sax"); + assertEquals(attr.getType("megi"), "sax"); + assertEquals(attr.getURI(1), "www.megginson.com/sax/sax01"); + } + + /** + * Basic test for getLength(). + */ + @Test + public void testcase08() { + AttributesImpl attr = new AttributesImpl(); + assertEquals(attr.getLength(), 0); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + assertEquals(attr.getLength(), 2); + } + + /** + * Javadoc says getLocalName returns null if the index if out of range. + */ + @Test + public void testcase09() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + attr.removeAttribute(1); + assertNull(attr.getLocalName(1)); + } + + /** + * Javadoc says java.lang.ArrayIndexOutOfBoundsException is thrown When the + * supplied index does not point to an attribute in the list. + */ + @Test(expectedExceptions = ArrayIndexOutOfBoundsException.class) + public void testcase10() { + AttributesImpl attr = new AttributesImpl(); + attr.addAttribute(CAR_URI, CAR_LOCALNAME, CAR_QNAME, CAR_TYPE, CAR_VALUE); + attr.addAttribute(JEEP_URI, JEEP_LOCALNAME, JEEP_QNAME, JEEP_TYPE, + JEEP_VALUE); + attr.removeAttribute(1); + attr.removeAttribute(1); + } +} --- /dev/null 2014-08-20 22:07:21.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/AttributesNSTest.java 2014-08-20 22:07:21.000000000 -0700 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * This tests the Attributes interface. Here the startElement() callback of + * ContentHandler has Attributes as one of its arguments. Attributes + * pertaining to an element are taken into this argument and various methods + * of Attributes interfaces are tested. This program uses Namespace processing + * with namespaces in xml file. This program does not use Validation + */ +public class AttributesNSTest { + /** + * Test for Attribute Interface's setter/getter. + */ + @Test + public void testcase01() { + String outputFile = CLASS_DIR + "AttributesNS.out"; + String goldFile = GOLDEN_DIR + "AttributesNSGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + // http://www.saxproject.com/?selected=namespaces namespace-prefixes + //set to false to supress xmlns attributes + spf.setFeature("http://xml.org/sax/features/namespace-prefixes", + false); + SAXParser saxParser = spf.newSAXParser(); + MyAttrCHandler myAttrCHandler = new MyAttrCHandler(outputFile); + saxParser.parse(new File(xmlFile), myAttrCHandler); + myAttrCHandler.flushAndClose(); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException | ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:22.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/AttributesTest.java 2014-08-20 22:07:22.000000000 -0700 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * This tests the Attributes interface. Here the startElement() callback of + * ContentHandler has Attributes as one of its arguments. Attributes + * pertaining to an element are taken into this argument and various methods + * of Attributes interfaces are tested. + * This program uses Namespace processing without any namepsaces in xml file. + * This program uses Validation + */ +public class AttributesTest { + /** + * Unit test for Attributes interface. Prints all attributes into output + * file. Check it with golden file. + */ + @Test + public void testcase01() { + String outputFile = CLASS_DIR + "Attributes.out"; + String goldFile = GOLDEN_DIR + "AttributesGF.out"; + String xmlFile = XML_DIR + "family.xml"; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setFeature("http://xml.org/sax/features/namespace-prefixes", + true); + spf.setValidating(true); + SAXParser saxParser = spf.newSAXParser(); + MyAttrCHandler myAttrCHandler = new MyAttrCHandler(outputFile); + saxParser.parse(new File(xmlFile), myAttrCHandler); + myAttrCHandler.flushAndClose(); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException | ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:23.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/ContentHandlerTest.java 2014-08-20 22:07:22.000000000 -0700 @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Class registers a content event handler to XMLReader. Content event handler + * transverses XML and print all visited node when XMLreader parses XML. Test + * verifies output is same as the golden file. + */ +public class ContentHandlerTest { + /** + * Content event handler visit all nodes to print to output file. + */ + @Test + public void testcase01() { + String outputFile = CLASS_DIR + "Content.out"; + String goldFile = GOLDEN_DIR + "ContentGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + + try(FileInputStream instream = new FileInputStream(xmlFile)) { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + ContentHandler cHandler = new MyContentHandler(outputFile); + xmlReader.setContentHandler(cHandler); + InputSource is = new InputSource(instream); + xmlReader.parse(is); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch( IOException | SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} + +/** + * A content write out handler. + */ +class MyContentHandler extends XMLFilterImpl { + /** + * Prefix to every exception. + */ + private final static String WRITE_ERROR = "bWriter error"; + + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Default document locator. + */ + private Locator locator; + + /** + * Initiate FileWriter when construct a MyContentHandler. + * @param outputFileName output file name. + * @throws SAXException creation of FileWriter failed. + */ + public MyContentHandler(String outputFileName) throws SAXException { + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write characters tag along with content of characters when meet + * characters event. + * @throws IOException error happen when writing file. + */ + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + String s = new String(ch, start, length); + println("characters...\n" + s); + } + + /** + * Write endDocument tag then flush the content and close the file when meet + * endDocument event. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void endDocument() throws SAXException { + try { + println("endDocument..."); + bWriter.flush(); + bWriter.close(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } + + /** + * Write endElement tag with namespaceURI, localName, qName to the file when + * meet endElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void endElement(String namespaceURI,String localName,String qName) throws SAXException{ + println("endElement...\n" + "namespaceURI: " + namespaceURI + + " localName: "+ localName + " qName: " + qName); + } + + /** + * Write endPrefixMapping tag along with prefix to the file when meet + * endPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void endPrefixMapping(String prefix) throws SAXException { + println("endPrefixMapping...\n" + "prefix: " + prefix); + } + + /** + * Write ignorableWhitespace tag along with white spaces when meet + * ignorableWhitespace event. + * @throws IOException error happen when writing file. + */ + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + String s = new String(ch, start, length); + println("ignorableWhitespace...\n" + s + + " ignorable white space string length: " + s.length()); + } + + /** + * Write processingInstruction tag along with target name and target data + * when meet processingInstruction event. + * @throws IOException error happen when writing file. + */ + @Override + public void processingInstruction(String target, String data) throws SAXException { + println("processingInstruction...target:" + target + + " data: " + data); + } + + /** + * Write setDocumentLocator tag when meet setDocumentLocator event. + */ + @Override + public void setDocumentLocator(Locator locator) { + try { + this.locator = locator; + println("setDocumentLocator..."); + } catch (SAXException ex) { + System.err.println(WRITE_ERROR + ex); + } + } + + /** + * Write skippedEntity tag along with entity name when meet skippedEntity + * event. + * @throws IOException error happen when writing file. + */ + @Override + public void skippedEntity(String name) throws SAXException { + println("skippedEntity...\n" + "name: " + name); + } + + /** + * Write startDocument tag when meet startDocument event. + * @throws IOException error happen when writing file. + */ + @Override + public void startDocument() throws SAXException { + println("startDocument..."); + } + + /** + * Write startElement tag along with namespaceURI, localName, qName, number + * of attributes and line number when meet startElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void startElement(String namespaceURI, String localName, + String qName, Attributes atts) throws SAXException { + println("startElement...\n" + "namespaceURI: " + namespaceURI + + " localName: " + localName + " qName: " + qName + + " Number of Attributes: " + atts.getLength() + + " Line# " + locator.getLineNumber()); + } + + /** + * Write startPrefixMapping tag along with prefix and uri when meet + * startPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + println("startPrefixMapping...\n" + "prefix: " + prefix + + " uri: " + uri); + } + + /** + * Write outString to file. + * @param outString String to be written to File + * @throws SAXException if write file failed + */ + private void println(String outString) throws SAXException { + try { + bWriter.write( outString, 0, outString.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } +} --- /dev/null 2014-08-20 22:07:23.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/DefaultHandlerTest.java 2014-08-20 22:07:23.000000000 -0700 @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * XMLReader parse XML with default handler that transverses XML and + * print all visited node. Test verifies output is same as the golden file. + */ +public class DefaultHandlerTest { + /** + * Test default handler that transverses XML and print all visited node. + */ + @Test + public void testDefaultHandler() { + String outputFile = CLASS_DIR + "DefaultHandler.out"; + String goldFile = GOLDEN_DIR + "DefaultHandlerGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxparser = spf.newSAXParser(); + + MyDefaultHandler handler = new MyDefaultHandler(outputFile); + File file = new File(xmlFile); + String Absolutepath = file.getAbsolutePath(); + String newAbsolutePath = Absolutepath; + if (File.separatorChar == '\\') + newAbsolutePath = Absolutepath.replace('\\', '/'); + String uri = "file:///" + newAbsolutePath; + saxparser.parse(uri, handler); + } catch (IOException | ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + // Need close the output file before we compare it with golden file. + try { + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} + +class MyDefaultHandler extends DefaultHandler { + /** + * Prefix to every exception. + */ + private final static String WRITE_ERROR = "bWrite error"; + + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Initiate FileWriter when construct a MyContentHandler. + * @param outputFileName output file name. + * @throws SAXException creation of FileWriter failed. + */ + MyDefaultHandler(String outputFileName) throws SAXException { + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write characters tag along with content of characters when meet + * characters event. + * @throws IOException error happen when writing file. + */ + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + println("characters...\n" + new String(ch, start, length)); + } + + /** + * Write endDocument tag then flush the content and close the file when meet + * endDocument event. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void endDocument() throws SAXException { + try { + println("endDocument..."); + bWriter.flush(); + bWriter.close(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } + + /** + * Write endElement tag with namespaceURI, localName, qName to the file when + * meet endElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void endElement(String namespaceURI,String localName,String qName) throws SAXException{ + println("endElement...\n" + "namespaceURI: " + namespaceURI + + " localName: "+ localName + " qName: " + qName); + } + + /** + * Write endPrefixMapping tag along with prefix to the file when meet + * endPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void endPrefixMapping(String prefix) throws SAXException { + println("endPrefixmapping .." + prefix); + } + + /** + * Write error tag along with exception to the file when meet recoverable + * error event. + * @throws IOException error happen when writing file. + */ + @Override + public void error(SAXParseException e) throws SAXException { + println("error: " + e.getMessage()); + } + + /** + * Write fatalError tag along with exception to the file when meet + * unrecoverable error event. + * @throws IOException error happen when writing file. + */ + @Override + public void fatalError(SAXParseException e) throws SAXException { + println("fatal error: "); + } + + /** + * Write warning tag along with exception to the file when meet warning event. + * @throws IOException error happen when writing file. + */ + @Override + public void warning(SAXParseException e) throws SAXException { + println("warning : "); + } + + /** + * Write ignorableWhitespace tag along with white spaces when meet + * ignorableWhitespace event. + * @throws IOException error happen when writing file. + */ + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + String s = new String(ch, start, length); + println("ignorableWhitespace...\n" + s + + " ignorable white space string length: " + s.length()); + } + + /** + * Write processingInstruction tag along with target name and target data + * when meet processingInstruction event. + * @throws IOException error happen when writing file. + */ + @Override + public void processingInstruction(String target, String data) throws SAXException { + println("processingInstruction...target:" + target + + " data: " + data); + } + + @Override + public void setDocumentLocator(Locator locator) { + try { + println("setDocumentLocator..."); + } catch (SAXException ex) { + System.err.println(WRITE_ERROR + ex); + } + } + + /** + * Write skippedEntity tag along with entity name when meet skippedEntity + * event. + * @throws IOException error happen when writing file. + */ + @Override + public void skippedEntity(String name) throws SAXException { + println("skippedEntity...\n" + "name: " + name); + } + + /** + * Write startDocument tag when meet startDocument event. + * @throws IOException error happen when writing file. + */ + @Override + public void startDocument() throws SAXException { + println("startDocument..."); + } + + /** + * Write startElement tag along with namespaceURI, localName, qName, number + * of attributes and line number when meet startElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void startElement(String namespaceURI, String localName, + String qName, Attributes atts) throws SAXException { + println("startElement...\n" + "namespaceURI: " + namespaceURI + + " localName: " + localName + " qName: " + qName + + " Number of Attributes: " + atts.getLength()); + } + + /** + * Write startPrefixMapping tag along with prefix and uri when meet + * startPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + println("startPrefixMapping...\n" + "prefix: " + prefix + " uri: " + uri); + } + + /** + * Write outString to file. + * @param outString String to be written to File + * @throws SAXException if write file failed + */ + private void println(String outString) throws SAXException { + try { + bWriter.write( outString, 0, outString.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } +} --- /dev/null 2014-08-20 22:07:24.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/EHFatalTest.java 2014-08-20 22:07:24.000000000 -0700 @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * ErrorHandler unit test. Set a ErrorHandle to XMLReader. Capture fatal error + * events in ErrorHandler. + */ +public class EHFatalTest { + /** + * Error Handler to capture all error events to output file. Verifies the + * output file is same as golden file. + */ + @Test + public void testEHFatal() { + String outputFile = CLASS_DIR + "EHFatal.out"; + String goldFile = GOLDEN_DIR + "EHFatalGF.out"; + String xmlFile = XML_DIR + "invalid.xml"; + + try(MyErrorHandler eHandler = new MyErrorHandler(outputFile); + FileInputStream instream = new FileInputStream(xmlFile)) { + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setErrorHandler(eHandler); + InputSource is = new InputSource(instream); + xmlReader.parse(is); + } catch (IOException | ParserConfigurationException ex) { + failUnexpected(ex); + } catch (SAXException ex) { + System.out.println("This is expected:" + ex); + } + // Need close the output file before we compare it with golden file. + try { + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} + +/** + * A fatal error event handler only capture fatal error event and write event to + * output file. + */ +class MyErrorHandler extends XMLFilterImpl implements AutoCloseable { + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Initiate FileWriter when construct a MyContentHandler. + * @param outputFileName output file name. + * @throws SAXException creation of FileWriter failed. + */ + MyErrorHandler(String outputFileName) throws SAXException { + super(); + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write fatalError tag along with exception to the file when meet + * unrecoverable error event. + * @throws IOException error happen when writing file. + */ + @Override + public void fatalError(SAXParseException e) throws SAXException { + String str = "In fatalError..\nSAXParseException: " + e.getMessage(); + try { + bWriter.write( str, 0,str.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Flush the content and close the file. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void close() throws IOException { + bWriter.flush(); + bWriter.close(); + } +} --- /dev/null 2014-08-20 22:07:24.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/MyAttrCHandler.java 2014-08-20 22:07:24.000000000 -0700 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Simple attributes handler. + */ +public class MyAttrCHandler extends DefaultHandler { + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Initiate FileWriter + * @param fileName output file name. + * @throws IOException + */ + public MyAttrCHandler(String fileName) throws IOException { + bWriter = new BufferedWriter(new FileWriter(fileName)); + } + + /** + * Write element content before start access every element. + * @throws org.xml.sax.SAXException + */ + @Override + public void startElement(String uri, String localName, + String qName, Attributes attributes) throws SAXException { + try { + String string = "uri <" + uri + "> localName <" + localName + + "> qName <" + qName + ">"; + + bWriter.write( string, 0, string.length()); + bWriter.newLine(); + + int length = attributes.getLength(); + string = "length: " + length; + + bWriter.write( string, 0, string.length()); + bWriter.newLine(); + + for (int ind=0; ind < length ; ind++) { + string = "For index = " + ind + "\n"; + string += "getLocalName <" + attributes.getLocalName(ind) + +">" + "\n"; + string += "getQName <" + attributes.getQName(ind) +">" + "\n"; + string += "getType <" + attributes.getType(ind) +">" + "\n"; + string += "getURI <" + attributes.getURI(ind) +">" + "\n"; + string += "getValue <" + attributes.getValue(ind) +">" + "\n"; + + bWriter.write( string, 0, string.length()); + bWriter.newLine(); + + String gotLocalName = attributes.getLocalName(ind); + String gotQName = attributes.getQName(ind); + String gotURI = attributes.getURI(ind); + + string ="Using localName, qname and uri pertaining to index = " + + ind; + bWriter.write( string, 0, string.length()); + bWriter.newLine(); + + string = "getIndex(qName) <" + attributes.getIndex(gotQName) + +">" + "\n"; + string += "getIndex(uri, localName) <" + + attributes.getIndex(gotURI, gotLocalName) +">" + "\n"; + + string += "getType(qName) <" + + attributes.getType(gotQName) +">" + "\n"; + string += "getType(uri, localName) <" + + attributes.getType(gotURI, gotLocalName) +">" + "\n"; + + string += "getValue(qName) <" + + attributes.getValue(gotQName) +">" + "\n"; + string += "getValue(uri, localName) <" + + attributes.getValue(gotURI, gotLocalName) +">" + "\n"; + + bWriter.write( string, 0, string.length()); + bWriter.newLine(); + } + bWriter.newLine(); + } catch(IOException ex){ + throw new SAXException(ex); + } + } + + /** + * Flush the stream and close the file. + * @throws IOException when writing or closing file failed. + */ + public void flushAndClose() throws IOException { + bWriter.flush(); + bWriter.close(); + } +} --- /dev/null 2014-08-20 22:07:25.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/MyNSContentHandler.java 2014-08-20 22:07:25.000000000 -0700 @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.helpers.LocatorImpl; +import org.xml.sax.Locator; +import org.xml.sax.Attributes; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.FileWriter; +import org.xml.sax.SAXException; + +class MyNSContentHandler extends DefaultHandler { + /** + * Prefix for written string. + */ + private final static String WRITE_ERROR = "bWrite error"; + /** + * FileWriter to write output file. + */ + private final BufferedWriter bWriter; + + /** + * Default locator. + */ + Locator locator = new LocatorImpl(); + + /** + * Initiate FileWrite. + * @param outputFileName file name of output file. + * @throws SAXException when open output file failed. + */ + public MyNSContentHandler(String outputFileName) throws SAXException { + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write characters tag along with content of characters when meet + * characters event. + * @throws IOException error happen when writing file. + */ + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + String s = new String(ch, start, length); + println("characters...length is:" + s.length() + "\n" + + "<" + s + ">"); + } + + /** + * Write endDocument tag then flush the content and close the file when meet + * endDocument event. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void endDocument() throws SAXException { + try { + println("endDocument..."); + bWriter.flush(); + bWriter.close(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } + + /** + * Write endElement tag with namespaceURI, localName, qName to the file when + * meet endElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void endElement(String namespaceURI, String localName, String qName) + throws SAXException { + println("endElement...\n" + "namespaceURI: <" + namespaceURI + + "> localName: <" + localName + "> qName: <" + qName + ">"); + } + + /** + * Write endPrefixMapping tag along with prefix to the file when meet + * endPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void endPrefixMapping(String prefix) throws SAXException { + println("endPrefixMapping...\n" + "prefix: <" + prefix + ">"); + } + + /** + * Write ignorableWhitespace tag along with white spaces when meet + * ignorableWhitespace event. + * @throws IOException error happen when writing file. + */ + @Override + public void ignorableWhitespace(char[] ch, int start, int length) + throws SAXException { + String s = new String(ch, start, length); + println("ignorableWhitespace...\n" + s + + " ignorable white space string length: " + s.length()); + } + + /** + * Write processingInstruction tag along with target name and target data + * when meet processingInstruction event. + * @throws IOException error happen when writing file. + */ + @Override + public void processingInstruction(String target, String data) + throws SAXException { + println("processingInstruction...target:<" + target + + "> data: <" + data + ">"); + } + + /** + * Write setDocumentLocator tag when meet setDocumentLocator event. + */ + @Override + public void setDocumentLocator(Locator locator) { + try { + this.locator = locator; + println("setDocumentLocator..."); + } catch (SAXException ex) { + System.err.println(WRITE_ERROR + ex); + } + } + + /** + * Write skippedEntity tag along with entity name when meet skippedEntity + * event. + * @throws IOException error happen when writing file. + */ + @Override + public void skippedEntity(String name) throws SAXException { + println("skippedEntity...\n" + "name: <" + name + ">"); + } + + /** + * Write startDocument tag when meet startDocument event. + * @throws IOException error happen when writing file. + */ + @Override + public void startDocument() throws SAXException { + println("startDocument..."); + } + + /** + * Write startElement tag along with namespaceURI, localName, qName, number + * of attributes and line number when meet startElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void startElement(String namespaceURI, String localName, + String qName, Attributes atts) throws SAXException { + println("startElement...\n" + "namespaceURI: <" + namespaceURI + + "> localName: <" + localName + "> qName: <" + qName + + "> Number of Attributes: <" + atts.getLength() + + "> Line# <" + locator.getLineNumber() + ">"); + } + + /** + * Write startPrefixMapping tag along with prefix and uri when meet + * startPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + println("startPrefixMapping...\n" + "prefix: <" + prefix + + "> uri: <" + uri + ">"); + } + /** + * Write outString to output file. + * @param outString string to be written. + * @throws SAXException + */ + private void println(String outString) throws SAXException { + try { + bWriter.write( outString, 0, outString.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException(WRITE_ERROR, ex); + } + } +} --- /dev/null 2014-08-20 22:07:25.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/NSSupportTest.java 2014-08-20 22:07:25.000000000 -0700 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.util.Enumeration; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import org.testng.annotations.Test; +import org.xml.sax.helpers.NamespaceSupport; + +/** + * Unit test cases for NamespaceSupport API + */ +public class NSSupportTest { + /** + * Empty prefix name. + */ + private final static String EMPTY_PREFIX = ""; + + /** + * A URI for W3 1999 HTML sepc. + */ + private final static String W3_URI = "http://www.w3.org/1999/xhtml"; + + /** + * A prefix named "dc". + */ + private final static String DC_PREFIX = "dc"; + + /** + * A URI for "http://www.purl.org/dc#". + */ + private final static String PURL_URI = "http://www.purl.org/dc#"; + + /** + * Test for NamespaceSupport.getDeclaredPrefixes(). + */ + @Test + public void testcase01() { + String[] prefixes = new String[2]; + NamespaceSupport support = new NamespaceSupport(); + support.pushContext(); + support.declarePrefix(EMPTY_PREFIX, W3_URI); + support.declarePrefix(DC_PREFIX, PURL_URI); + + Enumeration e = support.getDeclaredPrefixes(); + int i = 0; + while(e.hasMoreElements()) { + prefixes[i++] = e.nextElement().toString(); + } + support.popContext(); + + assertEquals(prefixes, new String[]{EMPTY_PREFIX, DC_PREFIX}); + } + + /** + * Test for NamespaceSupport.getDeclaredPrefixes() and support.processName(). + */ + @Test + public void testcase02() { + String[] parts = new String[3]; + NamespaceSupport support = new NamespaceSupport(); + + support.pushContext(); + support.declarePrefix(DC_PREFIX, PURL_URI); + parts = support.processName("dc:title", parts, false); + support.popContext(); + assertEquals(parts, new String[]{PURL_URI, "title", "dc:title"}); + } + + /** + * Test for NamespaceSupport.getDeclaredPrefixes() and support.processName(). + */ + @Test + public void testcase03() { + String[] parts = new String[3]; + NamespaceSupport support = new NamespaceSupport(); + support.pushContext(); + support.declarePrefix(EMPTY_PREFIX, W3_URI); + parts = support.processName("a", parts, false); + support.popContext(); + assertEquals(parts, new String[]{W3_URI, "a", "a"}); + } + + + /** + * Test for NamespaceSupport.popContext(). + */ + @Test + public void testcase04() { + NamespaceSupport support = new NamespaceSupport(); + + support.pushContext(); + support.declarePrefix(EMPTY_PREFIX, W3_URI); + support.declarePrefix(DC_PREFIX, PURL_URI); + + assertEquals(support.getURI(EMPTY_PREFIX), W3_URI); + assertEquals(support.getURI(DC_PREFIX), PURL_URI); + support.popContext(); + assertNull(support.getURI(EMPTY_PREFIX)); + assertNull(support.getURI(DC_PREFIX)); + } +} --- /dev/null 2014-08-20 22:07:26.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/NSTableTest01.java 2014-08-20 22:07:26.000000000 -0700 @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; + +/** + * Class containing the test cases for Namespace Table defined at + * http://www.megginson.com/SAX/Java/namespaces.html + */ +public class NSTableTest01 { + private static final String NAMESPACES = + "http://xml.org/sax/features/namespaces"; + private static final String NAMESPACE_PREFIXES = + "http://xml.org/sax/features/namespace-prefixes"; + + /** + * Here namespace processing and namespace-prefixes are enabled. + * The testcase tests XMLReader for this. + */ + @Test + public void xrNSTable01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setFeature(NAMESPACE_PREFIXES, true); + + assertTrue(xmlReader.getFeature(NAMESPACES)); + assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * Here namespace processing is enabled. This will make namespace-prefixes + * disabled. The testcase tests XMLReader for this. + */ + @Test + public void xrNSTable02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + + XMLReader xmlReader = saxParser.getXMLReader(); + assertTrue(xmlReader.getFeature(NAMESPACES)); + assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + + } + + /** + * Here namespace processing is disabled. This will make namespace-prefixes + * enabled. The testcase tests XMLReader for this. + */ + @Test + public void xrNSTable03() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser saxParser = spf.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + assertFalse(xmlReader.getFeature(NAMESPACES)); + assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * Here namespace processing is disabled, and namespace-prefixes is + * disabled. This will make namespace processing on.The testcase tests + * XMLReader for this. This behavior only apply to crimson, not + * xerces + */ + @Test + public void xrNSTable04() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser saxParser = spf.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setFeature(NAMESPACE_PREFIXES, false); + + assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * Here namespace processing and namespace-prefixes are enabled. + * The testcase tests SAXParserFactory for this. + */ + @Test + public void spNSTable01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setFeature(NAMESPACE_PREFIXES,true); + assertTrue(spf.getFeature(NAMESPACES)); + assertTrue(spf.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXNotRecognizedException + | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Here namespace processing is enabled. This will make namespace-prefixes + * disabled. The testcase tests SAXParserFactory for this. + */ + @Test + public void spNSTable02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + assertTrue(spf.getFeature(NAMESPACES)); + assertFalse(spf.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXNotRecognizedException + | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Here namespace processing is disabled. This will make namespace-prefixes + * enabled. The testcase tests SAXParserFactory for this. + */ + @Test + public void spNSTable03() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + assertFalse(spf.getFeature(NAMESPACES)); + assertTrue(spf.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXNotRecognizedException + | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + /** + * Here namespace processing is disabled, and namespace-prefixes is + * disabled. This will make namespace processing on.The testcase tests + * SAXParserFactory for this. This behavior only apply to crimson, + * not xerces. + */ + @Test + public void spNSTable04() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setFeature(NAMESPACE_PREFIXES, false); + + assertFalse(spf.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXNotRecognizedException + | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:27.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/ParserAdapterTest.java 2014-08-20 22:07:26.000000000 -0700 @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.ParserAdapter; +import org.xml.sax.helpers.XMLFilterImpl; +import org.xml.sax.helpers.XMLReaderAdapter; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + + +/** + * Unit test cases for ParserAdapter API. By default the only features recognized + * are namespaces and namespace-prefixes. + */ +public class ParserAdapterTest { + /** + * namespaces feature name. + */ + private static final String NAMESPACES = + "http://xml.org/sax/features/namespaces"; + + /** + * namespaces-prefiexs feature name. + */ + private static final String NAMESPACE_PREFIXES = + "http://xml.org/sax/features/namespace-prefixes"; + + /** + * ParserAdapter instance to share by all tests. + */ + private final ParserAdapter parserAdapter; + + /** + * Initiate ParserAdapter. + * @throws ParserConfigurationException + * @throws SAXException + */ + ParserAdapterTest() throws ParserConfigurationException, SAXException { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader); + parserAdapter = new ParserAdapter(xmlReaderAdapter); + } + + /** + * Verifies parserAdapter.getContentHandler() + */ + @Test + public void contentHandler01() { + ContentHandler contentHandler = new XMLFilterImpl(); + parserAdapter.setContentHandler(contentHandler); + assertNotNull(parserAdapter.getContentHandler()); + } + + /** + * No exception is expected when set content handler as null. + */ + @Test + public void contentHandler02() { + parserAdapter.setContentHandler(null); + } + + /** + * Verifies parserAdapter.getEntityResolver() + */ + @Test + public void entity01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + parserAdapter.setEntityResolver(xmlFilter); + assertNotNull(parserAdapter.getEntityResolver()); + } + + /** + * No exception is expected when set entity resolver as null. + */ + @Test + public void entity02() { + parserAdapter.setEntityResolver(null); + } + + /** + * Verifies parserAdapter.getDTDHandler() + */ + @Test + public void dtdHandler01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + parserAdapter.setDTDHandler(xmlFilter); + assertNotNull(parserAdapter.getDTDHandler()); + } + + /** + * No exception is expected when set DTD handler as null. + */ + @Test + public void dtdHandler02() { + parserAdapter.setDTDHandler(null); + } + + /** + * Verifies parserAdapter.getErrorHandler() + */ + @Test + public void errorHandler01() { + XMLFilterImpl eHandler = new XMLFilterImpl(); + parserAdapter.setErrorHandler(eHandler); + assertNotNull(parserAdapter.getErrorHandler()); + } + + /** + * No exception is expected when set error handler as null. + */ + @Test + public void errorHandler02() { + parserAdapter.setErrorHandler(null); + } + + /** + * parserAdapter.getFeature(NAMESPACES) returns true be default. + */ + @Test + public void getFeature01() { + try { + assertTrue(parserAdapter.getFeature(NAMESPACES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * parserAdapter.getFeature(NAMESPACE_PREFIXES) returns true be default. + */ + @Test + public void getFeature02() { + try { + assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * SAXNotRecognizedException thrown when feature name is not known one. + * @throws org.xml.sax.SAXNotRecognizedException expected Exception + */ + @Test(expectedExceptions = SAXNotRecognizedException.class) + public void getFeature03() throws SAXNotRecognizedException { + try { + parserAdapter.getFeature("no-meaning-feature"); + } catch (SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain getFeature after it's set returns set value. + */ + @Test + public void setFeature01() { + try { + parserAdapter.setFeature(NAMESPACES, false); + assertFalse(parserAdapter.getFeature(NAMESPACES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain getFeature after it's set returns set value. + */ + @Test + public void setFeature02() { + try { + parserAdapter.setFeature(NAMESPACE_PREFIXES, false); + assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain getFeature after it's set returns set value. + */ + @Test + public void setFeature03() { + try { + parserAdapter.setFeature(NAMESPACES, true); + assertTrue(parserAdapter.getFeature(NAMESPACES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain getFeature after it's set returns set value. + */ + @Test + public void setFeature04() { + try { + parserAdapter.setFeature(NAMESPACE_PREFIXES, true); + assertTrue(parserAdapter.getFeature(NAMESPACE_PREFIXES)); + } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { + failUnexpected(ex); + } + } + + /** + * NPE expected when parsing a null object by ParserAdapter. + */ + @Test(expectedExceptions = NullPointerException.class) + public void parse01() { + try { + parserAdapter.parse((InputSource)null); + } catch (IOException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * SAXException expected when parsing a wrong-formatter XML with ParserAdapter. + * @throws org.xml.sax.SAXException + */ + @Test(expectedExceptions = SAXException.class) + public void parse02() throws SAXException { + try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) { + InputSource is = new InputSource(fis); + parserAdapter.parse(is); + } catch (IOException ex) { + failUnexpected(ex); + } + } + + /** + * Parse a well-formatter XML with ParserAdapter. + */ + @Test + public void parse03() { + try(FileInputStream fis = new FileInputStream(XML_DIR + "correct.xml")) { + InputSource is = new InputSource(fis); + parserAdapter.parse(is); + } catch (IOException | SAXException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:27.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/ResolverTest.java 2014-08-20 22:07:27.000000000 -0700 @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Entity resolver should be invoked in XML parse. This test verifies parsing + * process by checking the output with golden file. + */ +public class ResolverTest { + /** + * Unit test for entityResolver setter. + */ + public void testResolver() { + String outputFile = CLASS_DIR + "EntityResolver.out"; + String goldFile = GOLDEN_DIR + "EntityResolverGF.out"; + String xmlFile = XML_DIR + "publish.xml"; + + try(FileInputStream instream = new FileInputStream(xmlFile); + MyEntityResolver eResolver = new MyEntityResolver(outputFile)) { + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setEntityResolver(eResolver); + InputSource is = new InputSource(instream); + xmlReader.parse(is); + } catch(IOException | SAXException | ParserConfigurationException ex ) { + failUnexpected(ex); + } + // Need close the output file before we compare it with golden file. + try { + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} + +/** + * Simple entity resolver to write every entity to an output file. + */ +class MyEntityResolver extends XMLFilterImpl implements AutoCloseable { + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Initiate FileWriter when construct a MyContentHandler. + * @param outputFileName output file name. + * @throws SAXException creation of FileWriter failed. + */ + MyEntityResolver(String outputFileName) throws SAXException { + super(); + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write In resolveEntity tag along with publicid and systemId when meet + * resolveEntity event. + * @throws IOException error happen when writing file. + */ + @Override + public InputSource resolveEntity(String publicid, String systemid) + throws SAXException, IOException { + String str = "In resolveEntity.." + " " + publicid + " " + systemid; + bWriter.write( str, 0,str.length()); + bWriter.newLine(); + return super.resolveEntity(publicid, systemid); + } + + /** + * Flush the content and close the file. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void close() throws IOException { + bWriter.flush(); + bWriter.close(); + } +} --- /dev/null 2014-08-20 22:07:28.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/SAXParserNSTableTest.java 2014-08-20 22:07:28.000000000 -0700 @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * This class contains the testcases to test SAXParser with regard to + * Namespace Table defined at http://www.megginson.com/SAX/Java/namespaces.html + */ +public class SAXParserNSTableTest { + /** + * namespace processing is enabled. namespace-prefix is also is enabled. + * So it is a True-True combination. + * The test is to test SAXParser with these conditions + */ + @Test + public void testWithTrueTrue() { + String outputFile = CLASS_DIR + "SPNSTableTT.out"; + String goldFile = GOLDEN_DIR + "NSTableTTGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setFeature("http://xml.org/sax/features/namespace-prefixes", + true); + + SAXParser saxParser = spf.newSAXParser(); + saxParser.parse(new File(xmlFile), new MyNSContentHandler(outputFile)); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } + /** + * namespace processing is enabled. Hence namespace-prefix is + * expected to be automaically off. So it is a True-False combination. + * The test is to test SAXParser with these conditions + */ + public void testWithTrueFalse() { + String outputFile = CLASS_DIR + "SPNSTableTF.out"; + String goldFile = GOLDEN_DIR + "NSTableTFGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + saxParser.parse(new File(xmlFile), new MyNSContentHandler(outputFile)); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } + + /** + * namespace processing is not enabled. Hence namespace-prefix is + * expected to be automaically on. So it is a False-True combination. + * The test is to test SAXParser with these conditions + */ + public void testWithFalseTrue() { + String outputFile = CLASS_DIR + "SPNSTableFT.out"; + String goldFile = GOLDEN_DIR + "NSTableFTGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + saxParser.parse(new File(xmlFile), new MyNSContentHandler(outputFile)); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} --- /dev/null 2014-08-20 22:07:28.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLFilterCBTest.java 2014-08-20 22:07:28.000000000 -0700 @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Set parent of XMLFilter to XMLReader. Parsing on XML file will invoke XMLFilter + * to write to output file. Test verifies output is same as the golden file. + */ +public class XMLFilterCBTest { + public void testXMLFilterCB() { + String outputFile = CLASS_DIR + "XMLFilter.out"; + String goldFile = GOLDEN_DIR + "XMLFilterGF.out"; + String xmlFile = XML_DIR + "namespace1.xml"; + + try (FileInputStream fis = new FileInputStream(xmlFile)){ + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + MyXMLFilter myXmlFilter = new MyXMLFilter(outputFile); + myXmlFilter.setParent(xmlReader); + InputSource is = new InputSource(fis); + myXmlFilter.parse(is); + } catch( SAXException | IOException | ParserConfigurationException ex) { + failUnexpected(ex); + } + // Need close the output file before we compare it with golden file. + try { + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (IOException ex) { + failUnexpected(ex); + } finally { + try { + Path outputPath = Paths.get(outputFile); + if(Files.exists(outputPath)) + Files.delete(outputPath); + } catch (IOException ex) { + failCleanup(ex, outputFile); + } + } + } +} + +/** + * Writer XMLFiler which write all tags to output file when event happens. + */ +class MyXMLFilter extends XMLFilterImpl{ + /** + * FileWriter to write string to output file. + */ + private final BufferedWriter bWriter; + + /** + * Initiate FileWriter for output file. + * @param outputFileName output file name. + * @throws SAXException if open file failed. + */ + MyXMLFilter(String outputFileName) throws SAXException { + try { + bWriter = new BufferedWriter(new FileWriter(outputFileName)); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write characters tag along with content of characters when meet + * characters event. + * @throws IOException error happen when writing file. + */ + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + String s = new String(ch, start, length); + println("characters...\n" + s); + } + + /** + * Write endDocument tag then flush the content and close the file when meet + * endDocument event. + * @throws IOException error happen when writing file or closing file. + */ + @Override + public void endDocument() throws SAXException { + try { + println("endDocument..."); + bWriter.flush(); + bWriter.close(); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Write endElement tag with namespaceURI, localName, qName to the file when + * meet endElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void endElement(String namespaceURI,String localName,String qName) + throws SAXException{ + println("endElement...\n" + "namespaceURI: " + namespaceURI + + " localName: "+ localName + " qName: " + qName); + } + + /** + * Write endPrefixMapping tag along with prefix to the file when meet + * endPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void endPrefixMapping(String prefix) throws SAXException { + println("endPrefixmapping .." + prefix); + } + + /** + * Write error tag along with exception to the file when meet recoverable + * error event. + * @throws IOException error happen when writing file. + */ + @Override + public void error(SAXParseException e) throws SAXException { + println("error: " + e.getMessage()); + } + + /** + * Write fatalError tag along with exception to the file when meet + * unrecoverable error event. + * @throws IOException error happen when writing file. + */ + @Override + public void fatalError(SAXParseException e) throws SAXException { + println("fatal error: "); + } + + /** + * Write warning tag along with exception to the file when meet warning event. + * @throws IOException error happen when writing file. + */ + @Override + public void warning(SAXParseException e) throws SAXException { + println("warning : "); + } + + /** + * Write ignorableWhitespace tag along with white spaces when meet + * ignorableWhitespace event. + * @throws IOException error happen when writing file. + */ + @Override + public void ignorableWhitespace(char[] ch, int start, int length) + throws SAXException { + String s = new String(ch, start, length); + println("ignorableWhitespace...\n" + s + + " ignorable white space string length: " + s.length()); + } + + /** + * Write processingInstruction tag along with target name and target data + * when meet processingInstruction event. + * @throws IOException error happen when writing file. + */ + @Override + public void processingInstruction(String target, String data) + throws SAXException { + println("processingInstruction...target:" + target + + " data: " + data); + } + + /** + * Write setDocumentLocator tag when meet setDocumentLocator event. + */ + @Override + public void setDocumentLocator(Locator locator) { + try { + println("setDocumentLocator..."); + } catch (SAXException ex) { + System.err.println(ex); + } + } + + /** + * Write skippedEntity tag along with entity name when meet skippedEntity + * event. + * @throws IOException error happen when writing file. + */ + @Override + public void skippedEntity(String name) throws SAXException { + println("skippedEntity...\n" + "name: " + name); + } + + /** + * Write startDocument tag when meet startDocument event. + * @throws IOException error happen when writing file. + */ + @Override + public void startDocument() throws SAXException { + println("startDocument..."); + } + + /** + * Write startElement tag along with namespaceURI, localName, qName, number + * of attributes and line number when meet startElement event. + * @throws IOException error happen when writing file. + */ + @Override + public void startElement(String namespaceURI, String localName, + String qName, Attributes atts) throws SAXException { + println("startElement...\n" + "namespaceURI: " + namespaceURI + + " localName: " + localName + " qName: " + qName + + " Number of Attributes: " + atts.getLength()); + } + + /** + * Write startPrefixMapping tag along with prefix and uri when meet + * startPrefixMapping event. + * @throws IOException error happen when writing file. + */ + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + println("startPrefixMapping...\n" + "prefix: " + + prefix + " uri: " + uri); + } + + /** + * Write outString to file. + * @param outString String to be written to File + * @throws SAXException if write file failed + */ + private void println(String outString) throws SAXException { + try { + bWriter.write( outString, 0, outString.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException(ex); + } + } +} --- /dev/null 2014-08-20 22:07:29.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLFilterTest.java 2014-08-20 22:07:29.000000000 -0700 @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Unit test for XMLFilter. + */ +public class XMLFilterTest { + /** + * name spaces constant. + */ + private static final String NAMESPACES = + "http://xml.org/sax/features/namespaces"; + + /** + * name spaces prefixes constant. + */ + private static final String NAMESPACE_PREFIXES = + "http://xml.org/sax/features/namespace-prefixes"; + + /** + * No exception expected when set a correct content handler. + */ + @Test + public void contentHandler01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setContentHandler(xmlFilter); + assertNotNull(xmlFilter.getContentHandler()); + } + + /** + * No exception is expected when set content handler as null. + */ + @Test + public void contentHandler02() { + new XMLFilterImpl().setContentHandler(null); + } + + /** + * No exception expected when set a correct entity solver. + */ + @Test + public void entity01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setEntityResolver(xmlFilter); + assertNotNull(xmlFilter.getEntityResolver()); + } + + /** + * No exception is expected when set entity resolver as null. + */ + @Test + public void entity02() { + new XMLFilterImpl().setEntityResolver(null); + } + + /** + * No exception expected when set a correct DTD handler. + */ + @Test + public void dtdHandler01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setDTDHandler(xmlFilter); + assertNotNull(xmlFilter.getDTDHandler()); + } + + /** + * No exception is expected when set DTD handler as null. + */ + @Test + public void dtdHandler02() { + new XMLFilterImpl().setDTDHandler(null); + } + + /** + * No exception expected when set a correct error handler. + */ + @Test + public void errorHandler01() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setErrorHandler(xmlFilter); + assertNotNull(xmlFilter.getErrorHandler()); + } + + /** + * No exception is expected when set error handler as null. + */ + @Test + public void errorHandler02() { + new XMLFilterImpl().setErrorHandler(null); + } + + /** + * By default true is expected get namespaces feature. + * @throws SAXException + */ + @Test + public void getFeature01() throws SAXException { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setParent(xmlReader); + assertTrue(xmlFilter.getFeature(NAMESPACES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * By default false is expected get namespaces-prefix feature. + */ + @Test + public void getFeature02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setParent(xmlReader); + assertFalse(xmlFilter.getFeature(NAMESPACE_PREFIXES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * SAXNotRecognizedException is expected when get a feature by an invalid + * feature name. + * @throws org.xml.sax.SAXNotRecognizedException If the feature + * value can't be assigned or retrieved from the parent. + * @throws org.xml.sax.SAXNotSupportedException When the + * parent recognizes the feature name but + * cannot determine its value at this time. + */ + @Test(expectedExceptions = SAXNotRecognizedException.class) + public void getFeature03() throws SAXNotRecognizedException, + SAXNotSupportedException { + new XMLFilterImpl().getFeature("no-meaning-feature"); + } + + /** + * Set namespaces feature to a value to XMLFilter. it's expected same when + * obtain it again. + */ + @Test + public void setFeature01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setParent(xmlReader); + xmlFilter.setFeature(NAMESPACES, false); + assertFalse(xmlFilter.getFeature(NAMESPACES)); + xmlFilter.setFeature(NAMESPACES, true); + assertTrue(xmlFilter.getFeature(NAMESPACES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * Set namespaces-prefix feature to a value to XMLFilter. it's expected same + * when obtain it again. + */ + @Test + public void setFeature02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlFilter.setParent(xmlReader); + xmlFilter.setFeature(NAMESPACE_PREFIXES, false); + assertFalse(xmlFilter.getFeature(NAMESPACE_PREFIXES)); + xmlFilter.setFeature(NAMESPACE_PREFIXES, true); + assertTrue(xmlFilter.getFeature(NAMESPACE_PREFIXES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * NullPointerException is expected when parse a null InputSource. + */ + @Test(expectedExceptions = NullPointerException.class) + public void parse01() { + try { + new XMLFilterImpl().parse((InputSource)null); + } catch (IOException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * SAXException is expected when parsing a invalid formatted XML file. + * @throws org.xml.sax.SAXException when parse a incorrect formatted XML + * file. + */ + @Test(expectedExceptions = NullPointerException.class) + public void parse02() throws SAXException { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) { + InputSource is = new InputSource(fis); + xmlFilter.parse(is); + } catch (IOException ex) { + failUnexpected(ex); + } + } + + /** + * No exception when parse a normal XML file. + */ + @Test(expectedExceptions = NullPointerException.class) + public void parse03() { + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + try(FileInputStream fis = new FileInputStream(XML_DIR + "correct2.xml")) { + InputSource is = new InputSource(fis); + xmlFilter.parse(is); + } catch (IOException | SAXException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:30.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLReaderAdapterTest.java 2014-08-20 22:07:29.000000000 -0700 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.HandlerBase; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderAdapter; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Class containing the test cases for XMLReaderAdapter API + */ +public class XMLReaderAdapterTest { + /** + * http://xml.org/sax/features/namespace-prefixes property name. + */ + private final static String NM_PREFIXES_PROPERTY + = "http://xml.org/sax/features/namespace-prefixes"; + + /** + * To test the constructor that uses "org.xml.sax.driver" property + * @throws org.xml.sax.SAXException If the embedded driver cannot be + * instantiated or if the org.xml.sax.driver property is not specified. + */ + @Test + public void constructor01() throws SAXException { + assertNotNull(new XMLReaderAdapter()); + } + + /** + * To test the constructor that uses XMLReader + */ + @Test + public void constructor02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + assertNotNull(new XMLReaderAdapter(xmlReader)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * To test the parse method. The specification says that this method + * will throw an exception if the embedded XMLReader does not support + * the http://xml.org/sax/features/namespace-prefixes property. + */ + @Test + public void nsfeature01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { + xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); + } + + assertTrue(xmlReader.getFeature(NM_PREFIXES_PROPERTY)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * To test the parse method. The specification says that this method + * will throw an exception if the embedded XMLReader does not support + * the http://xml.org/sax/features/namespace-prefixes property. + */ + @Test + public void parse01() { + try (FileInputStream fis = new FileInputStream(XML_DIR + "namespace1.xml")) { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { + xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); + } + XMLReaderAdapter xmlRA = new XMLReaderAdapter(xmlReader); + + InputSource is = new InputSource(fis); + xmlRA.setDocumentHandler(new HandlerBase()); + xmlRA.parse(is); + } catch (IOException | SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:30.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLReaderFactoryTest.java 2014-08-20 22:07:30.000000000 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.XMLReaderFactory; + +/** + * Unit test for XMLReaderFactory.createXMLReader API. + */ +public class XMLReaderFactoryTest { + /** + * No exception expected when create XMLReader by default. + * @throws org.xml.sax.SAXException when xml reader creation failed. + */ + @Test + public void createReader01() throws SAXException { + assertNotNull(XMLReaderFactory.createXMLReader()); + } + + /** + * No exception expected when create XMLReader with driver name + * org.apache.xerces.parsers.SAXParser + * or com.sun.org.apache.xerces.internal.parsers.SAXParser. + * @throws org.xml.sax.SAXException when xml reader creation failed. + */ + @Test + public void createReader02() throws SAXException { + //Disable this test because this is only work for apache implementation. + /*System.setProperty("org.xml.sax.driver", + "org.apache.xerces.parsers.SAXParser"); + assertNotNull(XMLReaderFactory. + createXMLReader("org.apache.xerces.parsers.SAXParser"));*/ + System.setProperty("org.xml.sax.driver", + "com.sun.org.apache.xerces.internal.parsers.SAXParser"); + assertNotNull(XMLReaderFactory. + createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser")); + } + + /** + * SAXException expected when create XMLReader with an invalid driver name. + * @throws org.xml.sax.SAXException expected Exception + */ + @Test(expectedExceptions = SAXException.class, + expectedExceptionsMessageRegExp = + "SAX2 driver class org.apache.crimson.parser.ABCD not found") + public void createReader03() throws SAXException{ + XMLReaderFactory.createXMLReader("org.apache.crimson.parser.ABCD"); + } +} --- /dev/null 2014-08-20 22:07:31.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLReaderNSTableTest.java 2014-08-20 22:07:31.000000000 -0700 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertTrue; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import static org.xml.sax.ptests.SAXTestConst.CLASS_DIR; +import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** This class contains the testcases to test XMLReader with regard to + * Namespace Table defined at + * http://www.megginson.com/SAX/Java/namespaces.html + */ +public class XMLReaderNSTableTest { + /** + * XML file that used to be parsed. + */ + private static final String xmlFile = XML_DIR + "namespace1.xml"; + + /** + * XML namespaces prefixes. + */ + private static final String NAMESPACE_PREFIXES = + "http://xml.org/sax/features/namespace-prefixes"; + /** + * namespace processing is enabled. namespace-prefix is also is enabled. + * So it is a True-True combination. + * The test is to test XMLReader with these conditions + */ + public void testWithTrueTrue() { + String outputFile = CLASS_DIR + "XRNSTableTT.out"; + String goldFile = GOLDEN_DIR + "NSTableTTGF.out"; + + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + + XMLReader xmlReader = saxParser.getXMLReader(); + xmlReader.setFeature(NAMESPACE_PREFIXES, true); + + xmlReader.setContentHandler(new MyNSContentHandler(outputFile)); + xmlReader.parse(new InputSource(new FileInputStream(xmlFile))); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } + } + + /** + * Namespace processing is enabled. Hence namespace-prefix is + * expected to be automaically off. So it is a True-False combination. + * The test is to test XMLReader with these conditions + */ + public void testWithTrueFalse() { + String outputFile = CLASS_DIR + "XRNSTableTF.out"; + String goldFile = GOLDEN_DIR + "NSTableTFGF.out"; + + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + + xmlReader.setContentHandler(new MyNSContentHandler(outputFile)); + xmlReader.parse(new InputSource(new FileInputStream(xmlFile))); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } + } + + /** + * namespace processing is not enabled. Hence namespace-prefix is + * expected to be automaically on. So it is a False-True combination. + * The test is to test XMLReader with these conditions + */ + public void testWithFalseTrue() { + String outputFile = CLASS_DIR + "XRNSTableFT.out"; + String goldFile = GOLDEN_DIR + "NSTableFTGF.out"; + + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser saxParser = spf.newSAXParser(); + XMLReader xmlReader = saxParser.getXMLReader(); + + xmlReader.setContentHandler(new MyNSContentHandler(outputFile)); + xmlReader.parse(new InputSource(new FileInputStream(xmlFile))); + assertTrue(compareWithGold(goldFile, outputFile)); + } catch (ParserConfigurationException | SAXException | IOException ex) { + failUnexpected(ex); + } + } +} --- /dev/null 2014-08-20 22:07:31.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLReaderTest.java 2014-08-20 22:07:31.000000000 -0700 @@ -0,0 +1,738 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import java.io.FileInputStream; +import java.io.IOException; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; +import org.xml.sax.ext.DeclHandler; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.XMLFilterImpl; +import static org.xml.sax.ptests.SAXTestConst.XML_DIR; + +/** + * Class containing the test cases for SAXParser API + */ +public class XMLReaderTest { + /** + * XML namespaces. + */ + private static final String NAMESPACES = + "http://xml.org/sax/features/namespaces"; + + /** + * XML namespaces prefixes. + */ + private static final String NAMESPACE_PREFIXES = + "http://xml.org/sax/features/namespace-prefixes"; + + /** + * A string intern name. + */ + private static final String STRING_INTERNING = + "http://xml.org/sax/features/string-interning"; + + /** + * Validation name. + */ + private static final String VALIDATION = + "http://xml.org/sax/features/validation"; + + /** + * A general external entities name + */ + private static final String EXTERNAL_G_ENTITIES = + "http://xml.org/sax/features/external-general-entities"; + + /** + * A external parameter entities name + */ + private static final String EXTERNAL_P_ENTITIES = + "http://xml.org/sax/features/external-parameter-entities"; + + /** + * XML DOM node name. + */ + private static final String DOM_NODE = "http://xml.org/sax/properties/dom-node"; + + /** + * XML String name. + */ + private static final String XML_STRING = "http://xml.org/sax/properties/xml-string"; + + /** + * Declare handler name + */ + private static final String DECL_HANDLER = + "http://xml.org/sax/properties/declaration-handler"; + + /** + * Lexical handler name + */ + private static final String LEXICAL_HANDLER = + "http://xml.org/sax/properties/lexical-handler"; + + /** + * According to the SAX2 specs, All XMLReaders are required to recognize the + * http://xml.org/sax/features/namespaces feature names. + * This test case is to test this. + */ + @Test + public void featureNS01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertFalse(xmlReader.getFeature(NAMESPACES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * According to the SAX2 specs, All XMLReaders are required to recognize the + * http://xml.org/sax/features/namespaces feature names. + * This test case is to test this. + */ + @Test + public void featureNS02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertTrue(xmlReader.getFeature(NAMESPACES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain http://xml.org/sax/features/namespaces feature name after it's + * just set. Expect it's same as set value. + */ + @Test + public void featureNS03() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setFeature(NAMESPACES, true); + assertTrue(xmlReader.getFeature(NAMESPACES)); + xmlReader.setFeature(NAMESPACES, false); + assertFalse(xmlReader.getFeature(NAMESPACES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * According to the SAX2 specs, All XMLReaders are required to recognize the + * http://xml.org/sax/features/namespace-prefixes feature names. + * This test case is to test this. + */ + @Test + public void featureNSP01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES)); + + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * According to the SAX2 specs, All XMLReaders are required to recognize the + * http://xml.org/sax/features/namespace-prefixes feature names. + * This test case is to test this. + */ + @Test + public void featureNSP02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * Obtain http://xml.org/sax/features/namespaces-prefixes feature name after + * it's just set. Expect it's same as set value. + */ + @Test + public void featureNSP03() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setFeature(NAMESPACE_PREFIXES, true); + assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES)); + xmlReader.setFeature(NAMESPACE_PREFIXES, false); + assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES)); + } catch (ParserConfigurationException | SAXException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns true if a feature has not been preset when namespace + * awareness is set. + */ + @Test + public void featureSI01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertTrue(xmlReader.getFeature(STRING_INTERNING)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature with validation feature name returns the value that + * setValidation set. + */ + @Test + public void featureV01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + assertFalse(spf.newSAXParser().getXMLReader().getFeature(VALIDATION)); + spf.setValidating(true); + assertTrue(spf.newSAXParser().getXMLReader().getFeature(VALIDATION)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns the value that a feature has been preset as when + * namespace awareness is set. + */ + @Test + public void featureV02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + + xmlReader.setFeature(VALIDATION, true); + assertTrue(xmlReader.getFeature(VALIDATION)); + + xmlReader.setFeature(VALIDATION, false); + assertFalse(xmlReader.getFeature(VALIDATION)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns true if a feature has not been preset when namespace + * awareness is set. + */ + @Test + public void featureEGE01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertTrue(xmlReader.getFeature(EXTERNAL_G_ENTITIES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns false if a feature has been preset as false when + * namespace awareness is set. + */ + @Test + public void featureEGE02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setFeature(EXTERNAL_G_ENTITIES, false); + assertFalse(xmlReader.getFeature(EXTERNAL_G_ENTITIES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns true if a feature has not been preset when namespace + * awareness is set. + */ + @Test + public void featureEPE01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertTrue(xmlReader.getFeature(EXTERNAL_P_ENTITIES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature returns false if a feature has been preset as false when + * namespace awareness is set. + */ + @Test + public void featureEPE02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setFeature(EXTERNAL_P_ENTITIES, false); + assertFalse(xmlReader.getFeature(EXTERNAL_P_ENTITIES)); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * getFeature with a unknown feature name throws SAXNotRecognizedException. + * @throws SAXNotRecognizedException If the feature value can't be assigned + * or retrieved. + */ + @Test(expectedExceptions = SAXNotRecognizedException.class) + public void featureNE01() throws SAXNotRecognizedException { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + boolean noMeaningFeature = xmlReader.getFeature("no-meaning-feature"); + } catch(SAXNotRecognizedException ex) { + throw ex; + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No exception expected when set entity resolver as simple entity resolver. + */ + @Test + public void entity01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlReader.setEntityResolver(xmlFilter); + assertNotNull(xmlReader.getEntityResolver()); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No NPE expected when set entity resolver as null. + */ + @Test + public void entity02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setEntityResolver(null); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No exception expected when set DTD handler as simple DTD handler. + */ + @Test + public void dtdhandler01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlReader.setDTDHandler(xmlFilter); + assertNotNull(xmlReader.getDTDHandler()); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No NPE expected when set DTD handler as null. + */ + @Test + public void dtdhandler02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setDTDHandler(null); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No exception expected when set content handler as simple content handler. + */ + @Test + public void contenthandler01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + XMLFilterImpl xmlFilter = new XMLFilterImpl(); + xmlReader.setContentHandler(xmlFilter); + assertNotNull(xmlReader.getContentHandler()); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No NPE expected when set content handler as null. + */ + @Test + public void contenthandler02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setContentHandler(null); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No exception expected when set content handler as simple error handler. + */ + @Test + public void errorhandler01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setErrorHandler(new XMLFilterImpl()); + assertNotNull(xmlReader.getErrorHandler()); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * No NPE expected when set error handler as null. + */ + @Test + public void errorhandler02() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.setErrorHandler(null); + } catch (SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * Parse a null input source throw NPE. + */ + @Test(expectedExceptions = NullPointerException.class) + public void parse01() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.parse((InputSource)null); + } catch (SAXException | ParserConfigurationException | IOException ex) { + failUnexpected(ex); + } + } + + /** + * Unit test for parse a error-formatted file. SAXException is expected. + * @throws org.xml.sax.SAXException parsing failed. + */ + @Test(expectedExceptions = SAXException.class) + public void parse02() throws SAXException { + try (FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")){ + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + InputSource is = new InputSource(fis); + xmlReader.parse(is); + } catch (ParserConfigurationException | IOException ex) { + failUnexpected(ex); + } + } + + /** + * Unit test for parse a well-formatted file. No exception is expected. + */ + @Test + public void parse03(){ + try (FileInputStream fis = new FileInputStream(XML_DIR + "correct2.xml")) { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + InputSource is = new InputSource(fis); + xmlReader.parse(is); + } catch (IOException | SAXException | ParserConfigurationException ex) { + failUnexpected(ex); + } + } + + /** + * Modified by IBM + * Xerces does not support this feature and it is not mandatory + * @throws org.xml.sax.SAXNotSupportedException + */ + @Test(expectedExceptions = SAXNotSupportedException.class) + public void xrProperty01() throws SAXNotSupportedException { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + xmlReader.getProperty(XML_STRING); + } catch(SAXNotSupportedException ex) { + throw ex; + } catch (SAXException | ParserConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * SAXNotSupportedException thrown if property name is known but no value + * assigned to this property. + * @throws org.xml.sax.SAXNotSupportedException when XMLReader recognizes + * the property name but cannot determine its value at this time. + */ + @Test(expectedExceptions = SAXNotSupportedException.class) + public void xrProperty02() throws SAXNotSupportedException { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertNull(xmlReader.getProperty(DOM_NODE)); + } catch (SAXNotSupportedException ex) { + throw ex; + } catch (SAXException | ParserConfigurationException ex){ + failUnexpected(ex); + } + } + + + /** + * XMLReader.getProperty returns null if LEXICAL_HANDLER wasn't set. + */ + @Test + public void xrProperty03() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertNull(xmlReader.getProperty(LEXICAL_HANDLER)); + } catch (SAXException | ParserConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * XMLReader.getProperty returns null if DECL_HANDLER wasn't set. + */ + @Test + public void xrProperty04() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + assertNull(xmlReader.getProperty(DECL_HANDLER)); + } catch (SAXException | ParserConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * XMLReader.setProperty/getProperty for LEXICAL_HANDLER unit test. + */ + @Test + public void xrProperty05() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + MyLexicalHandler myLexicalHandler = new MyLexicalHandler(); + xmlReader.setProperty(LEXICAL_HANDLER, myLexicalHandler); + assertNotNull(xmlReader.getProperty(LEXICAL_HANDLER)); + } catch (SAXException | ParserConfigurationException ex){ + failUnexpected(ex); + } + } + + /** + * XMLReader.setProperty/getProperty for DECL_HANDLER unit test. + */ + @Test + public void xrProperty06() { + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + XMLReader xmlReader = spf.newSAXParser().getXMLReader(); + MyDeclHandler myDeclHandler = new MyDeclHandler(); + xmlReader.setProperty(DECL_HANDLER, myDeclHandler); + assertNotNull(xmlReader.getProperty(DECL_HANDLER)); + } catch (ParserConfigurationException | SAXException ex){ + failUnexpected(ex); + } + } +} + +/** + * Simple LexicalHandler that skips every lexical event. + */ +class MyLexicalHandler implements LexicalHandler { + /** + * Report an XML comment anywhere in the document. + * + * @param ch An array holding the characters in the comment. + * @param start The starting position in the array. + * @param length The number of characters to use from the array. + */ + @Override + public void comment(char[] ch, int start, int length) { + } + + /** + * Report the end of a CDATA section. + */ + @Override + public void endCDATA() { + } + + /** + * Report the end of DTD declarations. + */ + @Override + public void endDTD() { + } + + /** + * Report the end of an entity. + * + * @param name The name of the entity that is ending. + */ + @Override + public void endEntity(String name) { + } + + /** + * Report the start of a CDATA section. + */ + @Override + public void startCDATA() { + } + + /** + * Report the start of DTD declarations, if any. + * + * @param name The document type name. + * @param publicId The declared public identifier for the external DTD subset. + * @param systemId The declared system identifier for the external DTD subset. + */ + @Override + public void startDTD(String name, String publicId, String systemId) { + } + + /** + * Report the beginning of some internal and external XML entities. + * + * @param name The name of the entity. + */ + @Override + public void startEntity(String name) { + } +} + +/** + * Simple DeclHandler that skips every DTD declaration event. + */ +class MyDeclHandler implements DeclHandler { + /** + * Report an attribute type declaration. + * @param eName The name of the associated element. + * @param aName The name of the attribute. + * @param type A string representing the attribute type. + * @param mode A string representing the attribute defaulting mode + * ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if + * none of these applies. + * @param value A string representing the attribute's default value, + * or null if there is none. + */ + @Override + public void attributeDecl(String eName, String aName, String type, + String valueDefault, String value) { + } + + /** + * Report an element type declaration. + * @param name The element type name. + * @param model The content model as a normalized string. + */ + @Override + public void elementDecl(String name, String model) { + } + + /** + * Report a parsed external entity declaration. + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%'. + * @param publicId The entity's public identifier, or null if none + * was given. + * @param systemId The entity's system identifier. + */ + @Override + public void externalEntityDecl(String name, String publicId, + String systemId) { + } + + /** + * Report an internal entity declaration. + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%'. + * @param value The replacement text of the entity. + */ + @Override + public void internalEntityDecl(String name, String value) { + } +} --- /dev/null 2014-08-20 22:07:32.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/correct.xml 2014-08-20 22:07:32.000000000 -0700 @@ -0,0 +1,23 @@ + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-08-20 22:07:33.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/correct2.xml 2014-08-20 22:07:32.000000000 -0700 @@ -0,0 +1,22 @@ + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-08-20 22:07:33.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/family.xml 2014-08-20 22:07:33.000000000 -0700 @@ -0,0 +1,14 @@ + + + + + + +]> + + Susan + Jack + Chelsea + David + --- /dev/null 2014-08-20 22:07:34.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/firstdtd.dtd 2014-08-20 22:07:34.000000000 -0700 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + --- /dev/null 2014-08-20 22:07:34.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/invalid.xml 2014-08-20 22:07:34.000000000 -0700 @@ -0,0 +1,24 @@ + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + &mkm; + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-08-20 22:07:35.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/namespace1.xml 2014-08-20 22:07:35.000000000 -0700 @@ -0,0 +1,15 @@ + + + + Typography + + + +

    Welcome to the world of typography! Here is a book that you may find useful.

    + Digital Typography + Donald Knuth + + + + --- /dev/null 2014-08-20 22:07:36.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/ns4.xml 2014-08-20 22:07:35.000000000 -0700 @@ -0,0 +1,8 @@ +
    Book-Signing Event + + + + + + +
    --- /dev/null 2014-08-20 22:07:36.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/AttributesGF.out 2014-08-20 22:07:36.000000000 -0700 @@ -0,0 +1,135 @@ +uri <> localName qName +length: 0 + +uri <> localName qName +length: 1 +For index = 0 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 0 +getIndex(qName) <0> +getIndex(uri, localName) <0> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + + +uri <> localName qName +length: 1 +For index = 0 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 0 +getIndex(qName) <0> +getIndex(uri, localName) <0> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + + +uri <> localName qName +length: 3 +For index = 0 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 0 +getIndex(qName) <0> +getIndex(uri, localName) <0> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + +For index = 1 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 1 +getIndex(qName) <1> +getIndex(uri, localName) <1> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + +For index = 2 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 2 +getIndex(qName) <2> +getIndex(uri, localName) <2> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + + +uri <> localName qName +length: 3 +For index = 0 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 0 +getIndex(qName) <0> +getIndex(uri, localName) <0> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + +For index = 1 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 1 +getIndex(qName) <1> +getIndex(uri, localName) <1> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + +For index = 2 +getLocalName +getQName +getType +getURI <> +getValue + +Using localName, qname and uri pertaining to index = 2 +getIndex(qName) <2> +getIndex(uri, localName) <2> +getType(qName) +getType(uri, localName) +getValue(qName) +getValue(uri, localName) + + --- /dev/null 2014-08-20 22:07:37.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/AttributesNSGF.out 2014-08-20 22:07:37.000000000 -0700 @@ -0,0 +1,36 @@ +uri localName qName +length: 0 + +uri localName qName +length: 0 + +uri localName qName <title> +length: 0 + +uri <http://www.w3.org/TR/REC-html40> localName <body> qName <body> +length: 0 + +uri <http://www.w3.org/TR/REC-html40> localName <p> qName <p> +length: 0 + +uri <urn:BooksAreUs.org:BookInfo> localName <title> qName <b:title> +length: 1 +For index = 0 +getLocalName <style> +getQName <style> +getType <CDATA> +getURI <> +getValue <font-family: sans-serif;> + +Using localName, qname and uri pertaining to index = 0 +getIndex(qName) <0> +getIndex(uri, localName) <0> +getType(qName) <CDATA> +getType(uri, localName) <CDATA> +getValue(qName) <font-family: sans-serif;> +getValue(uri, localName) <font-family: sans-serif;> + + +uri <urn:BooksAreUs.org:BookInfo> localName <author> qName <b:author> +length: 0 + --- /dev/null 2014-08-20 22:07:37.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/ContentGF.out 2014-08-20 22:07:37.000000000 -0700 @@ -0,0 +1,80 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: uri: http://www.w3.org/TR/REC-html40 +startPrefixMapping... +prefix: b uri: urn:BooksAreUs.org:BookInfo +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html Number of Attributes: 0 Line# 3 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head Number of Attributes: 0 Line# 4 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title Number of Attributes: 0 Line# 5 +characters... +Typography +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head +characters... + + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body Number of Attributes: 0 Line# 8 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p Number of Attributes: 0 Line# 9 +characters... + Welcome to the world of typography! Here is a book that you may find useful. +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title Number of Attributes: 1 Line# 10 +characters... +Digital Typography +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author Number of Attributes: 0 Line# 11 +characters... +Donald Knuth +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author +characters... + + +processingInstruction...target:netscape data: http://www.hotmail.com +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body +characters... + + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html +endPrefixMapping... +prefix: +endPrefixMapping... +prefix: b +endDocument... --- /dev/null 2014-08-20 22:07:38.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/DTDHandlerGF.out 2014-08-20 22:07:38.000000000 -0700 @@ -0,0 +1,2 @@ +In unparsedEntityDecl... name:logo publicId:null systemId:http://sc11152338.us.oracle.com:8080/xmlsqe/jaxp/web/testfiles/JAXPREP/images/tool.gif notationName:gif +In notationDecl... name:gif publicId:null systemId:http://sardinia/ --- /dev/null 2014-08-20 22:07:39.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/DefaultHandlerGF.out 2014-08-20 22:07:38.000000000 -0700 @@ -0,0 +1,78 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: uri: http://www.w3.org/TR/REC-html40 +startPrefixMapping... +prefix: b uri: urn:BooksAreUs.org:BookInfo +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title Number of Attributes: 0 +characters... +Typography +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head +characters... + + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p Number of Attributes: 0 +characters... + Welcome to the world of typography! Here is a book that you may find useful. +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title Number of Attributes: 1 +characters... +Digital Typography +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author Number of Attributes: 0 +characters... +Donald Knuth +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author +characters... + + +processingInstruction...target:netscape data: http://www.hotmail.com +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body +characters... + + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html +endPrefixmapping .. +endPrefixmapping ..b +endDocument... --- /dev/null 2014-08-20 22:07:39.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/EHFatalGF.out 2014-08-20 22:07:39.000000000 -0700 @@ -0,0 +1,2 @@ +In fatalError.. +SAXParseException: The entity "mkm" was referenced, but not declared. --- /dev/null 2014-08-20 22:07:40.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/EntityResolverGF.out 2014-08-20 22:07:40.000000000 -0700 @@ -0,0 +1,2 @@ +In resolveEntity.. -//mkrishna mohan//DTD//music pub//EN/ http://sc11152338.us.oracle.com:8080/xmlsqe/jaxp/web/testfiles/JAXPREP/publishers.dtd +In resolveEntity.. null http://sc11152338.us.oracle.com:8080/xmlsqe/jaxp/web/testfiles/JAXPREP/familytree.dtd --- /dev/null 2014-08-20 22:07:40.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/NSTableFTGF.out 2014-08-20 22:07:40.000000000 -0700 @@ -0,0 +1,130 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <html> Number of Attributes: <2> Line# <3> +characters...length is:3 +< + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <head> Number of Attributes: <0> Line# <4> +characters...length is:5 +< + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <title> Number of Attributes: <0> Line# <5> +characters...length is:10 +<Typography> +endElement... +namespaceURI: <> localName: <> qName: <title> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:3 +< + > +endElement... +namespaceURI: <> localName: <> qName: <head> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:4 +< + + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <body> Number of Attributes: <0> Line# <8> +characters...length is:5 +< + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <p> Number of Attributes: <0> Line# <9> +characters...length is:77 +< Welcome to the world of typography! Here is a book that you may find useful.> +endElement... +namespaceURI: <> localName: <> qName: <p> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:5 +< + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <b:title> Number of Attributes: <1> Line# <10> +characters...length is:18 +<Digital Typography> +endElement... +namespaceURI: <> localName: <> qName: <b:title> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:1 +< > +characters...length is:5 +< + > +startPrefixMapping... +prefix: <xml> uri: <http://www.w3.org/XML/1998/namespace> +startPrefixMapping... +prefix: <xmlns> uri: <http://www.w3.org/2000/xmlns/> +startElement... +namespaceURI: <> localName: <> qName: <b:author> Number of Attributes: <0> Line# <11> +characters...length is:12 +<Donald Knuth> +endElement... +namespaceURI: <> localName: <> qName: <b:author> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:5 +< + > +processingInstruction...target:<netscape> data: <http://www.hotmail.com> +characters...length is:3 +< + > +endElement... +namespaceURI: <> localName: <> qName: <body> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +characters...length is:2 +< + +> +endElement... +namespaceURI: <> localName: <> qName: <html> +endPrefixMapping... +prefix: <xml> +endPrefixMapping... +prefix: <xmlns> +endDocument... --- /dev/null 2014-08-20 22:07:41.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/NSTableTFGF.out 2014-08-20 22:07:41.000000000 -0700 @@ -0,0 +1,80 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: <> uri: <http://www.w3.org/TR/REC-html40> +startPrefixMapping... +prefix: <b> uri: <urn:BooksAreUs.org:BookInfo> +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> Number of Attributes: <0> Line# <3> +characters...length is:3 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> Number of Attributes: <0> Line# <4> +characters...length is:5 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> Number of Attributes: <0> Line# <5> +characters...length is:10 +<Typography> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> +characters...length is:3 +< + > +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> +characters...length is:4 +< + + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> Number of Attributes: <0> Line# <8> +characters...length is:5 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> Number of Attributes: <0> Line# <9> +characters...length is:77 +< Welcome to the world of typography! Here is a book that you may find useful.> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> +characters...length is:5 +< + > +startElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> Number of Attributes: <1> Line# <10> +characters...length is:18 +<Digital Typography> +endElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> +characters...length is:5 +< + > +startElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> Number of Attributes: <0> Line# <11> +characters...length is:12 +<Donald Knuth> +endElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> +characters...length is:5 +< + > +processingInstruction...target:<netscape> data: <http://www.hotmail.com> +characters...length is:3 +< + > +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> +characters...length is:2 +< + +> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> +endPrefixMapping... +prefix: <> +endPrefixMapping... +prefix: <b> +endDocument... --- /dev/null 2014-08-20 22:07:42.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/NSTableTTGF.out 2014-08-20 22:07:41.000000000 -0700 @@ -0,0 +1,80 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: <> uri: <http://www.w3.org/TR/REC-html40> +startPrefixMapping... +prefix: <b> uri: <urn:BooksAreUs.org:BookInfo> +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> Number of Attributes: <2> Line# <3> +characters...length is:3 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> Number of Attributes: <0> Line# <4> +characters...length is:5 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> Number of Attributes: <0> Line# <5> +characters...length is:10 +<Typography> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <title> qName: <title> +characters...length is:3 +< + > +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <head> qName: <head> +characters...length is:4 +< + + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> Number of Attributes: <0> Line# <8> +characters...length is:5 +< + > +startElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> Number of Attributes: <0> Line# <9> +characters...length is:77 +< Welcome to the world of typography! Here is a book that you may find useful.> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <p> qName: <p> +characters...length is:5 +< + > +startElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> Number of Attributes: <1> Line# <10> +characters...length is:18 +<Digital Typography> +endElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <title> qName: <b:title> +characters...length is:5 +< + > +startElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> Number of Attributes: <0> Line# <11> +characters...length is:12 +<Donald Knuth> +endElement... +namespaceURI: <urn:BooksAreUs.org:BookInfo> localName: <author> qName: <b:author> +characters...length is:5 +< + > +processingInstruction...target:<netscape> data: <http://www.hotmail.com> +characters...length is:3 +< + > +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <body> qName: <body> +characters...length is:2 +< + +> +endElement... +namespaceURI: <http://www.w3.org/TR/REC-html40> localName: <html> qName: <html> +endPrefixMapping... +prefix: <> +endPrefixMapping... +prefix: <b> +endDocument... --- /dev/null 2014-08-20 22:07:42.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/out/XMLFilterGF.out 2014-08-20 22:07:42.000000000 -0700 @@ -0,0 +1,78 @@ +setDocumentLocator... +startDocument... +startPrefixMapping... +prefix: uri: http://www.w3.org/TR/REC-html40 +startPrefixMapping... +prefix: b uri: urn:BooksAreUs.org:BookInfo +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title Number of Attributes: 0 +characters... +Typography +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: title qName: title +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: head qName: head +characters... + + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body Number of Attributes: 0 +characters... + + +startElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p Number of Attributes: 0 +characters... + Welcome to the world of typography! Here is a book that you may find useful. +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: p qName: p +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title Number of Attributes: 1 +characters... +Digital Typography +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: title qName: b:title +characters... + + +startElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author Number of Attributes: 0 +characters... +Donald Knuth +endElement... +namespaceURI: urn:BooksAreUs.org:BookInfo localName: author qName: b:author +characters... + + +processingInstruction...target:netscape data: http://www.hotmail.com +characters... + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: body qName: body +characters... + + + +endElement... +namespaceURI: http://www.w3.org/TR/REC-html40 localName: html qName: html +endPrefixmapping .. +endPrefixmapping ..b +endDocument... --- /dev/null 2014-08-20 22:07:43.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/parsertest.xml 2014-08-20 22:07:43.000000000 -0700 @@ -0,0 +1,25 @@ +<?xml version="1.0" standalone="no"?> +<!DOCTYPE document SYSTEM "firstdtd.dtd"> +<document> + Publishers of the Music of New York Women Composers + + <title>The Publishers + + + Alfred Publishing + &mkm; + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-08-20 22:07:43.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/publish.xml 2014-08-20 22:07:43.000000000 -0700 @@ -0,0 +1,17 @@ + + + + Publishers of the Music of New York Women Composers + The Publishers + + ACA + info@composers.com + http://www.composers.com/ +
    170 West 74th St. NY NY 10023
    + 212-362-8900 + 212-874-8605 + &familytree; +
    +
    + --- /dev/null 2014-08-20 22:07:44.000000000 -0700 +++ new/test/javax/xml/jaxp/functional/org/xml/sax/xmlfiles/valid.xml 2014-08-20 22:07:44.000000000 -0700 @@ -0,0 +1,24 @@ + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + &mkm; + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-08-20 22:07:45.000000000 -0700 +++ new/test/javax/xml/jaxp/libs/javax/xml/transform/ptests/MyContentHandler.java 2014-08-20 22:07:44.000000000 -0700 @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.xml.transform.ptests; + +import org.xml.sax.ContentHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.Locator; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +/** + * A customized ContentHandler. It writes whole XML file with extra tag on every + * XML elements. + */ +public class MyContentHandler implements ContentHandler { + /** + * FileWrite to write content to. + */ + private final BufferedWriter bWriter; + + /** + * Create FileWiter for the processing. + * @param fileName Output file name. + * @throws org.xml.sax.SAXException + */ + public MyContentHandler(String fileName) throws SAXException { + try { + bWriter = new BufferedWriter(new FileWriter(fileName)); + } catch (IOException ex) { + throw new SAXException("Open file error", ex); + } + } + + /** + * Do nothing when set document locator. + */ + @Override + public void setDocumentLocator (Locator locator) { + } + + /** + * Open the output file when start to process the document. Write a + * startDocument tag to output File if opening file successfully. + * @throws SAXException if file writing failed. + */ + @Override + public void startDocument () throws SAXException { + //Bug # 4448884 filed. setDocumentLocator method should be called + //first. The bug won't be fixed. So startDocument is the next method + println("startDocument"); + } + + /** + * Write a startDocument tag to output File after processing whole document. + * Follow with closing the output file. + * @throws SAXException if file writing failed. + */ + @Override + public void endDocument() throws SAXException { + println("endDocument"); + + try { + bWriter.flush(); + bWriter.close(); + } catch (IOException ex) { + throw new SAXException("Close file error", ex); + } + } + + /** + * Write a startPrefixMapping appending with prefix and URI to output File + * before entering the scope of a prefix-URI mapping. + * @param prefix the Namespace prefix being declared. + * @param uri the Namespace URI the prefix is mapped to. + * @throws SAXException if file writing failed. + */ + @Override + public void startPrefixMapping (String prefix, String uri) + throws SAXException { + println("startPrefixMapping: " + prefix + ", " + uri); + } + + /** + * Write a endPrefixMapping appending with prefix to output File after a + * prefix-URI mapping. + * @param prefix the Namespace prefix being declared. + * @throws SAXException if file writing failed. + */ + @Override + public void endPrefixMapping (String prefix) throws SAXException { + println("endPrefixMapping: " + prefix); + } + + /** + * Write a startElement appending with namespaceURI,localName,qName and + * iteration on attributes to output File when start processing element. + * @param namespaceURI the Namespace URI. + * @param localName the local name (without prefix). + * @param qName the qualified name (with prefix). + * @param atts the attributes attached to the element. + * @throws SAXException if file writing failed. + */ + @Override + public void startElement (String namespaceURI, String localName, + String qName, Attributes atts) + throws SAXException { + String str = "startElement: " + namespaceURI + ", " + namespaceURI + + ", " + qName; + int n = atts.getLength(); + for(int i = 0; i < n; i++) { + str = str + ", " + atts.getQName(i); + } + + println(str); + } + + /** + * Write a startElement appending with namespaceURI,qName and to output File + * after processing element finished. + * @param namespaceURI the Namespace URI. + * @param localName the local name (without prefix). + * @param qName the qualified name (with prefix). + * @throws SAXException if file writing failed. + */ + @Override + public void endElement (String namespaceURI, String localName, + String qName) throws SAXException { + println("endElement: " + namespaceURI + ", " + namespaceURI + ", " + qName); + } + + + /** + * Write characters tag to file when receive character data. + * @param ch the characters from the XML document + * @param start the start position in the array + * @param length the number of characters to read from the array + * @throws SAXException if file writing failed. + */ + @Override + public void characters (char ch[], int start, int length) + throws SAXException { + println("characters"); + } + + /** + * Write ignorableWhitespace tag to file when receive notification of + * ignorable whitespace in element content. + * @param ch an array holds all ignorable whitespace. + * @param start start position of ignorable whitespace. + * @param length length of ignorable whitespace. + * @throws SAXException if file writing failed. + */ + @Override + public void ignorableWhitespace (char ch[], int start, int length) + throws SAXException { + println("ignorableWhitespace"); + } + + /** + * Write processingInstruction tag when receive notification of a processing + * instruction. + * @param target the processing instruction target + * @param data the processing instruction data, or null if none was + * supplied. The data does not include any whitespace + * separating it from the target. + * @throws SAXException if file writing failed. + */ + @Override + public void processingInstruction (String target, String data) + throws SAXException { + println("processingInstruction: " + target + ", " + target); + } + + /** + * Write the entity name to file when receive notification of a skipped entity. + * @param name entity name that skipped + * @throws SAXException if file writing failed. + */ + @Override + public void skippedEntity (String name) throws SAXException { + println("skippedEntity: " + name); + } + + /** + * Print a string output to file along with a new line. + * @param output string needed to be written to file. + * @throws SAXException if file writing failed. + */ + private void println(String output) throws SAXException { + try { + bWriter.write(output, 0, output.length()); + bWriter.newLine(); + } catch (IOException ex) { + throw new SAXException("bWriter error", ex); + } + } +} --- /dev/null 2014-08-20 22:07:45.000000000 -0700 +++ new/test/javax/xml/jaxp/libs/javax/xml/transform/ptests/TransformerTestConst.java 2014-08-20 22:07:45.000000000 -0700 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package javax.xml.transform.ptests; + +import static jaxp.library.JAXPTestUtilities.FILE_SEP; +import static jaxp.library.JAXPTestUtilities.USER_DIR; + +/** + * This is the Base test class provide basic support for JAXP functional test + */ +public class TransformerTestConst { + /** + * Current test directory. + */ + public static final String CLASS_DIR + = System.getProperty("test.classes", ".") + FILE_SEP; + + /** + * Package name that separates by slash. + */ + public static final String PACKAGE_NAME = FILE_SEP + + TransformerTestConst.class.getPackage().getName().replaceAll("[.]", FILE_SEP); + + /** + * Test base directory. Every package has its own test package directory. + */ + public static final String BASE_DIR + = System.getProperty("test.src", USER_DIR).replaceAll("\\" + System.getProperty("file.separator"), "/") + + PACKAGE_NAME + FILE_SEP + ".."; + + /** + * Source XML file directory. + */ + public static final String XML_DIR = BASE_DIR + FILE_SEP + "xmlfiles" + FILE_SEP; + + /** + * Golden output file directory. We pre-define all expected output in golden + * output file. Test verifies whether the standard output is same as content + * of golden file. + */ + public static final String GOLDEN_DIR = XML_DIR + FILE_SEP + "out" + FILE_SEP; +} --- /dev/null 2014-08-20 22:07:46.000000000 -0700 +++ new/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java 2014-08-20 22:07:46.000000000 -0700 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jaxp.library; + + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import static org.testng.Assert.fail; + +/** + * This is an interface provide basic support for JAXP functional test. + */ +public class JAXPTestUtilities { + /** + * Prefix for error message. + */ + public static final String ERROR_MSG_HEADER = "Unexcepted exception thrown:"; + + /** + * Prefix for error message on clean up block. + */ + public static final String ERROR_MSG_CLEANUP = "Clean up failed on %s"; + + /** + * Force using slash as File separator as we always use cygwin to test in + * Windows platform. + */ + public static final String FILE_SEP = "/"; + + /** + * User home. + */ + public static final String USER_DIR = System.getProperty("user.dir", "."); + + /** + * TEMP file directory. + */ + public static final String TEMP_DIR = System.getProperty("java.io.tmpdir", "."); + + /** + * Compare contents of golden file with test output file line by line. + * return true if they're identical. + * @param goldfile Golden output file name + * @param outputfile Test output file name + * @return true if two files are identical. + * false if two files are not identical. + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read + */ + public static boolean compareWithGold(String goldfile, String outputfile) + throws IOException { + return Files.readAllLines(Paths.get(goldfile)). + equals(Files.readAllLines(Paths.get(outputfile))); + } + + /** + * Prints error message if an exception is thrown + * @param ex The exception is thrown by test. + */ + public static void failUnexpected(Throwable ex) { + fail(ERROR_MSG_HEADER, ex); + } + + /** + * Prints error message if an exception is thrown when clean up a file. + * @param ex The exception is thrown in cleaning up a file. + * @param name Cleaning up file name. + */ + public static void failCleanup(IOException ex, String name) { + fail(String.format(ERROR_MSG_CLEANUP, name), ex); + } +} --- /dev/null 2014-08-20 22:07:47.000000000 -0700 +++ new/test/javax/xml/jaxp/libs/org/xml/sax/ptests/SAXTestConst.java 2014-08-20 22:07:46.000000000 -0700 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.xml.sax.ptests; + +import static jaxp.library.JAXPTestUtilities.FILE_SEP; +import static jaxp.library.JAXPTestUtilities.USER_DIR; + +/** + * This is the Base test class provide basic support for JAXP SAX functional + * test. These are JAXP SAX functional related properties that every test suite + * has their own TestBase class. + */ +public class SAXTestConst { + /** + * Current test directory. + */ + public static final String CLASS_DIR + = System.getProperty("test.classes", ".") + FILE_SEP; + + /** + * Package name that separates by slash. + */ + public static final String PACKAGE_NAME = FILE_SEP + + SAXTestConst.class.getPackage().getName().replaceAll("[.]", FILE_SEP); + + /** + * Test base directory. Every package has its own test package directory. + */ + public static final String BASE_DIR + = System.getProperty("test.src", USER_DIR).replaceAll("\\" + System.getProperty("file.separator"), "/") + + PACKAGE_NAME + FILE_SEP + ".."; + + /** + * Source XML file directory. + */ + public static final String XML_DIR = BASE_DIR + FILE_SEP + "xmlfiles" + FILE_SEP; + + /** + * Golden output file directory. We pre-define all expected output in golden + * output file. Test verifies whether the standard output is same as content + * of golden file. + */ + public static final String GOLDEN_DIR = XML_DIR + FILE_SEP + "out" + FILE_SEP; +}