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=238249dbbd8d49086b38c1696cb6d0cb685909fe;hp=bb6c35130ef81bd87b3b190914bb105404b3237a;hb=b925756421ea8565637d8575d8143dbf46db5a86;hpb=81387f0ae5898b196a54493f9bf4305993f39d1c 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 bb6c35130e..238249dbbd 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 @@ -41,7 +41,8 @@ import org.xml.sax.SAXException; import com.google.common.base.Charsets; -public class XmlUtil { +public final class XmlUtil { + public static final String XMLNS_ATTRIBUTE_KEY = "xmlns"; private static final DocumentBuilderFactory BUILDERFACTORY; @@ -54,6 +55,8 @@ public class XmlUtil { BUILDERFACTORY = factory; } + private XmlUtil() {} + public static Element readXmlToElement(String xmlContent) throws SAXException, IOException { Document doc = readXmlToDocument(xmlContent); return doc.getDocumentElement(); @@ -68,6 +71,9 @@ public class XmlUtil { return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8))); } + // TODO improve exceptions throwing + // along with XmlElement + public static Document readXmlToDocument(InputStream xmlContent) throws SAXException, IOException { DocumentBuilder dBuilder; try { @@ -133,14 +139,13 @@ public class XmlUtil { try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, addXmlDeclaration == true ? "no" : "yes"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, addXmlDeclaration ? "no" : "yes"); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(xml); transformer.transform(source, result); - String xmlString = result.getWriter().toString(); - return xmlString; + return result.getWriter().toString(); } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) { throw new RuntimeException("Unable to serialize xml element " + xml, e); }