Skip to content

Commit 90e8023

Browse files
authored
Merge pull request #23 from evolvedbinary/7.x.x/hotfix/binary-field-types
[7.x.x] Correct the data problems with Fields in the Lucene Full Text Index
2 parents 030537c + 5a1586b commit 90e8023

File tree

80 files changed

+7094
-1303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+7094
-1303
lines changed

exist-core/pom.xml

Lines changed: 114 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.exist.security.SecurityManager;
5555
import org.exist.storage.*;
5656
import org.exist.storage.io.VariableByteInput;
57-
import org.exist.storage.io.VariableByteOutputStream;
57+
import org.exist.storage.io.VariableByteOutput;
5858
import org.exist.storage.lock.*;
5959
import org.exist.storage.lock.Lock.LockMode;
6060
import org.exist.storage.txn.Txn;
@@ -1207,7 +1207,7 @@ BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, BinaryDocumen
12071207
* @throws IOException in case of I/O errors
12081208
12091209
*/
1210-
@EnsureContainerLocked(mode=READ_LOCK) void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException;
1210+
@EnsureContainerLocked(mode=READ_LOCK) void serialize(final VariableByteOutput outputStream) throws IOException, LockException;
12111211

12121212
@Override void close();
12131213

exist-core/src/main/java/org/exist/collections/LockedCollection.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
*
@@ -29,7 +53,7 @@
2953
import org.exist.security.PermissionDeniedException;
3054
import org.exist.security.Subject;
3155
import org.exist.storage.*;
32-
import org.exist.storage.io.VariableByteOutputStream;
56+
import org.exist.storage.io.VariableByteOutput;
3357
import org.exist.storage.lock.Lock;
3458
import org.exist.storage.lock.LockedDocumentMap;
3559
import org.exist.storage.lock.ManagedCollectionLock;
@@ -473,7 +497,7 @@ public BinaryDocument addBinaryResource(final Txn transaction, final DBBroker br
473497
}
474498

