Skip to content

Commit 13be94d

Browse files
committed
[bugfix] Fix issues with Saxon to eXist-db XDM conversion and vice-versa
Closes eXist-db/exist#5680
1 parent 142faf6 commit 13be94d

File tree

14 files changed

+763
-46
lines changed

14 files changed

+763
-46
lines changed

exist-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@
691691
<include>src/test/java/org/exist/xquery/value/DateTimeTypesTest.java</include>
692692
<include>src/test/java/org/exist/xquery/functions/fn/FunXmlToJsonTest.java</include>
693693
<include>src/test/java/org/exist/xquery/functions/fn/ParsingFunctionsTest.java</include>
694+
<include>src/test/java/org/exist/xquery/functions/fn/transform/ConvertTest.java</include>
694695
<include>src/test/java/org/exist/xquery/functions/fn/transform/FunTransformITTest.java</include>
695696
<include>src/test/java/org/exist/xquery/functions/xmldb/XMLDBStoreTest.java</include>
696697
<include>src/test/java/org/exist/xquery/functions/xquery3/SerializeTest.java</include>
@@ -736,24 +737,29 @@
736737
<include>src/main/java/org/exist/collections/Collection.java</include>
737738
<include>src/main/java/org/exist/collections/CollectionConfiguration.java</include>
738739
<include>src/main/java/org/exist/collections/CollectionConfigurationManager.java</include>
740+
<include>src/main/java/org/exist/collections/MutableCollection.java</include>
739741
<include>src/main/java/org/exist/collections/triggers/CollectionTrigger.java</include>
740742
<include>src/main/java/org/exist/collections/triggers/DocumentTrigger.java</include>
741743
<include>src/main/java/org/exist/collections/triggers/XQueryStartupTrigger.java</include>
742744
<include>src/main/java/org/exist/config/Configuration.java</include>
743745
<include>src/main/java/org/exist/config/ConfigurationImpl.java</include>
746+
<include>src/main/java/org/exist/dom/memtree/AttrImpl.java</include>
744747
<include>src/main/java/org/exist/dom/memtree/DocumentImpl.java</include>
745748
<include>src/main/java/org/exist/dom/memtree/DOMIndexer.java</include>
746749
<include>src/main/java/org/exist/dom/memtree/ElementImpl.java</include>
747750
<include>src/main/java/org/exist/dom/memtree/MemTreeBuilder.java</include>
748751
<include>src/main/java/org/exist/dom/memtree/NodeImpl.java</include>
749752
<include>src/main/java/org/exist/dom/persistent/AbstractCharacterData.java</include>
753+
<include>src/main/java/org/exist/dom/persistent/AttrImpl.java</include>
750754
<include>src/main/java/org/exist/dom/persistent/CommentImpl.java</include>
751755
<include>src/main/java/org/exist/dom/persistent/DocumentImpl.java</include>
752756
<include>src/main/java/org/exist/dom/persistent/DocumentSet.java</include>
753757
<include>src/main/java/org/exist/dom/persistent/ElementImpl.java</include>
754758
<include>src/main/java/org/exist/dom/persistent/NodeProxy.java</include>
755759
<include>src/test/java/org/exist/dom/persistent/NodeTest.java</include>
760+
<include>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</include>
756761
<include>src/main/java/org/exist/dom/persistent/ProcessingInstructionImpl.java</include>
762+
<include>src/main/java/org/exist/dom/persistent/StoredNode.java</include>
757763
<include>src/main/java/org/exist/dom/persistent/SymbolTable.java</include>
758764
<include>src/main/java/org/exist/dom/persistent/TextImpl.java</include>
759765
<include>src/main/java/org/exist/dom/persistent/VirtualNodeSet.java</include>
@@ -909,11 +915,13 @@
909915
<exclude>src/main/java/org/exist/collections/Collection.java</exclude>
910916
<exclude>src/main/java/org/exist/collections/CollectionConfiguration.java</exclude>
911917
<exclude>src/main/java/org/exist/collections/CollectionConfigurationManager.java</exclude>
918+
<exclude>src/main/java/org/exist/collections/MutableCollection.java</exclude>
912919
<exclude>src/main/java/org/exist/collections/triggers/CollectionTrigger.java</exclude>
913920
<exclude>src/main/java/org/exist/collections/triggers/DocumentTrigger.java</exclude>
914921
<exclude>src/main/java/org/exist/collections/triggers/XQueryStartupTrigger.java</exclude>
915922
<exclude>src/main/java/org/exist/config/Configuration.java</exclude>
916923
<exclude>src/main/java/org/exist/config/ConfigurationImpl.java</exclude>
924+
<exclude>src/main/java/org/exist/dom/memtree/AttrImpl.java</exclude>
917925
<exclude>src/main/java/org/exist/dom/memtree/DocumentImpl.java</exclude>
918926
<exclude>src/main/java/org/exist/dom/memtree/DocumentTypeImpl.java</exclude>
919927
<exclude>src/main/java/org/exist/dom/memtree/DOMIndexer.java</exclude>
@@ -928,13 +936,16 @@
928936
<exclude>src/main/java/org/exist/dom/memtree/reference/ProcessingInstructionReferenceImpl.java</exclude>
929937
<exclude>src/main/java/org/exist/dom/memtree/reference/TextReferenceImpl.java</exclude>
930938
<exclude>src/main/java/org/exist/dom/persistent/AbstractCharacterData.java</exclude>
939+
<exclude>src/main/java/org/exist/dom/persistent/AttrImpl.java</exclude>
931940
<exclude>src/main/java/org/exist/dom/persistent/CommentImpl.java</exclude>
932941
<exclude>src/main/java/org/exist/dom/persistent/DocumentImpl.java</exclude>
933942
<exclude>src/main/java/org/exist/dom/persistent/DocumentSet.java</exclude>
934943
<exclude>src/main/java/org/exist/dom/persistent/ElementImpl.java</exclude>
935944
<exclude>src/main/java/org/exist/dom/persistent/NodeProxy.java</exclude>
936945
<exclude>src/test/java/org/exist/dom/persistent/NodeTest.java</exclude>
946+
<exclude>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</exclude>
937947
<exclude>src/main/java/org/exist/dom/persistent/ProcessingInstructionImpl.java</exclude>
948+
<exclude>src/main/java/org/exist/dom/persistent/StoredNode.java</exclude>
938949
<exclude>src/main/java/org/exist/dom/persistent/SymbolTable.java</exclude>
939950
<exclude>src/main/java/org/exist/dom/persistent/TextImpl.java</exclude>
940951
<exclude>src/main/java/org/exist/dom/persistent/VirtualNodeSet.java</exclude>
@@ -1006,6 +1017,7 @@
10061017
<exclude>src/main/java/org/exist/xquery/functions/fn/LoadXQueryModule.java</exclude>
10071018
<exclude>src/main/java/org/exist/xquery/functions/fn/ParsingFunctions.java</exclude>
10081019
<exclude>src/test/java/org/exist/xquery/functions/fn/ParsingFunctionsTest.java</exclude>
1020+
<exclude>src/test/java/org/exist/xquery/functions/fn/transform/ConvertTest.java</exclude>
10091021
<exclude>src/test/java/org/exist/xquery/functions/fn/transform/FunTransformITTest.java</exclude>
10101022
<exclude>src/main/java/org/exist/xquery/functions/system/GetUptime.java</exclude>
10111023
<exclude>src/main/java/org/exist/xquery/functions/system/Shutdown.java</exclude>

