X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fxml%2FXmlUtil.java;fp=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fxml%2FXmlUtil.java;h=bb6c35130ef81bd87b3b190914bb105404b3237a;hp=137e215a31eb13423b6438671faed529a2fc7ce3;hb=5e035029b351317b24cf2dfb45504bf5a830d2d1;hpb=eac080120972a30ae37566fec20521286e87ef18 diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlUtil.java index 137e215a31..bb6c35130e 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlUtil.java @@ -42,8 +42,17 @@ import org.xml.sax.SAXException; import com.google.common.base.Charsets; public class XmlUtil { - public static final String XMLNS_ATTRIBUTE_KEY = "xmlns"; + private static final DocumentBuilderFactory BUILDERFACTORY; + + static { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setCoalescing(true); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + BUILDERFACTORY = factory; + } public static Element readXmlToElement(String xmlContent) throws SAXException, IOException { Document doc = readXmlToDocument(xmlContent); @@ -60,12 +69,11 @@ public class XmlUtil { } public static Document readXmlToDocument(InputStream xmlContent) throws SAXException, IOException { - DocumentBuilderFactory factory = getDocumentBuilderFactory(); DocumentBuilder dBuilder; try { - dBuilder = factory.newDocumentBuilder(); + dBuilder = BUILDERFACTORY.newDocumentBuilder(); } catch (ParserConfigurationException e) { - throw new RuntimeException(e); + throw new RuntimeException("Failed to parse XML document", e); } Document doc = dBuilder.parse(xmlContent); @@ -77,23 +85,13 @@ public class XmlUtil { return readXmlToDocument(new FileInputStream(xmlFile)).getDocumentElement(); } - private static final DocumentBuilderFactory getDocumentBuilderFactory() { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setCoalescing(true); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - return factory; - } - public static Document newDocument() { - DocumentBuilderFactory factory = getDocumentBuilderFactory(); try { - DocumentBuilder builder = factory.newDocumentBuilder(); + DocumentBuilder builder = BUILDERFACTORY.newDocumentBuilder(); Document document = builder.newDocument(); return document; } catch (ParserConfigurationException e) { - throw new RuntimeException(e); + throw new RuntimeException("Failed to create document", e); } }