Skip to content

Commit b31c4a9

Browse files
committed
[bugfix] Make sure that XDM Type information is correctly set in the XML:DB API
1 parent a4979fb commit b31c4a9

File tree

8 files changed

+206
-14
lines changed

8 files changed

+206
-14
lines changed

exist-core/pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,17 +1047,24 @@
10471047
<include>src/main/java/org/exist/validation/resolver/SearchResourceResolver.java</include>
10481048
<include>src/test/java/org/exist/w3c/tests/TestCase.java</include>
10491049
<include>src/main/java/org/exist/webstart/JnlpJarFiles.java</include>
1050+
<include>src/main/java/org/exist/xmldb/AbstractRemoteResource.java</include>
10501051
<include>src/test/java/org/exist/xmldb/ContentAsDOMTest.java</include>
10511052
<include>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</include>
10521053
<include>src/test/java/org/exist/xmldb/EXistXMLSerializeTest.java</include>
1054+
<include>src/main/java/org/exist/xmldb/EXistResource.java</include>
10531055
<include>src/test/java/org/exist/xmldb/IndexingTest.java</include>
1056+
<include>src/main/java/org/exist/xmldb/LocalBinaryResource.java</include>
10541057
<include>src/main/java/org/exist/xmldb/LocalResourceSet.java</include>
10551058
<include>src/main/java/org/exist/xmldb/LocalXMLResource.java</include>
10561059
<include>src/main/java/org/exist/xmldb/LocalXPathQueryService.java</include>
1057-
<include>src/main/java/org/exist/xmldb/RemoteRestoreService.java</include>
1060+
<include>src/main/java/org/exist/xmldb/RemoteBinaryResource.java</include>
10581061
<include>src/test/java/org/exist/xmldb/RemoteDOMTest.java</include>
1062+
<include>src/main/java/org/exist/xmldb/RemoteResourceSet.java</include>
1063+
<include>src/main/java/org/exist/xmldb/RemoteRestoreService.java</include>
1064+
<include>src/main/java/org/exist/xmldb/RemoteXMLResource.java</include>
10591065
<include>src/test/java/org/exist/xmldb/ResourceTest.java</include>
10601066
<include>src/test/java/org/exist/xmldb/SerializationTest.java</include>
1067+
<include>src/test/java/org/exist/xmldb/TestEXistXMLSerialize.java</include>
10611068
<include>src/test/java/org/exist/xmldb/TreeLevelOrderTest.java</include>
10621069
<include>src/test/java/org/exist/xmldb/concurrent/AbstractConcurrentTest.java</include>
10631070
<include>src/test/java/org/exist/xmldb/concurrent/ComplexUpdateTest.java</include>
@@ -1669,17 +1676,24 @@
16691676
<exclude>src/main/java/org/exist/validation/resolver/SearchResourceResolver.java</exclude>
16701677
<exclude>src/test/java/org/exist/w3c/tests/TestCase.java</exclude>
16711678
<exclude>src/main/java/org/exist/webstart/JnlpJarFiles.java</exclude>
1679+
<exclude>src/main/java/org/exist/xmldb/AbstractRemoteResource.java</exclude>
16721680
<exclude>src/test/java/org/exist/xmldb/ContentAsDOMTest.java</exclude>
16731681
<exclude>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</exclude>
16741682
<exclude>src/test/java/org/exist/xmldb/EXistXMLSerializeTest.java</exclude>
1683+
<exclude>src/main/java/org/exist/xmldb/EXistResource.java</exclude>
16751684
<exclude>src/test/java/org/exist/xmldb/IndexingTest.java</exclude>
1685+
<exclude>src/main/java/org/exist/xmldb/LocalBinaryResource.java</exclude>
16761686
<exclude>src/main/java/org/exist/xmldb/LocalResourceSet.java</exclude>
16771687
<exclude>src/main/java/org/exist/xmldb/LocalXMLResource.java</exclude>
16781688
<exclude>src/main/java/org/exist/xmldb/LocalXPathQueryService.java</exclude>
1679-
<exclude>src/main/java/org/exist/xmldb/RemoteRestoreService.java</exclude>
1689+
<exclude>src/main/java/org/exist/xmldb/RemoteBinaryResource.java</exclude>
16801690
<exclude>src/test/java/org/exist/xmldb/RemoteDOMTest.java</exclude>
1691+
<exclude>src/main/java/org/exist/xmldb/RemoteResourceSet.java</exclude>
1692+
<exclude>src/main/java/org/exist/xmldb/RemoteRestoreService.java</exclude>
1693+
<exclude>src/main/java/org/exist/xmldb/RemoteXMLResource.java</exclude>
16811694
<exclude>src/test/java/org/exist/xmldb/ResourceTest.java</exclude>
16821695
<exclude>src/test/java/org/exist/xmldb/SerializationTest.java</exclude>
1696+
<exclude>src/test/java/org/exist/xmldb/TestEXistXMLSerialize.java</exclude>
16831697
<exclude>src/test/java/org/exist/xmldb/TreeLevelOrderTest.java</exclude>
16841698
<exclude>src/test/java/org/exist/xmldb/concurrent/AbstractConcurrentTest.java</exclude>
16851699
<exclude>src/test/java/org/exist/xmldb/concurrent/ComplexUpdateTest.java</exclude>

