X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fxml%2FXmlElement.java;h=212214cd2ab516e8f7c8e1226b63bb16d886e927;hb=371bb07d5c970798f247170130c93147890708e8;hp=7cb0bb02859afd89418db41a69c60993671deeeb;hpb=4f623c74a703a31e787387b536981dcb344ca4f9;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java index 7cb0bb0285..212214cd2a 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlElement.java @@ -103,6 +103,9 @@ public class XmlElement { } public String getName() { + if (element.getLocalName()!=null && !element.getLocalName().equals("")){ + return element.getLocalName(); + } return element.getTagName(); } @@ -114,6 +117,10 @@ public class XmlElement { return element.getAttributeNS(namespace, attributeName); } + public NodeList getElementsByTagName(String name) { + return element.getElementsByTagName(name); + } + public void appendChild(Element element) { this.element.appendChild(element); // Element newElement = (Element) element.cloneNode(true); @@ -273,8 +280,8 @@ public class XmlElement { public String getNamespaceAttribute() { String attribute = element.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY); - Preconditions.checkState(attribute != null && !attribute.equals(""), "Element %s must specify a %s attribute", - toString(), XmlUtil.XMLNS_ATTRIBUTE_KEY); + Preconditions.checkState(attribute != null && !attribute.equals(""), "Element %s must specify namespace", + toString()); return attribute; } @@ -319,7 +326,7 @@ public class XmlElement { prefix = ""; } if (namespaces.containsKey(prefix) == false) { - throw new IllegalArgumentException("Cannot find namespace for " + element + ". Prefix from content is " + throw new IllegalArgumentException("Cannot find namespace for " + XmlUtil.toString(element) + ". Prefix from content is " + prefix + ". Found namespaces " + namespaces); } return Maps.immutableEntry(prefix, namespaces.get(prefix)); @@ -369,6 +376,20 @@ public class XmlElement { return element.hashCode(); } + public boolean hasNamespace() { + try { + getNamespaceAttribute(); + } catch (IllegalStateException e) { + try { + getNamespace(); + } catch (IllegalStateException e1) { + return false; + } + return true; + } + return true; + } + private static interface ElementFilteringStrategy { boolean accept(Element e); }