Skip to content

Commit fd3b651

Browse files
committed
[feature] Allow an XQJ serialization of XQuery Items as the result of executing an XQuery in the XML:RPC API. Enabled by default in Elemental. To preserve XML:RPC compatibility with eXist-db, this has been implemented in such a manner that this feature will not be used when using the Elemental XML:DB Remote API to talk to eXist-db, or when using the eXist-db XML:DB Remote API to talk to Elemental. Re-enables support for all XDM Types in XML:RPC API after 14644d5 disabled them due to API compatibility issues. If 14644d5 is reverted in future, then this commit can also be reverted.
1 parent 8a47b8e commit fd3b651

16 files changed

+499
-79
lines changed

exist-core/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@
758758
<include>src/main/java/org/exist/util/JREUtil.java</include>
759759
<include>src/main/java/org/exist/util/OSUtil.java</include>
760760
<include>src/main/java/org/exist/util/StringUtil.java</include>
761+
<include>src/main/java/org/exist/util/io/AbstractContentFile.java</include>
761762
<include>src/test/java/org/exist/util/serializer/SAXSerializerTest.java</include>
762763
<include>src/test/java/org/exist/xmldb/XMLDBExternalVariableTest.java</include>
763764
<include>src/main/java/org/exist/xmlrpc/ArrayWrapperParser.java</include>
@@ -996,6 +997,7 @@
996997
<include>src/test/java/org/exist/storage/io/VariableByteStreamTest.java</include>
997998
<include>src/main/java/org/exist/storage/lock/FileLock.java</include>
998999
<include>src/main/java/org/exist/storage/recovery/RecoveryManager.java</include>
1000+
<include>src/main/java/org/exist/storage/serializers/EXistOutputKeys.java</include>
9991001
<include>src/main/java/org/exist/storage/serializers/Serializer.java</include>
10001002
<include>src/main/java/org/exist/storage/serializers/XIncludeFilter.java</include>
10011003
<include>src/test/resources-filtered/org/exist/storage/statistics/conf.xml</include>
@@ -1021,8 +1023,14 @@
10211023
<include>src/test/java/org/exist/util/LeasableTest.java</include>
10221024
<include>src/main/java/org/exist/util/ParametersExtractor.java</include>
10231025
<include>src/main/java/org/exist/util/crypto/digest/DigestType.java</include>
1026+
<include>src/main/java/org/exist/util/io/ByteArrayContent.java</include>
1027+
<include>src/test/java/org/exist/util/io/ByteArrayContentTest.java</include>
1028+
<include>src/main/java/org/exist/util/io/ContentFile.java</include>
1029+
<include>src/main/java/org/exist/util/io/ContentFilePoolObjectFactory.java</include>
10241030
<include>src/test/java/org/exist/util/io/FilterInputStreamCacheMonitorTest.java</include>
10251031
<include>src/test/java/org/exist/util/io/OverflowToDiskStreamTest.java</include>
1032+
<include>src/main/java/org/exist/util/io/VirtualTempPath.java</include>
1033+
<include>src/test/java/org/exist/util/io/VirtualTempPathTest.java</include>
10261034
<include>src/test/java/org/exist/util/pool/NodePoolTest.java</include>
10271035
<include>src/main/java/org/exist/util/serializer/AttrList.java</include>
10281036
<include>src/main/java/org/exist/util/serializer/DOMSerializer.java</include>
@@ -1611,6 +1619,7 @@
16111619
<exclude>src/main/java/org/exist/storage/lock/ManagedLockGroupDocumentLock.java</exclude>
16121620
<exclude>src/main/java/org/exist/storage/lock/ManagedSingleLockDocumentLock.java</exclude>
16131621
<exclude>src/main/java/org/exist/storage/recovery/RecoveryManager.java</exclude>
1622+
<exclude>src/main/java/org/exist/storage/serializers/EXistOutputKeys.java</exclude>
16141623
<exclude>src/test/java/org/exist/storage/serializers/NativeSerializerTest.java</exclude>
16151624
<exclude>src/main/java/org/exist/storage/serializers/Serializer.java</exclude>
16161625
<exclude>src/main/java/org/exist/storage/serializers/XIncludeFilter.java</exclude>
@@ -1654,8 +1663,15 @@
16541663
<exclude>src/main/java/org/exist/util/StringUtil.java</exclude>
16551664
<exclude>src/main/java/org/exist/util/UTF8.java</exclude>
16561665
<exclude>src/main/java/org/exist/util/crypto/digest/DigestType.java</exclude>
1666+
<exclude>src/main/java/org/exist/util/io/AbstractContentFile.java</exclude>
1667+
<exclude>src/main/java/org/exist/util/io/ByteArrayContent.java</exclude>
1668+
<exclude>src/test/java/org/exist/util/io/ByteArrayContentTest.java</exclude>
1669+
<exclude>src/main/java/org/exist/util/io/ContentFile.java</exclude>
1670+
<exclude>src/main/java/org/exist/util/io/ContentFilePoolObjectFactory.java</exclude>
16571671
<exclude>src/test/java/org/exist/util/io/FilterInputStreamCacheMonitorTest.java</exclude>
16581672
<exclude>src/test/java/org/exist/util/io/OverflowToDiskStreamTest.java</exclude>
1673+
<exclude>src/main/java/org/exist/util/io/VirtualTempPath.java</exclude>
1674+
<exclude>src/test/java/org/exist/util/io/VirtualTempPathTest.java</exclude>
16591675
<exclude>src/test/java/org/exist/util/pool/NodePoolTest.java</exclude>
16601676
<exclude>src/main/java/org/exist/util/serializer/AttrList.java</exclude>
16611677
<exclude>src/main/java/org/exist/util/serializer/DOMSerializer.java</exclude>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.exist.xquery.Expression;
5454
import org.exist.xquery.XQueryContext;
5555
import org.w3c.dom.DOMException;
56-
import org.w3c.dom.Document;
5756
import org.w3c.dom.Node;
5857
import org.w3c.dom.NodeList;
5958
import org.xml.sax.Attributes;

