1 /* 2 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package test.astro; 24 25 import static jaxp.library.JAXPTestUtilities.filenameToURL; 26 import static test.astro.AstroConstants.DECXSL; 27 import static test.astro.AstroConstants.RAXSL; 28 import static test.astro.AstroConstants.STYPEXSL; 29 30 import java.io.IOException; 31 32 import javax.xml.parsers.DocumentBuilderFactory; 33 import javax.xml.parsers.ParserConfigurationException; 34 import javax.xml.transform.Source; 35 import javax.xml.transform.dom.DOMSource; 36 37 import org.w3c.dom.Document; 38 import org.xml.sax.SAXException; 39 40 /* 41 * Implementation of the filter factory interface that utilizes DOM 42 * sources rather than Stream or SAX sources. This factory utilizes a 43 * DocumentBuilder to read in the stylesheets and create the DOM used 44 * to create the filters for the query pipeline. 45 * 46 */ 47 public class DOMFilterFactoryImpl extends SourceFilterFactory { 48 @Override 49 protected Source getSource(String xslFileName) throws SAXException, ParserConfigurationException, IOException { 50 Document document = getStylesheetDOM(xslFileName); 51 return new DOMSource(document); 52 } 53 54 55 @Override 56 protected String getRAXsl() { 57 return RAXSL; 58 } 59 60 @Override 61 protected String getDECXsl() { 62 return DECXSL; 63 } 64 65 @Override 66 protected String getRADECXsl() { 67 return DECXSL; 68 } 69 70 @Override 71 protected String getStellarXsl() { 72 return STYPEXSL; 73 } 74 75 private Document getStylesheetDOM(String xslfilename) throws SAXException, IOException, ParserConfigurationException { 76 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 77 dbf.setNamespaceAware(true); 78 return dbf.newDocumentBuilder().parse(filenameToURL(xslfilename)); 79 } 80 }