exist-core/src/main/java/org/exist/xmldb/AbstractRemoteResource.java

Lines changed: 32 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
*
@@ -54,6 +78,7 @@ public abstract class AbstractRemoteResource extends AbstractRemote
5478
implements EXistResource, ExtendedResource, Resource {
5579
protected final XmldbURI path;
5680
private String mimeType;
81+
protected final Optional<String> type;
5782

5883
protected Path file = null;
5984
private ContentFile contentFile = null;
@@ -66,14 +91,15 @@ public abstract class AbstractRemoteResource extends AbstractRemote
6691
Instant dateCreated = null;
6792
Instant dateModified = null;
6893

69-
protected AbstractRemoteResource(final RemoteCollection parent, final XmldbURI documentName, final String mimeType) {
94+
protected AbstractRemoteResource(final RemoteCollection parent, final XmldbURI documentName, final String mimeType, final Optional<String> type) {
7095
super(parent);
7196
if (documentName.numSegments() > 1) {
7297
this.path = documentName;
7398
} else {
7499
this.path = parent.getPathURI().append(documentName);
75100
}
76101
this.mimeType = mimeType;
102+
this.type = type;
77103
}
78104

79105
@Override
@@ -540,6 +566,11 @@ private byte[] readFile(final InputStream is)
540566
}
541567
}
542568

