Skip to content

Commit

Permalink
check if a value exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rsehr committed Dec 2, 2024
1 parent 20a4111 commit 7d24cc8
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TifValidationSimpleXpathCheck implements TifValidationCheck {
private String errorMessage;
private Map<String, String> replaceMap;

// possible values: equals, greater, lesser, exists, not exists, same
private String checkType = "equals";

public TifValidationSimpleXpathCheck(Set<Namespace> namespaces, String xpath, String expectedValue, String errorMessage) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}
Expand Down

0 comments on commit 7d24cc8

Please sign in to comment.