| /* |
| * Portions Copyright 2006 Sun Microsystems, Inc. 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. Sun designates this |
| * particular file as subject to the "Classpath" exception as provided |
| * by Sun in the LICENSE file that accompanied this code. |
| * |
| * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| * CA 95054 USA or visit www.sun.com if you need additional information or |
| * have any questions. |
| */ |
| |
| package com.sun.xml.internal.ws.util; |
| |
| import com.sun.xml.internal.ws.util.xml.XmlUtil; |
| import org.w3c.dom.Document; |
| import org.w3c.dom.Node; |
| import org.xml.sax.SAXException; |
| |
| import javax.xml.parsers.DocumentBuilder; |
| import javax.xml.parsers.DocumentBuilderFactory; |
| import javax.xml.parsers.FactoryConfigurationError; |
| import javax.xml.parsers.ParserConfigurationException; |
| import javax.xml.transform.Source; |
| import javax.xml.transform.Transformer; |
| import javax.xml.transform.dom.DOMResult; |
| import java.io.InputStream; |
| import java.io.IOException; |
| |
| /** |
| * $author: JAXWS Development Team |
| */ |
| public class DOMUtil { |
| |
| private static DocumentBuilder db; |
| |
| /** |
| * Creates a new DOM document. |
| */ |
| public static Document createDom() { |
| synchronized (DOMUtil.class) { |
| if (db == null) { |
| try { |
| DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| dbf.setNamespaceAware(true); |
| db = dbf.newDocumentBuilder(); |
| } catch (ParserConfigurationException e) { |
| throw new FactoryConfigurationError(e); |
| } |
| } |
| return db.newDocument(); |
| } |
| } |
| |
| public static Node createDOMNode(InputStream inputStream) { |
| |
| DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| dbf.setNamespaceAware(true); |
| dbf.setValidating(false); |
| try { |
| DocumentBuilder builder = dbf.newDocumentBuilder(); |
| try { |
| return builder.parse(inputStream); |
| } catch (SAXException e) { |
| e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| } catch (IOException e) { |
| e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| } |
| } catch (ParserConfigurationException pce) { |
| IllegalArgumentException iae = new IllegalArgumentException(pce.getMessage()); |
| iae.initCause(pce); |
| throw iae; |
| } |
| return null; |
| } |
| } |