
com.xtremelabs.robolectric.res.XpathResourceXmlLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric Show documentation
Show all versions of robolectric Show documentation
An alternative Android testing framework.
package com.xtremelabs.robolectric.res;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.File;
public abstract class XpathResourceXmlLoader extends XmlLoader {
private String expression;
public XpathResourceXmlLoader(ResourceExtractor resourceExtractor, String expression) {
super(resourceExtractor);
this.expression = expression;
}
@Override protected void processResourceXml(File xmlFile, Document document, boolean isSystem) throws Exception {
XPathExpression stringsXPath = XPathFactory.newInstance().newXPath().compile(expression);
NodeList nodes = (NodeList) stringsXPath.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String name = node.getAttributes().getNamedItem("name").getNodeValue();
processNode(node, name, isSystem);
}
}
protected abstract void processNode(Node node, String name, boolean isSystem) throws XPathExpressionException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy