summaryrefslogtreecommitdiffstats
path: root/restconf-client/provider/src/main
diff options
context:
space:
mode:
authorjanani b <janani.b@huawei.com>2018-10-08 16:13:36 +0530
committerjanani b <janani.b@huawei.com>2018-10-08 16:33:50 +0530
commitda54fc49d3f16d7028a42cd90ad1500973814790 (patch)
tree1a4e3a7c444d5e75cba8bdff5c36d1ad86b3eee0 /restconf-client/provider/src/main
parent769622040a1fa819d2708c50d4904ac24b867a38 (diff)
Appending dummy root node to XML data format
To hold all the children in XML message a dummy root node is added Issue-ID: CCSDK-324 Change-Id: I7cf0266d15e6bfaa2b9207e77d8bd5372a164b4f Signed-off-by: janani b <janani.b@huawei.com>
Diffstat (limited to 'restconf-client/provider/src/main')
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerUtil.java7
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java12
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java18
3 files changed, 24 insertions, 13 deletions
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerUtil.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerUtil.java
index 598b08c1b..fbebd2b2d 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerUtil.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DfSerializerUtil.java
@@ -210,11 +210,10 @@ public final class DfSerializerUtil {
* @return base type definition
*/
static TypeDefinition<?> resolveBaseTypeFrom(TypeDefinition<?> type) {
- TypeDefinition superType;
- for(superType = type; superType.getBaseType() != null;
- superType = superType.getBaseType()) {
+ TypeDefinition superType = type;
+ while (superType.getBaseType() != null) {
+ superType = superType.getBaseType();
}
return superType;
}
-
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java
index 39a08e387..f098195e4 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeXmlListener.java
@@ -78,11 +78,13 @@ public class PropertiesNodeXmlListener implements PropertiesNodeListener {
@Override
public void start(PropertiesNode node) {
- //Do Nothing.
+ rootElement = addElement(null, node);
+ elementStack.push(rootElement);
}
@Override
public void end(PropertiesNode node) throws SvcLogicException {
+ xmlData = rootElement.asXML();
xmlData = UTF_HEADER + xmlData;
writer = getXmlWriter(xmlData, "4");
}
@@ -113,9 +115,6 @@ public class PropertiesNodeXmlListener implements PropertiesNodeListener {
NODE_TYPE_ERR, node.nodeType().toString()));
}
if (element != null) {
- if (elementStack.isEmpty()) {
- rootElement = element;
- }
elementStack.push(element);
}
}
@@ -133,10 +132,7 @@ public class PropertiesNodeXmlListener implements PropertiesNodeListener {
case MULTI_INSTANCE_NODE:
case MULTI_INSTANCE_LEAF_NODE:
case SINGLE_INSTANCE_LEAF_NODE:
- if (!elementStack.isEmpty() &&
- elementStack.peek().equals(rootElement)) {
- xmlData = rootElement.asXML();
- } else {
+ if (!elementStack.isEmpty()) {
elementStack.pop();
}
break;
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java
index 6eeb4b82c..f3c6723e1 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/XmlSerializer.java
@@ -61,7 +61,7 @@ public class XmlSerializer extends DataFormatSerializer {
PropertiesNodeXmlListener xmlListener = new PropertiesNodeXmlListener();
nodeWalker.walk(xmlListener, propNode);
Writer writer = xmlListener.getWriter();
- return writer.toString();
+ return removeRootNode(writer.toString(), propNode.name());
}
@Override
@@ -85,4 +85,20 @@ public class XmlSerializer extends DataFormatSerializer {
return serializerContext().getPropNodeSerializer().decode(
listener.serializerHelper().getPropertiesNode());
}
+
+ /**
+ * Removes root node from the XML data format message and makes the
+ * string to be pretty print.
+ *
+ * @param xml XML data format message
+ * @param rootName root node name
+ * @return pretty print format XML message
+ */
+ private static String removeRootNode(String xml, String rootName) {
+ xml = xml.replace("\n<" + rootName + ">", "\n");
+ xml = xml.replace("</" + rootName + ">" + "\n", "");
+ xml = xml.replaceAll("\n" + " ", "\n");
+ xml = xml.replaceFirst("\n", "");
+ return xml;
+ }
} \ No newline at end of file