Skip to content

Commit

Permalink
#9655 (#185) - handle different namespaces with same prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Apr 10, 2024
1 parent 5596605 commit 98d7050
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -223,10 +225,21 @@ public synchronized Map<String, String> getNamespacePrefixes() {
if (prefix != null && !prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
String nsUri = xmlStream.getNamespaceURI(i);
String oldPrefix = nsToPrefix.get(nsUri);
Optional<String> 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);
}
Expand Down

0 comments on commit 98d7050

Please sign in to comment.