From 7d24cc8fe5b1b1a2e07d53b7a52dd2bda325ce88 Mon Sep 17 00:00:00 2001 From: Robert Sehr Date: Mon, 2 Dec 2024 14:23:43 +0100 Subject: [PATCH] check if a value exists --- .../plugins/checks/TifValidationSimpleXpathCheck.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java index 6979136..54e65d1 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/checks/TifValidationSimpleXpathCheck.java @@ -27,6 +27,7 @@ public class TifValidationSimpleXpathCheck implements TifValidationCheck { private String errorMessage; private Map replaceMap; + // possible values: equals, greater, lesser, exists, not exists, same private String checkType = "equals"; public TifValidationSimpleXpathCheck(Set namespaces, String xpath, String expectedValue, String errorMessage) { @@ -54,6 +55,10 @@ private void createReplaceMap() { @Override public boolean check(Document doc) { Object value = xpath.evaluateFirst(doc); + if (value == null) { + return "not exists".equals(checkType); + } + if (value instanceof Element e) { value = e.getTextTrim(); } else if (value instanceof Attribute a) { @@ -66,6 +71,9 @@ public boolean check(Document doc) { this.replaceMap.put("found", (String) value); switch (checkType) { + case "exists": + return true; + case "equals": { return this.expectedValue.equals(value) || (value instanceof String s && s.matches(this.expectedValue)); }