1 /* 2 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 3 * 4 * This software is open source. 5 * See the bottom of this file for the licence. 6 * 7 * $Id: JAXPHelper.java,v 1.5 2004/06/25 08:03:37 maartenc Exp $ 8 */ 9 10 package org.dom4j.io; 11 12 import javax.xml.parsers.DocumentBuilder; 13 import javax.xml.parsers.DocumentBuilderFactory; 14 import javax.xml.parsers.SAXParser; 15 import javax.xml.parsers.SAXParserFactory; 16 17 import org.xml.sax.XMLReader; 18 19 /*** <code>JAXPHelper</code> contains some helper methods for working with 20 * JAXP. These methods are kept in a seperate class to avoid class loading 21 * issues, such that dom4j can work without JAXP on the CLASSPATH 22 * 23 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 24 * @version $Revision: 1.5 $ 25 */ 26 class JAXPHelper { 27 28 /*** This method attempts to use JAXP to locate the 29 * SAX2 XMLReader implementation. 30 * This method uses reflection to avoid being dependent directly 31 * on the JAXP classes. 32 */ 33 public static XMLReader createXMLReader(boolean validating, boolean namespaceAware) throws Exception { 34 SAXParserFactory factory = SAXParserFactory.newInstance(); 35 factory.setValidating( validating ); 36 factory.setNamespaceAware( namespaceAware ); 37 SAXParser parser = factory.newSAXParser(); 38 return parser.getXMLReader(); 39 } 40 41 public static org.w3c.dom.Document createDocument(boolean validating, boolean namespaceAware) throws Exception { 42 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 43 factory.setValidating( validating ); 44 factory.setNamespaceAware( namespaceAware ); 45 DocumentBuilder builder = factory.newDocumentBuilder(); 46 return builder.newDocument(); 47 } 48 } 49 50 51 52 53 /* 54 * Redistribution and use of this software and associated documentation 55 * ("Software"), with or without modification, are permitted provided 56 * that the following conditions are met: 57 * 58 * 1. Redistributions of source code must retain copyright 59 * statements and notices. Redistributions must also contain a 60 * copy of this document. 61 * 62 * 2. Redistributions in binary form must reproduce the 63 * above copyright notice, this list of conditions and the 64 * following disclaimer in the documentation and/or other 65 * materials provided with the distribution. 66 * 67 * 3. The name "DOM4J" must not be used to endorse or promote 68 * products derived from this Software without prior written 69 * permission of MetaStuff, Ltd. For written permission, 70 * please contact dom4j-info@metastuff.com. 71 * 72 * 4. Products derived from this Software may not be called "DOM4J" 73 * nor may "DOM4J" appear in their names without prior written 74 * permission of MetaStuff, Ltd. DOM4J is a registered 75 * trademark of MetaStuff, Ltd. 76 * 77 * 5. Due credit should be given to the DOM4J Project - 78 * http://www.dom4j.org 79 * 80 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 81 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 82 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 83 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 84 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 85 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 86 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 87 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 89 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 90 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 91 * OF THE POSSIBILITY OF SUCH DAMAGE. 92 * 93 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 94 * 95 * $Id: JAXPHelper.java,v 1.5 2004/06/25 08:03:37 maartenc Exp $ 96 */