use of javax.xml.xpath.XPath in project openhab1-addons by openhab.
the class Tr064Comm method readAllServices.
/***
* Connects to fbox service xml to get a list of all services
* which are offered by TR064. Saves it into local list
*/
private void readAllServices() {
Document xml = getFboxXmlResponse(_url + "/" + TR064DOWNLOADFILE);
if (xml == null) {
logger.error("Could not read xml response services");
return;
}
// get all service nodes
NodeList nlServices = xml.getElementsByTagName("service");
Node currentNode = null;
XPath xPath = XPathFactory.newInstance().newXPath();
for (int i = 0; i < nlServices.getLength(); i++) {
// iterate over all services fbox offered us
currentNode = nlServices.item(i);
Tr064Service trS = new Tr064Service();
try {
trS.setControlUrl((String) xPath.evaluate("controlURL", currentNode, XPathConstants.STRING));
trS.setEventSubUrl((String) xPath.evaluate("eventSubURL", currentNode, XPathConstants.STRING));
trS.setScpdurl((String) xPath.evaluate("SCPDURL", currentNode, XPathConstants.STRING));
trS.setServiceId((String) xPath.evaluate("serviceId", currentNode, XPathConstants.STRING));
trS.setServiceType((String) xPath.evaluate("serviceType", currentNode, XPathConstants.STRING));
} catch (XPathExpressionException e) {
logger.debug("Could not parse service {}", currentNode.getTextContent());
e.printStackTrace();
}
_alServices.add(trS);
}
}
use of javax.xml.xpath.XPath in project languagetool by languagetool-org.
the class PatternRuleXmlCreator method toXML.
/**
* Return the given pattern rule as an indented XML string.
* @since 2.3
*/
public final String toXML(PatternRuleId ruleId, Language language) {
List<String> filenames = language.getRuleFileNames();
XPath xpath = XPathFactory.newInstance().newXPath();
for (String filename : filenames) {
try (InputStream is = this.getClass().getResourceAsStream(filename)) {
Document doc = getDocument(is);
Node ruleNode = (Node) xpath.evaluate("/rules/category/rule[@id='" + ruleId.getId() + "']", doc, XPathConstants.NODE);
if (ruleNode != null) {
return nodeToString(ruleNode);
}
Node ruleNodeInGroup = (Node) xpath.evaluate("/rules/category/rulegroup/rule[@id='" + ruleId.getId() + "']", doc, XPathConstants.NODE);
if (ruleNodeInGroup != null) {
return nodeToString(ruleNodeInGroup);
}
if (ruleId.getSubId() != null) {
NodeList ruleGroupNodes = (NodeList) xpath.evaluate("/rules/category/rulegroup[@id='" + ruleId.getId() + "']/rule", doc, XPathConstants.NODESET);
if (ruleGroupNodes != null) {
for (int i = 0; i < ruleGroupNodes.getLength(); i++) {
if (Integer.toString(i + 1).equals(ruleId.getSubId())) {
return nodeToString(ruleGroupNodes.item(i));
}
}
}
} else {
Node ruleGroupNode = (Node) xpath.evaluate("/rules/category/rulegroup[@id='" + ruleId.getId() + "']", doc, XPathConstants.NODE);
if (ruleGroupNode != null) {
return nodeToString(ruleGroupNode);
}
}
} catch (Exception e) {
throw new RuntimeException("Could not turn rule '" + ruleId + "' for language " + language + " into a string", e);
}
}
throw new RuntimeException("Could not find rule '" + ruleId + "' for language " + language + " in files: " + filenames);
}
use of javax.xml.xpath.XPath in project buck by facebook.
the class AndroidXPathFactory method newXPath.
/**
* Creates a new XPath object, specifying which prefix in the query is used for the
* android namespace.
* @param androidPrefix The namespace prefix.
*/
public static XPath newXPath(String androidPrefix) {
XPath xpath = sFactory.newXPath();
xpath.setNamespaceContext(new AndroidNamespaceContext(androidPrefix));
return xpath;
}
use of javax.xml.xpath.XPath in project buck by facebook.
the class AndroidXPathFactory method newXPath.
/**
* Creates a new XPath object using the default prefix for the android namespace.
* @see #DEFAULT_NS_PREFIX
*/
public static XPath newXPath() {
XPath xpath = sFactory.newXPath();
xpath.setNamespaceContext(AndroidNamespaceContext.getDefault());
return xpath;
}
use of javax.xml.xpath.XPath in project flyway by flyway.
the class GradleLargeTest method getPomVersion.
/**
* Retrieves the version embedded in the project pom. Useful for running these tests in IntelliJ.
*
* @return The POM version.
*/
private String getPomVersion() {
try {
File pom = new File("pom.xml");
if (!pom.exists()) {
return "unknown";
}
XPath xPath = XPathFactory.newInstance().newXPath();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(false);
Document document = documentBuilderFactory.newDocumentBuilder().parse(pom);
return xPath.evaluate("/project/version", document);
} catch (Exception e) {
throw new IllegalStateException("Unable to read POM version", e);
}
}
Aggregations