From 98d70502c9c2ce0f8cfce10f556bcb42cc5e6efc Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Wed, 10 Apr 2024 14:51:56 +0200 Subject: [PATCH] #9655 (#185) - handle different namespaces with same prefix --- .../commons/xml/schema/XMLSchemaInfoSet.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/xml/schema/XMLSchemaInfoSet.java b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/xml/schema/XMLSchemaInfoSet.java index 7af1184fd6..6966c2ab64 100644 --- a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/xml/schema/XMLSchemaInfoSet.java +++ b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/xml/schema/XMLSchemaInfoSet.java @@ -54,7 +54,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; +import java.util.UUID; import javax.xml.XMLConstants; import javax.xml.namespace.QName; @@ -223,10 +225,21 @@ public synchronized Map getNamespacePrefixes() { if (prefix != null && !prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { String nsUri = xmlStream.getNamespaceURI(i); String oldPrefix = nsToPrefix.get(nsUri); + Optional oldNsUri = nsToPrefix.entrySet() + .stream() + .filter(entry -> prefix.equals(entry.getValue())) + .map(Map.Entry::getKey) + .findFirst(); if (oldPrefix != null && !oldPrefix.equals(prefix)) { LOG.debug("Multiple prefices for namespace '" + nsUri + "': " + prefix + " / " + oldPrefix); } + else if (oldNsUri.isPresent() && !oldNsUri.get().equals(nsUri)) { + String newPrefix = prefix + UUID.randomUUID(); + LOG.warn("Multiple nsUrls for prefix '" + prefix + "': " + nsUri + + ". Created new prefix: " + newPrefix); + nsToPrefix.put(nsUri, newPrefix); + } else { nsToPrefix.put(nsUri, prefix); }