[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Check XPath outcome on string length.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Check XPath outcome on string length. |
Date: |
Thu, 30 Apr 2020 22:26:02 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 88126d0 Check XPath outcome on string length.
88126d0 is described below
commit 88126d05cfc90f0c7de09270e71ec8457142b447
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Apr 30 22:13:55 2020 +0200
Check XPath outcome on string length.
---
nexus/src/test/kotlin/XPathTest.kt | 5 ++---
util/src/main/kotlin/XMLUtil.kt | 6 ++++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/nexus/src/test/kotlin/XPathTest.kt
b/nexus/src/test/kotlin/XPathTest.kt
index bb1b93b..be48c4f 100644
--- a/nexus/src/test/kotlin/XPathTest.kt
+++ b/nexus/src/test/kotlin/XPathTest.kt
@@ -3,6 +3,7 @@ package tech.libeufin.nexus
import org.junit.Test
import org.w3c.dom.Document
import tech.libeufin.util.XMLUtil
+import tech.libeufin.util.pickString
class XPathTest {
@@ -13,9 +14,7 @@ class XPathTest {
<node>lorem ipsum</node>
</root>""".trimIndent()
val doc: Document = XMLUtil.parseStringIntoDom(xml)
- XMLUtil.getNodeFromXpath(doc, "/*[local-name()='root']")
- val text = XMLUtil.getStringFromXpath(doc, "//*[local-name()='node']")
- println(text)
+ println(doc.pickString( "//*[local-name()='node']"))
}
}
diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt
index eb1f6f7..fd33932 100644
--- a/util/src/main/kotlin/XMLUtil.kt
+++ b/util/src/main/kotlin/XMLUtil.kt
@@ -417,8 +417,10 @@ class XMLUtil private constructor() {
fun getStringFromXpath(doc: Document, query: String): String {
val xpath = XPathFactory.newInstance().newXPath()
- val ret = xpath.evaluate(query, doc, XPathConstants.STRING)
- ?: throw UtilError(HttpStatusCode.NotFound, "Unsuccessful
XPath query string: $query")
+ val ret = xpath.evaluate(query, doc, XPathConstants.STRING) as
String
+ if (ret.isEmpty()) {
+ throw UtilError(HttpStatusCode.NotFound, "Unsuccessful XPath
query string: $query")
+ }
return ret as String
}
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Check XPath outcome on string length.,
gnunet <=