diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2020-03-26 11:17:09 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2020-03-26 11:17:09 +0100 |
commit | 3f8e7a5f595be2175ca56713ad20a80e562125aa (patch) | |
tree | 6df1771fbf68118c8f630a9eef0b525e103f62c6 /util | |
parent | a25c0115b69b6e37ad264d136e38a982993b0fbe (diff) | |
download | libeufin-3f8e7a5f595be2175ca56713ad20a80e562125aa.tar.gz libeufin-3f8e7a5f595be2175ca56713ad20a80e562125aa.tar.bz2 libeufin-3f8e7a5f595be2175ca56713ad20a80e562125aa.zip |
Throw error if XPath fails.
Diffstat (limited to 'util')
-rw-r--r-- | util/src/main/kotlin/XMLUtil.kt | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt index 1e095869..273660f1 100644 --- a/util/src/main/kotlin/XMLUtil.kt +++ b/util/src/main/kotlin/XMLUtil.kt @@ -21,6 +21,7 @@ package tech.libeufin.util import com.sun.org.apache.xerces.internal.dom.DOMInputImpl import com.sun.xml.bind.marshaller.NamespacePrefixMapper +import io.ktor.http.HttpStatusCode import org.slf4j.Logger import org.slf4j.LoggerFactory import org.w3c.dom.Document @@ -407,14 +408,18 @@ class XMLUtil private constructor() { return valResult } - fun getNodeFromXpath(doc: Document, query: String): Node? { + fun getNodeFromXpath(doc: Document, query: String): Node { val xpath = XPathFactory.newInstance().newXPath() - return xpath.evaluate(query, doc, XPathConstants.NODE) as Node? + val ret = xpath.evaluate(query, doc, XPathConstants.NODE) + ?: throw UtilError(HttpStatusCode.NotFound, "Unsuccessful XPath query string: $query") + return ret as Node } - fun getStringFromXpath(doc: Document, query: String): String? { + fun getStringFromXpath(doc: Document, query: String): String { val xpath = XPathFactory.newInstance().newXPath() - return xpath.evaluate(query, doc, XPathConstants.STRING) as String? + val ret = xpath.evaluate(query, doc, XPathConstants.STRING) + ?: throw UtilError(HttpStatusCode.NotFound, "Unsuccessful XPath query string: $query") + return ret as String } } } |