--- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/AstroTest.java 2015-03-30 19:51:28.600466146 -0700 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static java.lang.String.valueOf; +import static jaxp.library.JAXPTestUtilities.USER_DIR; +import static org.testng.Assert.assertEquals; +import static test.astro.AstroConstants.ASTROCAT; +import static test.astro.AstroConstants.GOLDEN_DIR; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import javax.xml.transform.sax.TransformerHandler; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/* + * @summary run astro application, test xslt + * + * There are vast amounts of textual astronomical data, typically user is + * interested in a small subset, which is the result from carrying out a query. + * A query can be composed of one or more filters, for example, the user could + * query the database for all stars of visual magnitude down to 6.5 that lie + * between right ascensions 0 h to 2 h, and between declinations of 45 to 90 degrees. + * + * Astro application uses JAXP to query astronomical data saved in an XML dataset. + * A FilterFactory implementation creates filter(A filter is an instance of a JAXP + * TransformerHandler) from an XSL stylesheet. + * A InputSourceFactory implementation creates a new sax input source from an XML file. + * AstroProcessor leverages InputSourceFactory to parse catalog.xml, which saves + * textual astronomical data, and then creates filters with specified parameters + * from FilterFactory, all of the filters are chained together, AstroProcessor + * appends the HTML filter at the end of filter chain, and hooks up the chain to + * the input source, finally processes and outputs to the user specified output file. + * + * AstroTest drives AstroProcessor to run the specified queries(total 4 in setup), + * and then compares the output with the golden files to determine PASS or FAIL. + * It provides variant implementations of FilterFactory and InputSourceFactory to + * AstroProcessor to test different JAXP classes and features. + * + */ +public class AstroTest extends JAXPFileBaseTest { + private FiltersAndGolden[] data; + + @BeforeClass + public void setup() throws Exception { + data = new FiltersAndGolden[4]; + data[0] = new FiltersAndGolden(getGoldenFileContent(1), astro -> astro.getRAFilter(0.106, 0.108)); + data[1] = new FiltersAndGolden(getGoldenFileContent(2), astro -> astro.getStellarTypeFilter("K0IIIbCN-0.5")); + data[2] = new FiltersAndGolden(getGoldenFileContent(3), astro -> astro.getStellarTypeFilter("G"), astro -> astro.getDecFilter(-5.0, 60.0)); + data[3] = new FiltersAndGolden(getGoldenFileContent(4), astro -> astro.getRADECFilter(0.084, 0.096, -5.75, 14.0)); + + Files.createDirectories(Paths.get(USER_DIR + "astro")); + } + + /* + * Provide permutations of InputSourceFactory and FilterFactory for test. + */ + @DataProvider(name = "factories") + public Object[][] getQueryFactories() { + return new Object[][] { + { StreamFilterFactoryImpl.class, InputSourceFactoryImpl.class }, + { SAXFilterFactoryImpl.class, InputSourceFactoryImpl.class }, + { DOMFilterFactoryImpl.class, InputSourceFactoryImpl.class }, + { TemplatesFilterFactoryImpl.class, InputSourceFactoryImpl.class }, + { StreamFilterFactoryImpl.class, DOML3InputSourceFactoryImpl.class } }; + } + + @Test(dataProvider = "factories") + public void test(Class fFactClass, Class isFactClass) throws Exception { + System.out.println(fFactClass.getName() +" : " + isFactClass.getName()); + AstroProcessor astro = new AstroProcessor(fFactClass, ASTROCAT, isFactClass); + + for (int i = 0; i < data.length; i++) { + runProcess(astro, valueOf(i + 1), data[i].getGolden(), data[i].getFilters()); + } + } + + private void runProcess(AstroProcessor astro, String processNum, List goldenfileContent, FilterCreator... filterCreators) throws Exception { + System.out.println("run process " + processNum); + TransformerHandler[] filters = new TransformerHandler[filterCreators.length]; + for (int i = 0; i < filterCreators.length; i++) + filters[i] = filterCreators[i].createFilter(astro); + + String outputfile = Files.createTempFile(Paths.get(USER_DIR + "/astro"), "query" + processNum + ".out.", null).toString(); + System.out.println("output file: " + outputfile); + astro.process(outputfile, filters); + assertEquals(Files.readAllLines(Paths.get(outputfile)), goldenfileContent); + } + + private List getGoldenFileContent(int num) throws IOException { + return Files.readAllLines(Paths.get(GOLDEN_DIR + "query" + num + ".out")); + } + + @FunctionalInterface + private interface FilterCreator { + TransformerHandler createFilter(AstroProcessor astro) throws Exception; + } + + private static class FiltersAndGolden { + private FilterCreator[] filters; + private List golden; + + FiltersAndGolden(List golden, FilterCreator... filters) { + this.filters = filters; + this.golden = golden; + } + + FilterCreator[] getFilters() { + return filters; + } + + List getGolden() { + return golden; + } + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/DocumentLSTest.java 2015-03-30 19:51:29.085527795 -0700 @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.USER_DIR; +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.w3c.dom.ls.DOMImplementationLS.MODE_SYNCHRONOUS; +import static test.astro.AstroConstants.ASTROCAT; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSOutput; +import org.w3c.dom.ls.LSParser; +import org.w3c.dom.ls.LSSerializer; + +/* + * @summary DOM L3 DocumentLS tests + */ +public class DocumentLSTest extends JAXPFileBaseTest { + @Test + public void testNewDocument() throws ParserConfigurationException { + Document doc = getDocumentBuilder().newDocument(); + assertNull(doc.getDocumentElement()); + } + + @Test + public void testLSInputParseXMLFile() throws Exception { + DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation(); + LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null); + LSInput src = impl.createLSInput(); + + try (InputStream is = new FileInputStream(ASTROCAT)) { + src.setByteStream(is); + assertNotNull(src.getByteStream()); + // set certified accessor methods + boolean origCertified = src.getCertifiedText(); + src.setCertifiedText(true); + assertTrue(src.getCertifiedText()); + src.setCertifiedText(origCertified); // set back to orig + + src.setSystemId(filenameToURL(ASTROCAT)); + + Document doc = domParser.parse(src); + Element result = doc.getDocumentElement(); + assertEquals(result.getTagName(), "stardb"); + } + } + + @Test + public void testLSInputParseString() throws Exception { + DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation(); + String xml = "runDocumentLS_Q6"; + + LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null); + LSSerializer domSerializer = impl.createLSSerializer(); + // turn off xml decl in serialized string for comparison + domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); + LSInput src = impl.createLSInput(); + src.setStringData(xml); + assertEquals(src.getStringData(), xml); + + Document doc = domParser.parse(src); + String result = domSerializer.writeToString(doc); + + assertEquals(result, "runDocumentLS_Q6"); + } + + @Test + public void testLSOutput() throws Exception { + DocumentBuilder db = getDocumentBuilder(); + // Create the Document using the supplied builder... + Document doc = db.parse(ASTROCAT); + + DOMImplementationLS impl = null; + + impl = (DOMImplementationLS) db.getDOMImplementation(); + LSSerializer domSerializer = impl.createLSSerializer(); + MyDOMOutput mydomoutput = new MyDOMOutput(); + try (OutputStream os = new FileOutputStream(USER_DIR + "test.out")) { + mydomoutput.setByteStream(os); + mydomoutput.setEncoding("UTF-8"); + assertTrue(domSerializer.write(doc, mydomoutput)); + } + } + + private static class MyDOMOutput implements LSOutput { + private OutputStream bytestream = null; + private String encoding = null; + private String sysId = null; + private Writer writer = null; + + public OutputStream getByteStream() { + return bytestream; + } + + public Writer getCharacterStream() { + return writer; + } + + public String getEncoding() { + return encoding; + } + + public String getSystemId() { + return sysId; + } + + public void setByteStream(OutputStream bs) { + bytestream = bs; + } + + public void setCharacterStream(Writer cs) { + writer = cs; + } + + public void setEncoding(String enc) { + encoding = enc; + } + + public void setSystemId(String sysId) { + this.sysId = sysId; + } + } + + private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + return dbf.newDocumentBuilder(); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/NamespaceContextTest.java 2015-03-30 19:51:29.392566818 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX; +import static javax.xml.XMLConstants.NULL_NS_URI; +import static org.testng.Assert.assertEquals; + +import javax.xml.namespace.QName; + +import jaxp.library.JAXPBaseTest; + +import org.testng.annotations.Test; + +/* + * @summary javax.xml.namespace.QName tests + */ +public class NamespaceContextTest extends JAXPBaseTest { + private static final String PREFIX = "astro"; + private static final String LOCAL_PART = "stardb"; + private static final String NS_URI = "http://www.astro.com"; + + @Test + public void testQNameConstructor() { + QName qname = new QName(NS_URI, LOCAL_PART, PREFIX); + assertEquals(qname.getNamespaceURI(), NS_URI); + assertEquals(qname.getLocalPart(), LOCAL_PART); + assertEquals(qname.getPrefix(), PREFIX); + } + + @Test + public void testDefaultFields() { + QName qname = new QName(LOCAL_PART); // just the local part specified + assertEquals(qname.getNamespaceURI(), NULL_NS_URI); + assertEquals(qname.getLocalPart(), LOCAL_PART); + assertEquals(qname.getPrefix(), DEFAULT_NS_PREFIX); + } + + @Test + public void testDefaultPrefix() { + QName qname = new QName(NS_URI, LOCAL_PART); // no pref + assertEquals(qname.getNamespaceURI(), NS_URI); + assertEquals(qname.getLocalPart(), LOCAL_PART); + assertEquals(qname.getPrefix(), DEFAULT_NS_PREFIX); + } + + @Test + public void testQNameString() { + QName qname = new QName(NS_URI, LOCAL_PART, PREFIX); + assertEquals(QName.valueOf(qname.toString()), qname); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/SAX201Test.java 2015-03-30 19:51:29.668601901 -0700 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import javax.xml.parsers.SAXParserFactory; + +import jaxp.library.JAXPBaseTest; + +import org.testng.annotations.Test; +import org.xml.sax.XMLReader; + +/* + * @summary test SAX 2.0.1 + */ +public class SAX201Test extends JAXPBaseTest { + @Test + public void test() throws Exception { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader reader = spf.newSAXParser().getXMLReader(); + reader.setErrorHandler(null); // SAX 2.0.1 allows + reader.setContentHandler(null); // SAX 2.0.1 allows + reader.setEntityResolver(null); // SAX 2.0.1 allows + reader.setDTDHandler(null); // SAX 2.0.1 allows + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/SchemaValidationTest.java 2015-03-30 19:51:29.959638890 -0700 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import static test.astro.AstroConstants.ASTROCAT; +import static test.astro.AstroConstants.JAXP_SCHEMA_LANGUAGE; +import static test.astro.AstroConstants.JAXP_SCHEMA_SOURCE; + +import java.io.File; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/* + * @summary schema validation tests + */ +public class SchemaValidationTest extends JAXPFileBaseTest { + /* + * Only set the schemaLanguage, without setting schemaSource. It should + * work. + */ + @Test + public void testSchemaValidation() throws Exception { + SAXParser sp = getValidatingParser(); + sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + sp.parse(new File(ASTROCAT), new DefaultHandler()); + } + + /* + * Test SAXException shall be thrown if schemaSource is set but + * schemaLanguage is not set. + */ + @Test(expectedExceptions = SAXException.class) + public void testSchemaValidationNeg() throws Exception { + SAXParser sp = getValidatingParser(); + sp.setProperty(JAXP_SCHEMA_SOURCE, "catalog.xsd"); + sp.parse(new File(ASTROCAT), new DefaultHandler()); + } + + private SAXParser getValidatingParser() throws ParserConfigurationException, SAXException { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setValidating(true); + return spf.newSAXParser(); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/XPathAPITest.java 2015-03-30 19:51:30.296681727 -0700 @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL; +import static javax.xml.xpath.XPathConstants.NODESET; +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static org.testng.Assert.assertEquals; +import static test.astro.AstroConstants.ASTROCAT; +import static test.astro.AstroConstants.JAXP_SCHEMA_LANGUAGE; +import static test.astro.AstroConstants.JAXP_SCHEMA_SOURCE; + +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import javax.xml.xpath.XPathVariableResolver; + +import jaxp.library.JAXPFileBaseTest; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/* + * @summary test XPath API + */ +@Test(singleThreaded = true) +public class XPathAPITest extends JAXPFileBaseTest { + private static final String STARDB_STAR_3_CONSTELLATION = "//astro:stardb/astro:star[3]/astro:constellation"; + private static final String STARDB_STAR = "//astro:stardb/astro:star"; + private Document doc; + private XPathFactory xpf; + private NamespaceContext nsContext; + + @BeforeClass + public void setup() throws Exception { + DocumentBuilderFactory df = DocumentBuilderFactory.newInstance(); + df.setNamespaceAware(true); + df.setValidating(true); + df.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + df.setAttribute(JAXP_SCHEMA_SOURCE, "catalog.xsd"); + DocumentBuilder bldr = df.newDocumentBuilder(); + doc = bldr.parse(ASTROCAT); + + xpf = XPathFactory.newInstance(DOM_OBJECT_MODEL); + + nsContext = new MyNamespaceContext(); + } + + @DataProvider(name = "nodelist-evaluator") + public Object[][] getNodeListEvaluator() throws MalformedURLException { + return new Object[][] { + { (XPathEvaluator) expression -> getXPath().evaluate(expression, doc.getDocumentElement(), NODESET) }, + { (XPathEvaluator) expression -> getXPath().evaluate(expression, createXMLInputSource(), NODESET) }, + { (XPathEvaluator) expression -> getXPathExpression(expression).evaluate(doc.getDocumentElement(), NODESET) }, + { (XPathEvaluator) expression -> getXPathExpression(expression).evaluate(createXMLInputSource(), NODESET) } }; + } + + @Test(dataProvider = "nodelist-evaluator") + public void testEvaluateNodeList(XPathEvaluator evaluator) throws Exception { + NodeList o = (NodeList) evaluator.evaluate(STARDB_STAR); + assertEquals(o.getLength(), 10); + } + + @DataProvider(name = "string-evaluator") + public Object[][] getStringEvaluator() throws MalformedURLException { + return new Object[][] { + { (XPathEvaluator) expression -> getXPath().evaluate(expression, doc.getDocumentElement()) }, + { (XPathEvaluator) expression -> getXPath().evaluate(expression, createXMLInputSource()) }, + { (XPathEvaluator) expression -> getXPathExpression(expression).evaluate(doc.getDocumentElement()) }, + { (XPathEvaluator) expression -> getXPathExpression(expression).evaluate(createXMLInputSource()) } }; + } + + @Test(dataProvider = "string-evaluator") + public void testEvaluateString(XPathEvaluator evaluator) throws Exception { + assertEquals(evaluator.evaluate(STARDB_STAR_3_CONSTELLATION), "Psc"); + } + + @Test + public void testXPathVariableResolver() throws Exception { + XPath xpath = getXPath(); + xpath.setXPathVariableResolver(new MyXPathVariableResolver()); + assertEquals(xpath.evaluate("//astro:stardb/astro:star[astro:hr=$id]/astro:constellation", doc.getDocumentElement()), "Peg"); + + } + + private static class MyXPathVariableResolver implements XPathVariableResolver { + public Object resolveVariable(QName vname) { + return "4"; //resolve $id as 4, xpath will locate to star[hr=4] + } + } + + /* + * Implementation of a NamespaceContext interface for the Xpath api tests. + * Used in xpath.setNamespaceContext(...) + */ + + private static class MyNamespaceContext implements NamespaceContext { + public String getNamespaceURI(String prefix) { + return "astro".equals(prefix) ? "http://www.astro.com/astro" : ""; + } + + public String getPrefix(String nsURI) { + return "http://www.astro.com/astro".equals(nsURI) ? "astro" : ""; + } + + public Iterator getPrefixes(String nsURI) { + ArrayList list = new ArrayList(); + list.add("astro"); + return list.iterator(); + } + } + + @FunctionalInterface + private interface XPathEvaluator { + Object evaluate(String expression) throws XPathExpressionException; + } + + private XPath getXPath() { + XPath xpath = xpf.newXPath(); + xpath.setNamespaceContext(nsContext); + return xpath; + } + + private XPathExpression getXPathExpression(String expression) throws XPathExpressionException { + return getXPath().compile(expression); + } + + private InputSource createXMLInputSource() { + return new InputSource(filenameToURL(ASTROCAT)); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/catalog.xml 2015-03-30 19:51:30.595719733 -0700 @@ -0,0 +1,17 @@ + + + <_test01> + + + <_test-04>T%e!s#t$ +
1000509.90.0860833333333333345134545.22916666666667114.44-16.886.70A1Vn
+
2000503.80.08438888888888889-003011-0.503055555555555698.33-61.146.29gG9
+
3Psc33 Psc000520.10.08891666666666666-054227-5.707500000000000593.75-65.934.61K0IIIbCN-0.5
+
4Peg86 Peg000542.00.09513234613.39611111111111106.19-47.985.51G5III
+
5000616.00.1044444444444444558261258.43666666666666117.03-03.925.96G5V
+
6000619.00.10527777777777779-490430-49.075321.61-66.385.70G1IV
+
7Cas10 Cas000626.50.1073611111111111264114664.19611111111111118.061.755.59B9III
+
8000636.80.1102222222222222229011729.02138888888889111.26-32.836.13K0V
+
9000650.10.11391666666666667-230627-23.107552.21-79.146.18A7V
+
10000718.20.12172222222222222-172311-17.38638888888888874.36-75.906.19A6Vn
+
--- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/catalog.xml.bak 2015-03-30 19:51:30.901758629 -0700 @@ -0,0 +1,2 @@ + +<_test01><_test-04>T%e!s#t$
1000509.90.0860833333333333345134545.22916666666667114.44-16.886.70A1Vn

2000503.80.08438888888888889-003011-0.503055555555555698.33-61.146.29gG9

3Psc33 Psc000520.10.08891666666666666-054227-5.707500000000000593.75-65.934.61K0IIIbCN-0.5

4Peg86 Peg000542.00.09513234613.39611111111111106.19-47.985.51G5III

5000616.00.1044444444444444558261258.43666666666666117.03-03.925.96G5V

6000619.00.10527777777777779-490430-49.075321.61-66.385.70G1IV

7Cas10 Cas000626.50.1073611111111111264114664.19611111111111118.061.755.59B9III

8000636.80.1102222222222222229011729.02138888888889111.26-32.836.13K0V

9000650.10.11391666666666667-230627-23.107552.21-79.146.18A7V

10000718.20.12172222222222222-172311-17.38638888888888874.36-75.906.19A6Vn
--- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/catalog.xsd 2015-03-30 19:51:31.198796381 -0700 @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/gold/query1.out 2015-03-30 19:51:31.501834895 -0700 @@ -0,0 +1,15 @@ + +

Bright Star Catalog Extract

+ +Star Id: 7
+Constellation: Cas
+Description: 10 Cas
+RA J2000: 00:06:26.5
+DEC J2000: 64:11:46
+Visual Magnitude: 5.59
+Spectral Type: B9III
+Galactic Longitude: 118.06
+Galactic Latitude: 1.75
+
+ + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/gold/query2.out 2015-03-30 19:51:31.810874173 -0700 @@ -0,0 +1,15 @@ + +

Bright Star Catalog Extract

+ +Star Id: 3
+Constellation: Psc
+Description: 33 Psc
+RA J2000: 00:05:20.1
+DEC J2000: 05:42:27
+Visual Magnitude: 4.61
+Spectral Type: K0IIIbCN-0.5
+Galactic Longitude: 93.75
+Galactic Latitude: -65.93
+
+ + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/gold/query3.out 2015-03-30 19:51:32.085909128 -0700 @@ -0,0 +1,39 @@ + +

Bright Star Catalog Extract

+ +Star Id: 2
+Constellation: +
+Description: +
+RA J2000: 00:05:03.8
+DEC J2000: 00:30:11
+Visual Magnitude: 6.29
+Spectral Type: gG9
+Galactic Longitude: 98.33
+Galactic Latitude: -61.14
+
+Star Id: 4
+Constellation: Peg
+Description: 86 Peg
+RA J2000: 00:05:42.0
+DEC J2000: 13:23:46
+Visual Magnitude: 5.51
+Spectral Type: G5III
+Galactic Longitude: 106.19
+Galactic Latitude: -47.98
+
+Star Id: 5
+Constellation: +
+Description: +
+RA J2000: 00:06:16.0
+DEC J2000: 58:26:12
+Visual Magnitude: 5.96
+Spectral Type: G5V
+Galactic Longitude: 117.03
+Galactic Latitude: -03.92
+
+ + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/gold/query4.out 2015-03-30 19:51:32.382946880 -0700 @@ -0,0 +1,37 @@ + +

Bright Star Catalog Extract

+ +Star Id: 2
+Constellation: +
+Description: +
+RA J2000: 00:05:03.8
+DEC J2000: 00:30:11
+Visual Magnitude: 6.29
+Spectral Type: gG9
+Galactic Longitude: 98.33
+Galactic Latitude: -61.14
+
+Star Id: 3
+Constellation: Psc
+Description: 33 Psc
+RA J2000: 00:05:20.1
+DEC J2000: 05:42:27
+Visual Magnitude: 4.61
+Spectral Type: K0IIIbCN-0.5
+Galactic Longitude: 93.75
+Galactic Latitude: -65.93
+
+Star Id: 4
+Constellation: Peg
+Description: 86 Peg
+RA J2000: 00:05:42.0
+DEC J2000: 13:23:46
+Visual Magnitude: 5.51
+Spectral Type: G5III
+Galactic Longitude: 106.19
+Galactic Latitude: -47.98
+
+ + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/dec-ent.xsl 2015-03-30 19:51:32.666982980 -0700 @@ -0,0 +1,36 @@ + + + +]> + + + + + + + + + + + &toplevel; + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/dec.xsl 2015-03-30 19:51:32.982023020 -0700 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/dec_frag.xsl 2015-03-30 19:51:33.336068017 -0700 @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/html.xsl 2015-03-30 19:51:33.620104116 -0700 @@ -0,0 +1,38 @@ + + + + + + + + +

Bright Star Catalog Extract

+ + + + +
+ + + Star Id:
+ Constellation:
+ Description:
+ RA J2000: ::
+ DEC J2000: ::
+ Visual Magnitude:
+ Spectral Type:
+ Galactic Longitude:
+ Galactic Latitude:
+
+
+ + + + + + +
+ --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/ra-ent.xsl 2015-03-30 19:51:33.932143775 -0700 @@ -0,0 +1,29 @@ + +]> + + + + + + + + + &toplevel; + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/ra-uri.xsl 2015-03-30 19:51:34.231181781 -0700 @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/ra.xsl 2015-03-30 19:51:34.525219152 -0700 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/ra_frag.xsl 2015-03-30 19:51:34.830257921 -0700 @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/radec.xsl 2015-03-30 19:51:35.122295037 -0700 @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/stellartype.xsl 2015-03-30 19:51:35.430334187 -0700 @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/toptemplate.xsl 2015-03-30 19:51:35.743373973 -0700 @@ -0,0 +1,17 @@ + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/functional/test/astro/xmlfiles/xsl/toptemplateinc.xsl 2015-03-30 19:51:36.083417191 -0700 @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/AbstractFilterFactory.java 2015-03-30 19:51:36.436462061 -0700 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015, 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 test.astro; + +import static test.astro.AstroConstants.HTMLXSL; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.TransformerHandler; + +import org.xml.sax.SAXException; + +public abstract class AbstractFilterFactory implements FilterFactory { + @Override + public TransformerHandler newRAFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + TransformerHandler retval = getTransformerHandler(getRAXsl()); + Transformer xformer = retval.getTransformer(); + xformer.setParameter("ra_min_hr", String.valueOf(min)); + xformer.setParameter("ra_max_hr", String.valueOf(max)); + return retval; + } + + @Override + public TransformerHandler newDECFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + TransformerHandler retval = getTransformerHandler(getDECXsl()); + Transformer xformer = retval.getTransformer(); + xformer.setParameter("dec_min_deg", String.valueOf(min)); + xformer.setParameter("dec_max_deg", String.valueOf(max)); + return retval; + } + + @Override + public TransformerHandler newRADECFilter(double rmin, double rmax, double dmin, double dmax) throws TransformerConfigurationException, SAXException, + ParserConfigurationException, IOException { + TransformerHandler retval = getTransformerHandler(getRADECXsl()); + Transformer xformer = retval.getTransformer(); + xformer.setParameter("ra_min_hr", String.valueOf(rmin)); + xformer.setParameter("ra_max_hr", String.valueOf(rmax)); + xformer.setParameter("dec_min_deg", String.valueOf(dmin)); + xformer.setParameter("dec_max_deg", String.valueOf(dmax)); + return retval; + } + + @Override + public TransformerHandler newStellarTypeFilter(String type) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + TransformerHandler retval = getTransformerHandler(getStellarXsl()); + Transformer xformer = retval.getTransformer(); + xformer.setParameter("type", type); + return retval; + } + + @Override + public TransformerHandler newHTMLOutput() throws TransformerConfigurationException, SAXException, ParserConfigurationException, IOException { + return getTransformerHandler(HTMLXSL); + } + + abstract protected TransformerHandler getTransformerHandler(String xslFileName) throws SAXException, ParserConfigurationException, + TransformerConfigurationException, IOException; + + abstract protected String getRAXsl(); + + abstract protected String getDECXsl(); + + abstract protected String getRADECXsl(); + + abstract protected String getStellarXsl(); +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/AstroConstants.java 2015-03-30 19:51:36.850514685 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static java.io.File.separator; +import static jaxp.library.JAXPTestUtilities.getPathByClassName; + +public class AstroConstants { + // Query parameters : + + public static final double RA_MIN = 0.0; // hours + public static final double RA_MAX = 24.0; // hours + public static final double DEC_MIN = -90.000; // degrees + public static final double DEC_MAX = 90.000; // degrees + + // Stylesheet source paths: + + public static final String XSLPATH = getPathByClassName(AstroConstants.class, "xmlfiles" + separator + "xsl"); + public static final String RAXSL = XSLPATH + "ra.xsl"; + public static final String DECXSL = XSLPATH + "dec.xsl"; + public static final String RADECXSL = XSLPATH + "radec.xsl"; + public static final String STYPEXSL = XSLPATH + "stellartype.xsl"; + public static final String HTMLXSL = XSLPATH + "html.xsl"; + + public static final String RAENTXSL = XSLPATH + "ra-ent.xsl"; + public static final String DECENTXSL = XSLPATH + "dec-ent.xsl"; + public static final String RAURIXSL = XSLPATH + "ra-uri.xsl"; + public static final String TOPTEMPLXSL = XSLPATH + "toptemplate.xsl"; + public static final String TOPTEMPLINCXSL = XSLPATH + "toptemplateinc.xsl"; + + // Catalog references + + public static final String ASTROCAT = getPathByClassName(AstroConstants.class, "xmlfiles") + "catalog.xml"; + + + public static final String GOLDEN_DIR = getPathByClassName(AstroConstants.class, "xmlfiles" + separator + "gold"); + public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/AstroProcessor.java 2015-03-30 19:51:37.289570487 -0700 @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import static test.astro.AstroConstants.DEC_MAX; +import static test.astro.AstroConstants.DEC_MIN; +import static test.astro.AstroConstants.JAXP_SCHEMA_LANGUAGE; +import static test.astro.AstroConstants.JAXP_SCHEMA_SOURCE; +import static test.astro.AstroConstants.RA_MAX; +import static test.astro.AstroConstants.RA_MIN; + +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.SAXResult; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; + +/* + * AstroProcessor is to carry out the user's query with filters and produce a table of + * star records that match the criterion, and finally output with HTML format. + */ +public class AstroProcessor { + private String catalogFileName; + + private FilterFactory ffact; + private InputSourceFactory isfact; + + private SAXParserFactory spf; + + /* + * Constructor for the Main astro class. + * + * @param fFactClass the class of the FilterFactory implementation + * + * @param catalogfilename the name of the XML input document (database) + * + * @param isFactClass the class of the Input Source Factory implementation + */ + public AstroProcessor(Class fFactClass, String catalogFileName, Class isFactClass) throws Exception { + // create the Filter Factory instance... + + ffact = fFactClass.newInstance(); + + // create the Input Source Instance + + isfact = isFactClass.newInstance(); + + spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setValidating(true); + + // All XML Readers are required to recognize these two: + spf.setFeature("http://xml.org/sax/features/namespaces", true); + spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true); + + // Other features... + spf.setFeature("http://xml.org/sax/features/validation", true); + spf.setFeature("http://apache.org/xml/features/validation/schema", true); + spf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); + + this.catalogFileName = catalogFileName; + } + + /* + * Sets the star stellar type query. + * + * @param arg stellar type string, can be a substring. + */ + public TransformerHandler getStellarTypeFilter(String arg) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + String stellarType = null; + if (arg != null && arg.length() != 0) { + stellarType = arg; // set value of query + } else { + throw new IllegalArgumentException("\n Stellar type string of length zero found."); + } + + return ffact.newStellarTypeFilter(stellarType); + } + + /* + * Sets the right ascension parameters for a query. Parameters are validated + * to be in the range of 0h and 24h inclusive. + * + * @param min minimum right ascension in hours. + * + * @param max maximum right ascension in hours. + */ + public TransformerHandler getRAFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + double raMin = RA_MIN; // hours + double raMax = RA_MAX; // hours + if (min < max) { + if ((min >= RA_MIN && min <= RA_MAX) && (max >= RA_MIN && max <= RA_MAX)) { + raMin = min; // set value of query + raMax = max; // set value of query + + } + } else { + throw new IllegalArgumentException("min must be less than max.\n" + "min=" + min + ", max=" + max); + } + + return ffact.newRAFilter(raMin, raMax); + } + + /* + * Sets the right ascension and dec parameters for a query. Parameters are + * validated to be in the range of ra 0h and 24h and dec -90 to +90 + * inclusive. + * + * @param rmin minimum right ascension in hours. + * + * @param rmax maximum right ascension in hours. + * + * @param dmin minimum declination in degs. + * + * @param dmax maximum declination in degs. + */ + public TransformerHandler getRADECFilter(double rmin, double rmax, double dmin, double dmax) throws TransformerConfigurationException, SAXException, + ParserConfigurationException, IOException { + double raMin = RA_MIN; // hours + double raMax = RA_MAX; // hours + double decMin = DEC_MIN; // degrees + double decMax = DEC_MAX; // degrees + if (rmin < rmax && dmin < dmax) { + if ((rmin >= RA_MIN && rmin <= RA_MAX) && (rmax >= RA_MIN && rmax <= RA_MAX)) { + raMin = rmin; // set value of query + raMax = rmax; // set value of query + } + if ((dmin >= DEC_MIN && dmin <= DEC_MAX) && (dmax >= DEC_MIN && dmax <= DEC_MAX)) { + decMin = dmin; // set value of query + decMax = dmax; // set value of query + } + + } else { + throw new IllegalArgumentException("min must be less than max.\n" + "rmin=" + rmin + ", rmax=" + rmax + ", dmin=" + dmin + ", dmax=" + dmax); + } + + return ffact.newRADECFilter(raMin, raMax, decMin, decMax); + } + + /* + * Sets the declination parameters for a query. Parameters are validated to + * be in the range of -90 and +90 degrees inclusive. + * + * @param min minimum declination in degrees. + * + * @param max maximum declination in degrees. + */ + public TransformerHandler getDecFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, + IOException { + double decMin = DEC_MIN; // degrees + double decMax = DEC_MAX; // degrees + if (min < max) { + if ((min >= DEC_MIN && min <= DEC_MAX) && (max >= DEC_MIN && max <= DEC_MAX)) { + decMin = min; // set value of query + decMax = max; // set value of query + } + } else { + throw new IllegalArgumentException("min must be less than max.\n" + "min=" + min + ", max=" + max); + } + + return ffact.newDECFilter(decMin, decMax); + } + + /* + * Runs the filter process against the astronomical database. + * + * @throws Exception + */ + public void process(String outputfile, TransformerHandler... filters) throws Exception { + XMLReader catparser = getXMLReader(); + + File catalogfile = new File(catalogFileName); + InputSource catsrc = isfact.newInputSource(catalogfile.getPath()); + + TransformerHandler outfilter = ffact.newHTMLOutput(); + // create an array from the Vector of filters... + + // hook the filters up to each other, there may be zero filters + int nfilters = filters.length; + if (nfilters != 0) { + TransformerHandler prev = null; + for (int i = 0; i < filters.length; i++) { + TransformerHandler curr = filters[i]; + if (prev != null) { + prev.setResult(new SAXResult(curr)); + } + prev = curr; + } + // hook up the last filter to the output filter + prev.setResult(new SAXResult(outfilter)); + // hook up the catalog parser to the first filter... + catparser.setContentHandler(filters[0]); + } else { + // There are no query filters, + // hook up the catalog parser directly to output filter... + catparser.setContentHandler(outfilter); + } + // hook up the output filter to the output file or std out + if (outputfile != null) { + outfilter.setResult(new StreamResult(outputfile)); + } else { + outfilter.setResult(new StreamResult(System.out)); + } + + catparser.parse(catsrc); + } + + private XMLReader getXMLReader() throws Exception { + SAXParser parser = spf.newSAXParser(); + parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + parser.setProperty(JAXP_SCHEMA_SOURCE, "catalog.xsd"); + XMLReader catparser = parser.getXMLReader(); + catparser.setErrorHandler(new CatalogErrorHandler()); + return catparser; + } + + /* + * Error Handler for the parsing of the XML astronomical catalog. + */ + private static class CatalogErrorHandler implements ErrorHandler { + private String getParseExceptionInfo(SAXParseException spe) { + String systemId = spe.getSystemId(); + if (systemId == null) { + systemId = "null"; + } + String info = "Catalog URI=" + systemId + " Line=" + spe.getLineNumber() + ": " + spe.getMessage(); + return info; + } + + public void warning(SAXParseException spe) throws SAXException { + String message = "Warning: " + getParseExceptionInfo(spe); + throw new SAXException(message); + } + + public void error(SAXParseException spe) throws SAXException { + String message = "Error: " + getParseExceptionInfo(spe); + throw new SAXException(message); + } + + public void fatalError(SAXParseException spe) throws SAXException { + String message = "Fatal Error: " + getParseExceptionInfo(spe); + throw new SAXException(message); + } + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/DOMFilterFactoryImpl.java 2015-03-30 19:51:37.664618153 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static test.astro.AstroConstants.DECXSL; +import static test.astro.AstroConstants.RAXSL; +import static test.astro.AstroConstants.STYPEXSL; + +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +/* + * Implementation of the filter factory interface that utilizes DOM + * sources rather than Stream or SAX sources. This factory utilizes a + * DocumentBuilder to read in the stylesheets and create the DOM used + * to create the filters for the query pipeline. + * + */ +public class DOMFilterFactoryImpl extends SourceFilterFactory { + @Override + protected Source getSource(String xslFileName) throws SAXException, ParserConfigurationException, IOException { + Document document = getStylesheetDOM(xslFileName); + return new DOMSource(document); + } + + + @Override + protected String getRAXsl() { + return RAXSL; + } + + @Override + protected String getDECXsl() { + return DECXSL; + } + + @Override + protected String getRADECXsl() { + return DECXSL; + } + + @Override + protected String getStellarXsl() { + return STYPEXSL; + } + + private Document getStylesheetDOM(String xslfilename) throws SAXException, IOException, ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + return dbf.newDocumentBuilder().parse(filenameToURL(xslfilename)); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/DOML3InputSourceFactoryImpl.java 2015-03-30 19:51:38.121676243 -0700 @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.USER_DIR; +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static org.w3c.dom.ls.DOMImplementationLS.MODE_SYNCHRONOUS; +import static org.w3c.dom.traversal.NodeFilter.SHOW_ELEMENT; + +import java.io.ByteArrayInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.file.Files; +import java.nio.file.Paths; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.DOMConfiguration; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSParser; +import org.w3c.dom.ls.LSParserFilter; +import org.w3c.dom.ls.LSSerializer; +import org.w3c.dom.ls.LSSerializerFilter; +import org.xml.sax.InputSource; + +/* + * A specialized implementation of an Input Source factory that utilizes + * DOM Level 3 implementations to build a Document (DOM) from the + * astro input file (XML) and then will serialize the DOM. The serialized DOM + * of the astro input file is then used to create the sax InputSource + * and set it's system id. It is then returned to the caller. + * + */ +public class DOML3InputSourceFactoryImpl implements InputSourceFactory { + public InputSource newInputSource(String filename) throws Exception { + // Create DOMImplementationLS, and DOM L3 LSParser + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + DocumentBuilder bldr = fact.newDocumentBuilder(); + DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation(); + LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null); + domparser.setFilter(new MyDOMBuilderFilter()); + + // Parse the xml document to create the DOM Document using + // the DOM L3 LSParser and a LSInput (formerly LSInputSource) + Document doc = null; + LSInput src = impl.createLSInput(); + // register the input file with the input source... + String systemId = filenameToURL(filename); + src.setSystemId(systemId); + try (Reader reader = new FileReader(filename)) { + src.setCharacterStream(reader); + src.setEncoding("UTF-8"); + doc = domparser.parse(src); + } + + // Use DOM L3 LSSerializer (previously called a DOMWriter) + // to serialize the xml doc DOM to a file stream. + String tmpCatalog = Files.createTempFile(Paths.get(USER_DIR + "/astro"), "catalog.xml", null).toString(); + + LSSerializer domserializer = impl.createLSSerializer(); + domserializer.setFilter(new MyDOMWriterFilter()); + domserializer.getNewLine(); + DOMConfiguration config = domserializer.getDomConfig(); + config.setParameter("xml-declaration", Boolean.TRUE); + String result = domserializer.writeToString(doc); + try (FileWriter os = new FileWriter(tmpCatalog, false)) { + os.write(result); + os.flush(); + } + + // Return the Input Source created from the Serialized DOM L3 Document. + InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog))))); + catsrc.setSystemId(systemId); + return catsrc; + } + + /* + * Implementation of a DOM L3 DOM Builder Filter. The filter is capable of + * examining nodes as they are available during the parse. This + * implementation both rejects (filters) and modifies particular nodes + * during the parse of the document. As such, the document in memory will + * become a subset of the document on the stream in accordance with the DOM + * Level 3 Load and Save Specification, v1.0, sect. 1.3 Load Interfaces. + */ + private static class MyDOMBuilderFilter implements LSParserFilter { + + /* + * Filter the DOM. Define element(s) and their children that should be + * efficiently skipped thereby filtering them out of the stream. + */ + @Override + public short startElement(Element e) { + return "_test01".equals(e.getTagName()) ? FILTER_REJECT : FILTER_ACCEPT; + } + + /* + * Modify the DOM 'in situ'. Find a particular Node and change the Node + * value of its child, allow other nodes to pass through unchanged. + */ + @Override + public short acceptNode(Node n) { + String localname = n.getLocalName(); + if (localname.equals("_test-04")) { + Node child = n.getFirstChild(); + String text = child.getNodeValue(); + if (text.equals("T%e!s#t$")) { + child.setNodeValue("T%E!S#T$"); + } + } + return FILTER_ACCEPT; + } + + /* + * Tells the DOMBuilder what types of nodes to show to the filter. + */ + @Override + public int getWhatToShow() { + return SHOW_ELEMENT; + } + } + + /* + * Implementation of a DOM Serializer Filter (previously called a DOM Writer + * Filter) which is a specialization of the NodeFilter interface. + */ + private static class MyDOMWriterFilter implements LSSerializerFilter { + public MyDOMWriterFilter() { + } + + /* + * Must implement method from NodeFilter interface + */ + @Override + public short acceptNode(Node node) { + return FILTER_ACCEPT; + } + + /* + * Tells the DOMBuilder what types of nodes to show to the filter. + */ + @Override + public int getWhatToShow() { + return SHOW_ELEMENT; + } + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/FilterFactory.java 2015-03-30 19:51:38.406712470 -0700 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.TransformerConfigurationException; + +import org.xml.sax.SAXException; + +/* + * Defines the interface for all concrete implementations of a Filter + * Factory. + */ +public interface FilterFactory { + /* + * Allows only the stars between right ascension (R.A.) of min and max to + * pass. Filters out all stars that are not in that range of right + * ascension. Units of right ascension are hours (h), range of parameters is + * 0h to 24h. + * + * @param min minimum R.A. + * + * @param max maxmimum R.A. + */ + TransformerHandler newRAFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, IOException; + + /* + * Allows only the stars between declination (DEC) of min and max to pass. + * Filters out all stars that are not in that range of declination. Units of + * declination are degrees (degs), range of parameters is -90 and +90 degs. + * + * @param min minimum DEC + * + * @param max maxmimum DEC + */ + TransformerHandler newDECFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException, IOException; + + /* + * Combines the usage of newRAFilter and newDECFilter into one. + * + * @param rmin minimum R.A. + * + * @param rmax maxmimum R.A. + * + * @param dmin minimum DEC + * + * @param dmax maxmimum DEC + */ + TransformerHandler newRADECFilter(double rmin, double rmax, double dmin, double dmax) throws TransformerConfigurationException, SAXException, + ParserConfigurationException, IOException; + + TransformerHandler newStellarTypeFilter(String type) throws TransformerConfigurationException, SAXException, ParserConfigurationException, IOException; + + TransformerHandler newHTMLOutput() throws TransformerConfigurationException, SAXException, ParserConfigurationException, IOException; +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/InputSourceFactory.java 2015-03-30 19:51:38.704750349 -0700 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import org.xml.sax.InputSource; + +/* + * Interface for all input source factory objects. The default implementation + * 'InputSourceFactoryImpl' is provided as a straight forward factory + * class that creates a new sax input source from a filename. + * + */ +public interface InputSourceFactory { + /* + * Creates a new sax InputSource object from a filename. + * Also sets the system id of the input source. + * @param file filename of the XML input to create the input source. + */ + InputSource newInputSource(String file) throws Exception; +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/InputSourceFactoryImpl.java 2015-03-30 19:51:38.989786576 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.filenameToURL; + +import org.xml.sax.InputSource; + +/* + * Default implementation of a input source factory. This is the most + * straight forward way to create a sax input source and set it's + * system id. + * + */ +public class InputSourceFactoryImpl implements InputSourceFactory { + public InputSourceFactoryImpl() { + } + + public InputSource newInputSource(String filename) { + InputSource catSrc = new InputSource(filename); + catSrc.setSystemId(filenameToURL(filename)); + return catSrc; + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/SAXFilterFactoryImpl.java 2015-03-30 19:51:39.363834115 -0700 @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static test.astro.AstroConstants.DECENTXSL; +import static test.astro.AstroConstants.DECXSL; +import static test.astro.AstroConstants.RAENTXSL; +import static test.astro.AstroConstants.STYPEXSL; +import static test.astro.AstroConstants.TOPTEMPLXSL; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.sax.SAXSource; + +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/* + * Implementation of the filter factory interface that utilizes SAX + * sources rather than Stream sources. This factory utilizes a + * SAX parser factory and XMLReader to read in the stylesheets used + * to create the filters for the query pipeline. + * The XMLReader has been equipped with an entity resolver + * SAXFilterFactoryEntityResolver, it is used to resolve external + * entities in two specialized stylesheets, ra-ent.xsl (derived from + * ra.xsl) and dec-ent.xsl (derived from dec.xsl). + * + */ +public class SAXFilterFactoryImpl extends SourceFilterFactory { + private EntityResolver entityResolver; + + public SAXFilterFactoryImpl() { + super(); + entityResolver = new SAXFilterFactoryEntityResolver(); + } + + @Override + protected Source getSource(String xslFileName) throws SAXException, ParserConfigurationException { + SAXSource saxsource = new SAXSource(new InputSource(filenameToURL(xslFileName))); + saxsource.setXMLReader(getXMLReader()); + return saxsource; + } + + @Override + protected String getRAXsl() { + return RAENTXSL; + } + + @Override + protected String getDECXsl() { + return DECENTXSL; + } + + @Override + protected String getRADECXsl() { + return DECXSL; + } + + @Override + protected String getStellarXsl() { + return STYPEXSL; + } + + /* + * Entity resolver implementation that is used in the SAXFilterFactory + * implementation for handling external entities that appear in two + * specialized stylesheets, 'ra-ent.xsl' and 'dec-ent.xsl'. Both of these + * stylesheets contain an external entity reference to the top level + * stylesheet template, which is stored in a separate file, + * 'toptemplate.xsl'. + */ + private static class SAXFilterFactoryEntityResolver implements EntityResolver { + public InputSource resolveEntity(String publicid, String sysId) { + if (sysId.equals("http://astro.com/stylesheets/toptemplate")) { + InputSource retval = new InputSource(TOPTEMPLXSL); + retval.setSystemId(filenameToURL(TOPTEMPLXSL)); + return retval; + } else { + return null; // use default behavior + } + } + } + + private XMLReader getXMLReader() throws SAXException, ParserConfigurationException { + SAXParserFactory pfactory = SAXParserFactory.newInstance(); + pfactory.setNamespaceAware(true); + // pfactory.setValidating(true); + XMLReader xmlreader = pfactory.newSAXParser().getXMLReader(); + // entity resolver is used in stylesheets ra-ent.xsl, + // dec-ent.xsl. Other stylehsheets will not use it + // since they do not contain ext entities. + xmlreader.setEntityResolver(entityResolver); + return xmlreader; + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/SourceFilterFactory.java 2015-03-30 19:51:39.686875172 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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 test.astro; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; + +import org.xml.sax.SAXException; + +public abstract class SourceFilterFactory extends AbstractFilterFactory { + @Override + protected TransformerHandler getTransformerHandler(String xslFileName) throws SAXException, ParserConfigurationException, + TransformerConfigurationException, IOException { + return getFactory().newTransformerHandler(getSource(xslFileName)); + } + + abstract protected Source getSource(String xslFileName) throws SAXException, ParserConfigurationException, IOException; + + private SAXTransformerFactory getFactory() { + return (SAXTransformerFactory) TransformerFactory.newInstance(); + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/StreamFilterFactoryImpl.java 2015-03-30 19:51:39.988913559 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static test.astro.AstroConstants.DECXSL; +import static test.astro.AstroConstants.RADECXSL; +import static test.astro.AstroConstants.RAXSL; +import static test.astro.AstroConstants.STYPEXSL; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +public class StreamFilterFactoryImpl extends SourceFilterFactory { + @Override + protected Source getSource(String xslFileName) { + return new StreamSource(filenameToURL(xslFileName)); + } + + @Override + protected String getRAXsl() { + return RAXSL; + } + + @Override + protected String getDECXsl() { + return DECXSL; + } + + @Override + protected String getRADECXsl() { + return RADECXSL; + } + + @Override + protected String getStellarXsl() { + return STYPEXSL; + } +} \ No newline at end of file --- /dev/null 2015-03-31 02:29:39.396799728 -0700 +++ new/test/javax/xml/jaxp/libs/test/astro/TemplatesFilterFactoryImpl.java 2015-03-30 19:51:40.314954998 -0700 @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2002, 2015, 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 test.astro; + +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static test.astro.AstroConstants.DECXSL; +import static test.astro.AstroConstants.RAURIXSL; +import static test.astro.AstroConstants.STYPEXSL; +import static test.astro.AstroConstants.TOPTEMPLINCXSL; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TemplatesHandler; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamSource; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/* + * Implementation of the filter factory interface that utilizes + * a TemplatesHandler and creates Templates from the stylesheets. + * The Templates objects are then used to create a TransformerHandler + * a.k.a Filter which is returned to the caller. + * This factory uses a Uri resolver which is registered with the + * Transformer factory. + * + */ +public class TemplatesFilterFactoryImpl extends AbstractFilterFactory { + private final URIResolver uriResolver = new TemplatesFilterFactoryURIResolver(); + + @Override + protected String getRAXsl() { + return RAURIXSL; + } + + @Override + protected String getDECXsl() { + return DECXSL; + } + + @Override + protected String getRADECXsl() { + return DECXSL; + } + + @Override + protected String getStellarXsl() { + return STYPEXSL; + } + + @Override + protected TransformerHandler getTransformerHandler(String xslFileName) throws SAXException, ParserConfigurationException, + TransformerConfigurationException, IOException { + SAXTransformerFactory factory = (SAXTransformerFactory) TransformerFactory.newInstance(); + factory.setURIResolver(uriResolver); + + TemplatesHandler templatesHandler = factory.newTemplatesHandler(); + + SAXParserFactory pFactory = SAXParserFactory.newInstance(); + pFactory.setNamespaceAware(true); + + XMLReader xmlreader = pFactory.newSAXParser().getXMLReader(); + + // create the stylesheet input source + InputSource xslSrc = new InputSource(xslFileName); + + xslSrc.setSystemId(filenameToURL(xslFileName)); + // hook up the templates handler as the xsl content handler + xmlreader.setContentHandler(templatesHandler); + // call parse on the xsl input source + + xmlreader.parse(xslSrc); + + // extract the Templates object created from the xsl input source + return factory.newTransformerHandler(templatesHandler.getTemplates()); + } + + /* + * Uri resolver used to resolve stylesheet used by the Templates filter + * factory. + */ + private static class TemplatesFilterFactoryURIResolver implements URIResolver { + public Source resolve(String href, String base) throws TransformerException { + if ("http://astro.com/stylesheets/topleveltemplate".equals(href)) { + StreamSource ss = new StreamSource(TOPTEMPLINCXSL); + ss.setSystemId(filenameToURL(TOPTEMPLINCXSL)); + return ss; + } else { + return null; + } + } + } +} \ No newline at end of file