From 0d583f175f498072680e190aa9049e4e49a1dbd6 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 10 Feb 2023 10:12:08 +0100 Subject: [PATCH] Validate context against aliases and versioning --- .../vc/probe/ContextPropertyProbe.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ContextPropertyProbe.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ContextPropertyProbe.java index f0ec2ab..865daca 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ContextPropertyProbe.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ContextPropertyProbe.java @@ -36,7 +36,7 @@ public class ContextPropertyProbe extends StringValuePropertyProbe { int pos = 0; for (String uri : contextUris) { - if ((nodeValues.size() < pos + 1) || !nodeValues.get(pos).equals(uri)) { + if ((nodeValues.size() < pos + 1) || !contains(uri, nodeValues.get(pos))) { return error("missing required @context uri " + uri + " at position " + (pos + 1), ctx); } pos++; @@ -46,5 +46,25 @@ public class ContextPropertyProbe extends StringValuePropertyProbe { return success(ctx); } + private boolean contains(String uri, String nodeValue) { + // check equal case + if (nodeValue.equals(uri)) { + return true; + } + // check aliases + if (type.getContextAliases().containsKey(uri)) { + if (type.getContextAliases().get(uri).stream().anyMatch(alias -> nodeValue.equals(alias))) { + return true; + } + } + // check versioning + if (type.getContextVersionPatterns().containsKey(uri)) { + if (type.getContextVersionPatterns().get(uri).stream().anyMatch(version -> nodeValue.matches(version))) { + return true; + } + } + return false; + } + public static final String ID = ContextPropertyProbe.class.getSimpleName(); }