+ /**
+ * A supporting method to extract the data and configuration element from the NETCONF-XML response
+ * from the node and create well formatted xml.
+ *
+ * @param requestData The unformatted NETCONF-XML
+ * @return responseBuilder the extracted data
+ * @throws APPCException Exception during parsing xml data
+ */
+ private String extractFromNetconfXml(String requestData) throws APPCException {
+ log.debug("extractFromNetconfXml -- Start");
+ StringBuilder responseBuilder = new StringBuilder();
+ StringWriter stringBuffer = new StringWriter();
+ try {
+ requestData = requestData.replaceAll("]]>]]>", "");
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = documentBuilder.parse(new InputSource(new StringReader(requestData)));
+ document.getDocumentElement().normalize();
+ XPath xPath = XPathFactory.newInstance().newXPath();
+ Node dataNode = (Node) xPath.evaluate("//data", document, XPathConstants.NODE);
+ Transformer xform = TransformerFactory.newInstance().newTransformer();
+ xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ xform.setOutputProperty(OutputKeys.INDENT, "yes");
+ xform.transform(new DOMSource(dataNode), new StreamResult(stringBuffer));
+ responseBuilder.append(stringBuffer.toString());
+ if (log.isTraceEnabled()) {
+ log.trace("ConfigComponentAdaptor:extractFromNetconfXml after Extract: "
+ + responseBuilder.toString());
+ }
+ } catch (SAXException | IOException | ParserConfigurationException | TransformerException
+ | XPathExpressionException exception) {
+ throw new APPCException("Error Occured during parsing Netconf-XML", exception);
+
+ }
+ log.debug("extractFromNetconfXml -- End");
+ return responseBuilder.toString();
+ }
+
+ private String trimResponse(String response) throws APPCException {
+ response = extractFromNetconfXml(response);
+ log.debug("runningConfig before trimResponse : " + response);