569+
@Override
570+
public String getTypeName() {
571+
return type.orElse("item()");
572+
}
573+
543574
@Override
544575
public final boolean isClosed() {
545576
return closed;

exist-core/src/main/java/org/exist/xmldb/EXistResource.java

Lines changed: 26 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
*
@@ -69,6 +93,8 @@ public interface EXistResource extends Resource, AutoCloseable {
6993

7094
@Nullable Properties getProperties();
7195

96+
String getTypeName();
97+
7298
boolean isClosed();
7399

74100
@Override

exist-core/src/main/java/org/exist/xmldb/LocalBinaryResource.java

Lines changed: 38 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
*
@@ -34,6 +58,7 @@
3458
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
3559
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
3660
import org.exist.xquery.value.BinaryValue;
61+
import org.exist.xquery.value.Type;
3762
import org.w3c.dom.DocumentType;
3863
import org.xml.sax.InputSource;
3964
import org.xml.sax.ext.LexicalHandler;
@@ -304,6 +329,19 @@ public void setProperties(final Properties properties) {
304329
return null;
305330
}
306331

332+
@Override
333+
public String getTypeName() {
334+
int type = Type.ITEM;
335+
336+
if (binaryValue != null) {
337+
type = binaryValue.getType();
338+
} else {
339+
type = Type.BASE64_BINARY;
340+
}
341+
342+
return Type.getTypeName(type);
343+
}
344+
307345
@Override
308346
protected void doClose() throws XMLDBException {
309347
if(!isExternal && file != null) {

exist-core/src/main/java/org/exist/xmldb/LocalXMLResource.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,18 @@ public void endDocument() throws SAXException {
703703
public void setXMLReader(XMLReader xmlReader) {
704704
// no action
705705
}
706+
707+
@Override
708+
public String getTypeName() {
709+
int type = Type.ITEM;
710+
711+
if (value != null) {
712+
type = value.getType();
713+
714+
} else if (root != null) {
715+
type = Type.fromDomNodeType(root.getNodeType());
716+
}
717+
718+
return Type.getTypeName(type);
719+
}
706720
}

exist-core/src/main/java/org/exist/xmldb/RemoteBinaryResource.java

Lines changed: 27 additions & 4 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
*
@@ -26,6 +50,7 @@
2650
import java.util.ArrayList;
2751
import java.util.List;
2852
import java.util.Map;
53+
import java.util.Optional;
2954
import java.util.Properties;
3055

3156
import javax.annotation.Nullable;
@@ -47,18 +72,16 @@ public class RemoteBinaryResource
4772
extends AbstractRemoteResource
4873
implements EXistBinaryResource {
4974

50-
private String type = null;
5175
private byte[] content = null; // only used for binary results from an XQuery execution, where we have been sent the result
5276
private BlobId blobId = null;
5377
private MessageDigest contentDigest = null;
5478

5579
public RemoteBinaryResource(final RemoteCollection parent, final XmldbURI documentName) throws XMLDBException {
56-
super(parent, documentName, MimeType.BINARY_TYPE.getName());
80+
super(parent, documentName, MimeType.BINARY_TYPE.getName(), Optional.of("xs:base64Binary"));
5781
}
5882

5983
public RemoteBinaryResource(final RemoteCollection parent, final XmldbURI documentName, final String type, final byte[] content) throws XMLDBException {
60-
super(parent, documentName, MimeType.BINARY_TYPE.getName());
61-
this.type = type;
84+
super(parent, documentName, MimeType.BINARY_TYPE.getName(), Optional.of(type));
6285
this.content = content;
6386
}
6487

exist-core/src/main/java/org/exist/xmldb/RemoteResourceSet.java

Lines changed: 28 additions & 4 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
*
@@ -170,7 +194,7 @@ public Resource getMembersAsResource() throws XMLDBException {
170194
dec.end();
171195
}
172196

173-
final RemoteXMLResource res = new RemoteXMLResource(collection, handle, 0, XmldbURI.EMPTY_URI, Optional.empty());
197+
final RemoteXMLResource res = new RemoteXMLResource(collection, handle, 0, XmldbURI.EMPTY_URI, Optional.ofNullable((String)table.get("type")));
174198
res.setContent(tempFile);
175199
res.setProperties(outputProperties);
176200
return res;
@@ -203,8 +227,8 @@ public Resource getResource(final long pos) throws XMLDBException {
203227
return (Resource) resources.get((int) pos);
204228
} else {
205229
final Map<String, String> item = (Map<String, String>)resources.get((int)pos);
206-
207-
return switch (item.get("type")) {
230+
final String type = item.get("type");
231+
return switch (type) {
208232
case "node()", "document-node()", "element()", "attribute()", "text()", "processing-instruction()", "comment()", "namespace()", "cdata-section()" ->
209233
getResourceNode((int) pos, item);
210234
case "xs:base64Binary" -> getResourceBinaryValue((int) pos, item, Base64::decodeBase64);
@@ -243,7 +267,7 @@ private RemoteXMLResource getResourceNode(final int pos, final Map<String, Strin
243267
}
244268

245269
private RemoteXMLResource getResourceValue(final int pos, final Map<String, String> valueDetail) throws XMLDBException {
246-
final RemoteXMLResource res = new RemoteXMLResource(collection, handle, pos, XmldbURI.create(Long.toString(pos)), Optional.empty());
270+
final RemoteXMLResource res = new RemoteXMLResource(collection, handle, pos, XmldbURI.create(Long.toString(pos)), Optional.empty(), Optional.ofNullable(valueDetail.get("type")));
247271
res.setContent(valueDetail.get("value"));
248272
res.setProperties(outputProperties);
249273
return res;

exist-core/src/main/java/org/exist/xmldb/RemoteXMLResource.java

Lines changed: 25 additions & 3 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
*
@@ -74,7 +98,6 @@ public class RemoteXMLResource
7498
private XMLReader xmlReader = null;
7599

76100
private final Optional<String> id;
77-
private final Optional<String> type;
78101
private final int handle;
79102
private int pos = -1;
80103
private String content = null;
@@ -147,11 +170,10 @@ public RemoteXMLResource(
147170
final Optional<String> id,
148171
final Optional<String> type)
149172
throws XMLDBException {
150-
super(parent, docId, MimeType.XML_TYPE.getName());
173+
super(parent, docId, MimeType.XML_TYPE.getName(), type);
151174
this.handle = handle;
152175
this.pos = pos;
153176
this.id = id;
154-
this.type = type;
155177
}
156178

157179
@Override

0 commit comments

Comments
 (0)