exist-core/src/main/java/org/exist/storage/serializers/EXistOutputKeys.java

Lines changed: 35 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
*
@@ -107,6 +131,17 @@ public class EXistOutputKeys {
107131
*/
108132
public static final String XDM_SERIALIZATION = "xdm-serialization";
109133

134+
/**
135+
* When serializing an XDM this should be used
136+
* to enforce XQJ serialization rules.
137+
*
138+
* XQJ has different serialization rules
139+
* compared to retrieving and serializing resources from the database.
140+
*
141+
* Set to "yes" to enable xqj-serialization rules, false otherwise.
142+
*/
143+
public static final String XQJ_SERIALIZATION = "xqj-serialization";
144+
110145
/**
111146
* Enforce newline at the end of JSON and XML documents.
112147
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
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+
package org.exist.util.io;
22+
23+
/**
24+
* @author <a href="mailto:[email protected]">Adam Retter</a>
25+
*/
26+
public abstract class AbstractContentFile implements ContentFile {
27+
28+
protected final ContentFileType type;
29+
30+
protected AbstractContentFile(final ContentFileType type) {
31+
this.type = type;
32+
}
33+
34+
@Override
35+
public ContentFileType getType() {
36+
return type;
37+
}
38+
}

exist-core/src/main/java/org/exist/util/io/ByteArrayContent.java

Lines changed: 31 additions & 6 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,20 +50,21 @@
2650
/**
2751
* @author <a href="mailto:[email protected]">Patrick Reinhart</a>
2852
*/
29-
public final class ByteArrayContent implements ContentFile {
53+
public final class ByteArrayContent extends AbstractContentFile {
3054
private static final byte[] EMPTY_BUFFER = new byte[0];
3155

3256
private byte[] data;
3357

34-
public static ByteArrayContent of(byte[] data) {
35-
return new ByteArrayContent(data);
58+
public static ByteArrayContent of(final ContentFileType type, final byte[] data) {
59+
return new ByteArrayContent(type, data);
3660
}
3761

38-
public static ByteArrayContent of(String data) {
39-
return new ByteArrayContent(data.getBytes(StandardCharsets.UTF_8));
62+
public static ByteArrayContent of(final ContentFileType type, final String data) {
63+
return of(type, data.getBytes(StandardCharsets.UTF_8));
4064
}
4165

42-
private ByteArrayContent(byte[] data) {
66+
private ByteArrayContent(final ContentFileType type, final byte[] data) {
67+
super(type);
4368
this.data = data;
4469
}
4570

exist-core/src/main/java/org/exist/util/io/ContentFile.java

Lines changed: 48 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
*
@@ -19,7 +43,6 @@
1943
* License along with this library; if not, write to the Free Software
2044
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2145
*/
22-
2346
package org.exist.util.io;
2447

2548
import java.io.ByteArrayInputStream;
@@ -32,6 +55,30 @@
3255
*/
3356
public interface ContentFile extends AutoCloseable {
3457

58+
enum ContentFileType {
59+
/**
60+
* The file contains content of which the format is unknown.
61+
*/
62+
UNKNOWN,
63+
64+
/**
65+
* The file contains content that has been serialized using the XDM method.
66+
*/
67+
XDM_SERIALIZATION,
68+
69+
/**
70+
* The file contains content that has been serialized using the XQJ method.
71+
*/
72+
XQJ_SERIALIZATION;
73+
}
74+
75+
/**
76+
* Get the type of the Content File.
77+
*
78+
* @return the type of the Content File.
79+
*/
80+
ContentFileType getType();
81+
3582
@Override
3683
/**
3784
* Closes all resource held by the implementation as open files or off HEAP memory as example.

exist-core/src/main/java/org/exist/util/io/ContentFilePoolObjectFactory.java

Lines changed: 26 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
*
@@ -19,15 +43,14 @@
1943
* License along with this library; if not, write to the Free Software
2044
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2145
*/
22-
2346
package org.exist.util.io;
2447

2548
import org.apache.commons.pool2.BasePooledObjectFactory;
2649
import org.apache.commons.pool2.PooledObject;
2750
import org.apache.commons.pool2.impl.DefaultPooledObject;
2851

2952
/**
30-
* Object factory responsible for creating {@link ContentFile} instances and wrap thos into pool objects.
53+
* Object factory responsible for creating {@link ContentFile} instances and wrap those into pool objects.
3154
*
3255
* @author <a href="mailto:[email protected]">Patrick Reinhart</a>
3356
*/
@@ -48,7 +71,7 @@ public ContentFilePoolObjectFactory(final TemporaryFileManager tempFileManager,
4871

4972
@Override
5073
public ContentFile create() throws Exception {
51-
return new VirtualTempPath(inMemorySize, tempFileManager);
74+
return new VirtualTempPath(ContentFile.ContentFileType.UNKNOWN, inMemorySize, tempFileManager);
5275
}
5376

5477
@Override

exist-core/src/main/java/org/exist/util/io/VirtualTempPath.java

Lines changed: 29 additions & 5 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
*
@@ -19,7 +43,6 @@
1943
* License along with this library; if not, write to the Free Software
2044
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2145
*/
22-
2346
package org.exist.util.io;
2447

2548
import java.io.*;
@@ -37,7 +60,7 @@
3760
* @author <a href="mailto:[email protected]">Patrick Reinhart</a>
3861
*/
3962
@ThreadSafe
40-
public final class VirtualTempPath implements ContentFile {
63+
public final class VirtualTempPath extends AbstractContentFile {
4164
public static final int DEFAULT_IN_MEMORY_SIZE = 4 * 1024 * 1024; // 4 MB
4265

4366
private static final byte[] EMPTY_BUFFER = new byte[0];
@@ -52,11 +75,12 @@ public final class VirtualTempPath implements ContentFile {
5275
@GuardedBy("lock")
5376
private Path contentFile;
5477

55-
public VirtualTempPath(TemporaryFileManager tempFileManager) {
56-
this(DEFAULT_IN_MEMORY_SIZE, tempFileManager);
78+
public VirtualTempPath(final ContentFileType type, final TemporaryFileManager tempFileManager) {
79+
this(type, DEFAULT_IN_MEMORY_SIZE, tempFileManager);
5780
}
5881

59-
public VirtualTempPath(int inMemorySize, TemporaryFileManager tempFileManager) {
82+
public VirtualTempPath(final ContentFileType type, final int inMemorySize, final TemporaryFileManager tempFileManager) {
83+
super(type);
6084
this.inMemorySize = inMemorySize;
6185
this.lock = new StampedLock();
6286
this.tempFileManager = tempFileManager;

0 commit comments

Comments
 (0)