Fix warnings in netconf-api and netconf-util
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / xml / XmlUtil.java
index bb6c35130ef81bd87b3b190914bb105404b3237a..238249dbbd8d49086b38c1696cb6d0cb685909fe 100644 (file)
@@ -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);
         }