net.sf.andromedaioc.util.XmlUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of andromeda-ioc Show documentation
Show all versions of andromeda-ioc Show documentation
Inversion of Control Framework for Android
The newest version!
package net.sf.andromedaioc.util;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XmlUtils {
private XmlUtils() {
}
public static Node extractAttributeNode(Node node, String attributeName) {
NamedNodeMap attributes = node.getAttributes();
return attributes.getNamedItem(attributeName);
}
public static String extractStringAttributeValue(Node node, String attributeName) {
Node attribute = extractAttributeNode(node, attributeName);
return attribute == null ? null : attribute.getNodeValue();
}
public static Class> extractClassAttributeValue(Node node, String attributeName) throws ClassNotFoundException {
String className = extractStringAttributeValue(node, attributeName);
return className == null ? null : Class.forName(className); // ClassLoader.getSystemClassLoader().loadClass(className);
}
public static boolean extractBooleanAttributeValue(Node node, String attributeName, boolean defaultValue) {
String value = extractStringAttributeValue(node, attributeName);
return value == null ? defaultValue : Boolean.valueOf(value);
}
public static Integer extractIntegerAttributeValue(Node node, String attributeName) {
String value = extractStringAttributeValue(node, attributeName);
return value == null ? null : Integer.parseInt(value);
}
public static Node findChildElementNode(Node parentNode, String childNodeName) {
NodeList childNodes = parentNode.getChildNodes();
for(int i=0; i