X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fxml%2FXmlElement.java;h=c37b4abc6215906f1a1a98f5b088e63633f81e16;hb=b0e337733be06807c12d5bbd3b5a29a94f44fdba;hp=5a7fde4e3ddd3e0f29720ebb914cf1a447817d8b;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;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 5a7fde4e3d..c37b4abc62 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 @@ -8,20 +8,28 @@ package org.opendaylight.controller.netconf.util.xml; -import java.io.IOException; -import java.util.*; - -import javax.annotation.Nullable; - -import org.w3c.dom.*; -import org.xml.sax.SAXException; - import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.xml.sax.SAXException; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class XmlElement { @@ -95,6 +103,9 @@ public class XmlElement { } public String getName() { + if (element.getLocalName()!=null && !element.getLocalName().equals("")){ + return element.getLocalName(); + } return element.getTagName(); } @@ -106,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); @@ -265,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; } @@ -361,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); }