class XMLUtil {

	@Pure
	@SuppressWarnings("checkstyle:cyclomaticcomplexity")
	private static String getAttributeValue(Node document, boolean caseSensitive, int idxStart, String... path) {
		assert document != null : AssertMessages.notNullParameter(0);
		assert path != null && (path.length - idxStart) >= 0 : AssertMessages.invalidValue(2);

		if ((path.length - idxStart) > 1) {
			final NodeList nodes = document.getChildNodes();
			final int len = nodes.getLength();
			for (int i = 0; i < len; ++i) {
				final Node node = nodes.item(i);
				if (node != null) {
					final String name = node.getNodeName();
					if (name != null
							&& ((caseSensitive && name.equals(path[idxStart]))
									|| (!caseSensitive && name.equalsIgnoreCase(path[idxStart])))) {
						final String value = getAttributeValue(node, caseSensitive, idxStart + 1, path);
						if (value != null) {
							return value;
						}
					}
				}
			}
		} else if (document instanceof Element) {
			if (caseSensitive) {
				return ((Element) document).getAttribute(path[idxStart]);
			}
			final NamedNodeMap map = ((Element) document).getAttributes();
			final int len = map.getLength();
			for (int i = 0; i < len; ++i) {
				final Node node = map.item(i);
				if (node instanceof Attr) {
					final Attr attr = (Attr) node;
					final String name = attr.getName();
					if (name != null && name.equalsIgnoreCase(path[idxStart])) {
						final String value = attr.getValue();
						if (value != null) {
							return value;
						}
					}
				}
			}
		} else {
			final NamedNodeMap attrs = document.getAttributes();
			if (attrs != null) {
				final int len = attrs.getLength();
				for (int idxAttr = 0; idxAttr < len; ++idxAttr) {
					final Node node = attrs.item(idxAttr);
					final String name = node.getNodeName();
					if (name != null
							&& ((caseSensitive && name.equals(path[idxStart]))
									|| (!caseSensitive && name.equalsIgnoreCase(path[idxStart])))) {
						return node.getNodeValue();
					}
				}
			}
		}
		return null;
	}

	private  XMLUtil();

}