exist-core/src/main/java/org/exist/Indexer.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -591,7 +615,7 @@ public void startElement(final String namespace, final String name, final String
591615
setPrevious(null);
592616
node.setOwnerDocument(document);
593617
node.setAttributes((short) attrLength);
594-
if (nsMappings != null && nsMappings.size() > 0) {
618+
if (!nsMappings.isEmpty()) {
595619
node.setNamespaceMappings(nsMappings);
596620
nsMappings.clear();
597621
}
@@ -615,7 +639,7 @@ public void startElement(final String namespace, final String name, final String
615639
node.setOwnerDocument(document);
616640
node.setNodeId(broker.getBrokerPool().getNodeFactory().createInstance(nodeFactoryInstanceCnt++));
617641
node.setAttributes((short) attrLength);
618-
if (nsMappings != null && nsMappings.size() > 0) {
642+
if (!nsMappings.isEmpty()) {
619643
node.setNamespaceMappings(nsMappings);
620644
nsMappings.clear();
621645
}

exist-core/src/main/java/org/exist/collections/MutableCollection.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -1160,7 +1184,7 @@ public void storeDocument(final Txn transaction, final DBBroker broker, final Xm
11601184

11611185
@Override
11621186
public void storeDocument(final Txn transaction, final DBBroker broker, final XmldbURI name, final Node node, @Nullable MimeType mimeType) throws EXistException, PermissionDeniedException, SAXException, LockException, IOException {
1163-
storeDocument(transaction, broker, name, node, mimeType);
1187+
storeDocument(transaction, broker, name, node, mimeType, null, null, null, null, null);
11641188
}
11651189

11661190
@Override

exist-core/src/main/java/org/exist/dom/memtree/AttrImpl.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -79,6 +103,11 @@ public Node getFirstChild() {
79103
return null;
80104
}
81105

106+
@Override
107+
public Node getPreviousSibling() {
108+
return null;
109+
}
110+
82111
@Override
83112
public Node getNextSibling() {
84113
return null;

exist-core/src/main/java/org/exist/dom/persistent/AttrImpl.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -385,6 +409,11 @@ public Node getFirstChild() {
385409
return null;
386410
}
387411

412+
@Override
413+
public Node getPreviousSibling() {
414+
return null;
415+
}
416+
388417
@Override
389418
public Node getNextSibling() {
390419
return null;

exist-core/src/main/java/org/exist/dom/persistent/ElementImpl.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ public int getPosition() {
195195
}
196196

197197
public boolean declaresNamespacePrefixes() {
198-
if(namespaceMappings == null) {
199-
return false;
200-
}
201-
return namespaceMappings.size() > 0;
198+
return namespaceMappings != null && !namespaceMappings.isEmpty();
202199
}
203200

204201
/**
@@ -474,13 +471,13 @@ public static void readNamespaceDecls(final List<String[]> namespaces, final Val
474471
}
475472

476473
public void addNamespaceMapping(final String prefix, final String ns) {
477-
if(prefix == null) {
474+
if (prefix == null) {
478475
return;
479476
}
480477

481-
if(namespaceMappings == null) {
478+
if (namespaceMappings == null) {
482479
namespaceMappings = new HashMap<>(1);
483-
} else if(namespaceMappings.containsKey(prefix)) {
480+
} else if (namespaceMappings.containsKey(prefix)) {
484481
return;
485482
}
486483

@@ -1364,8 +1361,13 @@ public void setChildCount(final int count) {
13641361
}
13651362

13661363
public void setNamespaceMappings(final Map<String, String> map) {
1367-
this.namespaceMappings = new HashMap<>(map);
1368-
for(final String ns : namespaceMappings.values()) {
1364+
if (this.namespaceMappings == null) {
1365+
this.namespaceMappings = new HashMap<>(map);
1366+
} else {
1367+
this.namespaceMappings.clear();
1368+
this.namespaceMappings.putAll(map);
1369+
}
1370+
for (final String ns : namespaceMappings.values()) {
13691371
ownerDocument.getBrokerPool().getSymbols().getNSSymbol(ns);
13701372
}
13711373
}
@@ -1544,7 +1546,7 @@ public void insertBefore(final Txn transaction, final NodeList nodes, final Node
15441546
}
15451547

15461548
final IStoredNode<?> following = (IStoredNode<?>) refChild;
1547-
final IStoredNode<?> previous = (IStoredNode<?>) following.getPreviousSibling();
1549+
final IStoredNode<?> previous = (IStoredNode<?>) ((StoredNode<?>) following).getPreviousSibling(true);
15481550
if(previous == null) {
15491551
// there's no sibling node before the new node
15501552
final NodeId newId = following.getNodeId().insertBefore();
@@ -1676,8 +1678,11 @@ public void update(final Txn transaction, final NodeList newContent) throws DOME
16761678
* Update a child node. This method will only update the child node
16771679
* but not its potential descendant nodes.
16781680
*
1679-
* @param oldChild to be replace
1681+
* @param oldChild to be replaced
16801682
* @param newChild to be added
1683+
*
1684+
* @return the new node
1685+
*
16811686
* @throws DOMException in case of a DOM error
16821687
*/
16831688
@Override
@@ -1699,7 +1704,7 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
16991704
attr.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attr.getValue())));
17001705
attr.setType(AttrImpl.ID);
17011706
}
1702-
IStoredNode<?> previousNode = (IStoredNode<?>) oldNode.getPreviousSibling();
1707+
IStoredNode<?> previousNode = (IStoredNode<?>) ((StoredNode<?>) oldNode).getPreviousSibling(true);
17031708
if(previousNode == null) {
17041709
previousNode = this;
17051710
} else {
@@ -1872,13 +1877,16 @@ public boolean visit(final IStoredNode node) {
18721877
}
18731878

18741879
/**
1875-
* Replaces the oldNode with the newChild
1880+
* Replaces the oldChild with the newChild
18761881
*
18771882
* @param transaction the transaction
18781883
* @param newChild to replace oldChild
1879-
* @param oldChild to be replace by newChild
1884+
* @param oldChild to be replaced by newChild
1885+
*
18801886
* @return The new node (this differs from the {@link org.w3c.dom.Node#replaceChild(Node, Node)} specification)
1887+
*
18811888
* @throws DOMException in case of a DOM error
1889+
*
18821890
* @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
18831891
*/
18841892
@Override
@@ -1893,7 +1901,7 @@ public Node replaceChild(final Txn transaction, final Node newChild, final Node
18931901
}
18941902

18951903
final NodePath thisPath = getPath();
1896-
IStoredNode<?> previous = (IStoredNode<?>) oldNode.getPreviousSibling();
1904+
IStoredNode<?> previous = (IStoredNode<?>) ((StoredNode<?>) oldNode).getPreviousSibling(true);
18971905
if(previous == null) {
18981906
previous = this;
18991907
} else {

0 commit comments

Comments
 (0)