package com.microsoft.windowsazure.core.utils;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public abstract class XmlUtility {
    public static Element getElementByTagNameNS(Node element, String namespace,
            String name) {
        NodeList elements = element.getChildNodes();
        CharSequence colon = ":";
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                if (elements.item(i).getNodeType() == Node.ELEMENT_NODE
                    && (elements.item(i).getAttributes().getNamedItemNS("http://www.w3.org/2001/XMLSchema-instance", "nil") == null
                    || !"true".equals(elements.item(i).getAttributes().getNamedItemNS("http://www.w3.org/2001/XMLSchema-instance", "nil")))) {
                    Element currentElement = (Element) elements.item(i);
                    String nodeName = currentElement.getNodeName();
                    String nodeNameOnly = nodeName;
                    if (nodeName.contains(colon)) {
                        String[] nodeNameSplit = nodeName.split(":");
                        nodeNameOnly = nodeNameSplit[1];
                    }
                    
                    if ((currentElement.getNamespaceURI() == null ||
                    	 currentElement.getNamespaceURI().equals(namespace))
                      && nodeNameOnly.equals(name)) {
                        return currentElement;
                    }
                }
            }
        }

        return null;
    }

    public static ArrayList<Element> getElementsByTagNameNS(Node element,
            String namespace, String name) {
        ArrayList<Element> childElements = new ArrayList<Element>();

        NodeList elements = element.getChildNodes();
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                if (elements.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    Element currentElement = (Element) elements.item(i);
                    if ((currentElement.getNamespaceURI() == null ||
                    	currentElement.getNamespaceURI().equals(namespace))
                            && currentElement.getNodeName().equals(name)) {

                        childElements.add(currentElement);
                    }
                }
            }
        }

        return childElements;
    }

    public static Element getElementByTagName(Node element, String name) {
        NodeList elements = element.getChildNodes();
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                if (elements.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    Element currentElement = (Element) elements.item(i);
                    if (currentElement.getNodeName().equals(name)) {

                        return currentElement;
                    }
                }
            }
        }

        return null;
    }
}

@@ -1294,35 +1294,32 @@
 aceURI() == null
- %7C%7C
 %0A               
@@ -1323,17 +1323,22 @@
         
-%09
+    %7C%7C
  current
@@ -1374,32 +1374,34 @@
 als(namespace))%0A
+  
                 
@@ -2126,19 +2126,16 @@
  == null
- %7C%7C
 %0A       
@@ -2151,9 +2151,15 @@
     
-%09
+    %7C%7C 
 curr
@@ -2198,36 +2198,32 @@
 als(namespace))%0A
-    
                 

Fix checkstyle errors