475499
@Override
476-
public void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException {
500+
public void serialize(final VariableByteOutput outputStream) throws IOException, LockException {
477501
collection.serialize(outputStream);
478502
}
479503

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
import org.exist.security.Subject;
7373
import org.exist.storage.*;
7474
import org.exist.storage.io.VariableByteInput;
75-
import org.exist.storage.io.VariableByteOutputStream;
75+
import org.exist.storage.io.VariableByteOutput;
7676
import org.exist.storage.lock.*;
7777
import org.exist.storage.lock.Lock.LockMode;
7878
import org.exist.storage.lock.Lock.LockType;
@@ -195,7 +195,7 @@ private MutableCollection(final DBBroker broker, final int collectionId,
195195
/**
196196
* Deserializes a Collection object
197197
*
198-
* Counterpart method to {@link #serialize(VariableByteOutputStream)}
198+
* Counterpart method to {@link #serialize(VariableByteOutput)}
199199
*
200200
* @param broker The database broker
201201
* @param path The path of the Collection
@@ -884,7 +884,7 @@ public Iterator<DocumentImpl> iteratorNoLock(final DBBroker broker) throws Permi
884884
* @param outputStream The output stream to write the collection contents to
885885
*/
886886
@Override
887-
public void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException {
887+
public void serialize(final VariableByteOutput outputStream) throws IOException, LockException {
888888
outputStream.writeInt(collectionId);
889889

890890
final int size;
@@ -914,7 +914,7 @@ public void close() {
914914
/**
915915
* Read collection contents from the stream
916916
*
917-
* Counterpart method to {@link #serialize(VariableByteOutputStream)}
917+
* Counterpart method to {@link #serialize(VariableByteOutput)}
918918
*
919919
* @param broker The database broker
920920
* @param path The path of the Collection

exist-core/src/main/java/org/exist/dom/QName.java

Lines changed: 99 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,16 +50,19 @@
2650
import org.exist.util.XMLNames;
2751
import org.exist.xquery.Constants;
2852

53+
import javax.annotation.Nullable;
2954
import javax.xml.XMLConstants;
3055
import java.util.regex.Matcher;
3156
import java.util.regex.Pattern;
3257

3358
import static org.exist.dom.QName.Validity.*;
59+
import static org.exist.util.StringUtil.isNullOrEmpty;
3460

3561
/**
3662
* Represents a QName, consisting of a local name, a namespace URI and a prefix.
3763
*
3864
* @author <a href="mailto:[email protected]">Wolfgang</a>
65+
* @author <a href="mailto:[email protected]">Adam Retter</a>
3966
*/
4067
public class QName implements Comparable<QName> {
4168

@@ -134,7 +161,18 @@ public byte getNameType() {
134161
* @return the string representation of this qualified name.
135162
* */
136163
public String getStringValue() {
137-
return getStringRepresentation(false);
164+
return getStringRepresentation(false, false);
165+
}
166+
167+
/**
168+
* Get an extended string representation of this qualified name.
169+
*
170+
* Will be of the format `local-name`, `{namespace}local-name`, or `{namespace}prefix:local-name`.
171+
*
172+
* @return the string representation of this qualified name.
173+
*/
174+
public String getExtendedStringValue() {
175+
return getStringRepresentation(false, true);
138176
}
139177

140178
/**
@@ -146,23 +184,32 @@ public String getStringValue() {
146184
*/
147185
@Override
148186
public String toString() {
149-
return getStringRepresentation(true);
187+
return getStringRepresentation(true, false);
150188
}
151189

152190
/**
153191
* Get a string representation of this qualified name.
154192
*
155193
* @param showNsWithoutPrefix true if the namespace should be shown even when there is no prefix, false otherwise.
156-
* When shown, it will be output using Clark notation, e.g. `{http://namespace}local-name`.
194+
* When shown, it will be output using Clark notation, e.g. `{namespace}local-name`.
195+
*
196+
* @param extended true if the namespace and prefix should be shown, requires showNsWithoutPrefix == false.
157197
*
158198
* @return the string representation of this qualified name.
159199
*/
160-
private String getStringRepresentation(final boolean showNsWithoutPrefix) {
200+
private String getStringRepresentation(final boolean showNsWithoutPrefix, final boolean extended) {
161201
if (prefix != null && !prefix.isEmpty()) {
162-
return prefix + COLON + localPart;
163-
} else if (showNsWithoutPrefix && namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
202+
if (extended) {
203+
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + prefix + COLON + localPart;
204+
} else {
205+
return prefix + COLON + localPart;
206+
}
207+
}
208+
209+
if (showNsWithoutPrefix && namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
164210
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + localPart;
165211
}
212+
166213
return localPart;
167214
}
168215

@@ -330,6 +377,52 @@ public static QName parse(final String namespaceURI, final String qname) throws
330377
return new QName(qname.substring(p + 1), namespaceURI, qname.substring(0, p));
331378
}
332379

380+
/**
381+
* Extract a QName from a namespace and qualified name string.
382+
*
383+
* @param extendedStringValue a string representation as produced by {@link #getExtendedStringValue()}, i.e.: `local-name`, `{namespace}local-name`, or `{namespace}prefix:local-name`.
384+
* @return The QName
385+
* @throws IllegalQNameException if the qname component is invalid
386+
*/
387+
public static QName parse(String extendedStringValue) throws IllegalQNameException {
388+
if (isNullOrEmpty(extendedStringValue)) {
389+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName is empty");
390+
}
391+
392+
final String namespaceUri;
393+
if (extendedStringValue.charAt(0) == LEFT_BRACE) {
394+
final int idxNsEnd = extendedStringValue.indexOf(RIGHT_BRACE);
395+
if (idxNsEnd == Constants.STRING_NOT_FOUND) {
396+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName, missing right brace: '" + extendedStringValue + "'");
397+
}
398+
namespaceUri = extendedStringValue.substring(1, idxNsEnd);
399+
extendedStringValue = extendedStringValue.substring(idxNsEnd + 1);
400+
} else if (extendedStringValue.indexOf(RIGHT_BRACE) != Constants.STRING_NOT_FOUND) {
401+
throw new IllegalQNameException(ILLEGAL_FORMAT.val, "Illegal extended string QName, missing left brace: '" + extendedStringValue + "'");
402+
} else {
403+
namespaceUri = XMLConstants.NULL_NS_URI;
404+
}
405+
406+
@Nullable final String prefix;
407+
final int idxColon = extendedStringValue.indexOf(COLON);
408+
if (idxColon == Constants.STRING_NOT_FOUND) {
409+
prefix = null;
410+
} else {
411+
prefix = extendedStringValue.substring(0, idxColon);
412+
if (!XMLNames.isNCName(prefix)) {
413+
throw new IllegalQNameException(INVALID_PREFIX.val, "Illegal extended string QName, invalid prefix: '" + extendedStringValue + "'");
414+
}
415+
extendedStringValue = extendedStringValue.substring(idxColon + 1);
416+
}
417+
418+
final String localPart = extendedStringValue;
419+
if (!XMLNames.isNCName(localPart)) {
420+
throw new IllegalQNameException(INVALID_LOCAL_PART.val, "Illegal extended string QName, invalid prefix: '" + extendedStringValue + "'");
421+
}
422+
423+
return new QName(localPart, namespaceUri, prefix);
424+
}
425+
333426
/**
334427
* Parses the given string into a QName. The method uses context to look up
335428
* a namespace URI for an existing prefix.

exist-core/src/main/java/org/exist/dom/persistent/BinaryDocument.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
*
@@ -27,7 +51,7 @@
2751
import org.exist.storage.BrokerPool;
2852
import org.exist.storage.blob.BlobId;
2953
import org.exist.storage.io.VariableByteInput;
30-
import org.exist.storage.io.VariableByteOutputStream;
54+
import org.exist.storage.io.VariableByteOutput;
3155
import org.exist.xmldb.XmldbURI;
3256
import org.exist.xquery.Expression;
3357
import org.w3c.dom.DocumentType;
@@ -167,7 +191,7 @@ public void setBlobId(final BlobId blobId) {
167191
}
168192

169193
@Override
170-
public void write(final VariableByteOutputStream ostream) throws IOException {
194+
public void write(final VariableByteOutput ostream) throws IOException {
171195
ostream.writeInt(getDocId());
172196
ostream.writeUTF(getFileURI().toString());
173197

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import org.exist.security.*;
6060
import org.exist.storage.*;
6161
import org.exist.storage.io.VariableByteInput;
62-
import org.exist.storage.io.VariableByteOutputStream;
62+
import org.exist.storage.io.VariableByteOutput;
6363
import org.exist.storage.lock.EnsureContainerLocked;
6464
import org.exist.storage.lock.EnsureLocked;
6565
import org.exist.storage.txn.Txn;
@@ -859,11 +859,11 @@ public void appendChild(final NodeHandle child) throws DOMException {
859859
/**
860860
* The method <code>write</code>
861861
*
862-
* @param ostream a <code>VariableByteOutputStream</code> value
862+
* @param ostream a <code>VariableByteOutput</code> value
863863
* @throws IOException if an error occurs
864864
*/
865865
@EnsureContainerLocked(mode=READ_LOCK)
866-
public void write(final VariableByteOutputStream ostream) throws IOException {
866+
public void write(final VariableByteOutput ostream) throws IOException {
867867
try {
868868
ostream.writeInt(docId);
869869
ostream.writeUTF(fileURI.toString());
@@ -885,7 +885,7 @@ public void write(final VariableByteOutputStream ostream) throws IOException {
885885
}
886886
}
887887

888-
void writeDocumentAttributes(final SymbolTable symbolTable, final VariableByteOutputStream ostream) throws IOException {
888+
void writeDocumentAttributes(final SymbolTable symbolTable, final VariableByteOutput ostream) throws IOException {
889889
ostream.writeLong(created);
890890
ostream.writeLong(lastModified);
891891
ostream.writeInt(symbolTable.getMimeTypeId(mimeType));

exist-core/src/main/java/org/exist/dom/persistent/DocumentMetadata.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
*
@@ -23,7 +47,7 @@
2347

2448
import org.exist.ResourceMetadata;
2549
import org.exist.storage.io.VariableByteInput;
26-
import org.exist.storage.io.VariableByteOutputStream;
50+
import org.exist.storage.io.VariableByteOutput;
2751
import org.w3c.dom.DocumentType;
2852

2953
import java.io.IOException;
@@ -100,7 +124,7 @@ public void decPageCount() {
100124
}
101125

102126
@Deprecated
103-
public void write(final SymbolTable symbolTable, final VariableByteOutputStream ostream) throws IOException {
127+
public void write(final SymbolTable symbolTable, final VariableByteOutput ostream) throws IOException {
104128
doc.writeDocumentAttributes(symbolTable, ostream);
105129
}
106130

0 commit comments

Comments
 (0)