Skip to content

Commit 519e35a

Browse files
authored
Merge pull request #9 from evolvedbinary/7.x.x/hotfix/all-document-children
[7.x.x] Make sure that all Child Nodes of a Document Node are accessible
2 parents dcc8782 + 9a330e5 commit 519e35a

File tree

108 files changed

+3458
-1050
lines changed

Some content is hidden

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

108 files changed

+3458
-1050
lines changed

exist-core/pom.xml

Lines changed: 108 additions & 2 deletions
Large diffs are not rendered by default.

exist-core/src/main/java/org/exist/backup/ZipWriter.java

Lines changed: 29 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
*
@@ -21,6 +45,8 @@
2145
*/
2246
package org.exist.backup;
2347

48+
import org.apache.commons.io.output.StringBuilderWriter;
49+
2450
import java.io.*;
2551
import java.nio.charset.StandardCharsets;
2652
import java.nio.file.Files;
@@ -38,7 +64,7 @@ public class ZipWriter implements BackupWriter
3864
{
3965
private String currentPath;
4066
private final ZipOutputStream out;
41-
private StringWriter contents;
67+
private StringBuilderWriter contents;
4268
private boolean dataWritten = false;
4369

4470
public ZipWriter(final String zipFile, final String collection) throws IOException
@@ -53,9 +79,9 @@ public ZipWriter(final Path zipFile, final String collection) throws IOException
5379
currentPath = collection;
5480
}
5581

56-
public Writer newContents() throws IOException
82+
public Writer newContents()
5783
{
58-
contents = new StringWriter();
84+
contents = new StringBuilderWriter();
5985
return( contents );
6086
}
6187

exist-core/src/main/java/org/exist/client/ClientFrame.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*/
4646
package org.exist.client;
4747

48+
import org.apache.commons.io.output.StringBuilderWriter;
4849
import org.exist.SystemProperties;
4950
import org.exist.backup.Backup;
5051
import org.exist.backup.CreateBackupDialog;
@@ -1750,16 +1751,17 @@ public static void showErrorMessage(final String message, final Throwable t) {
17501751
msgArea.setEditable(false);
17511752
msgArea.setBackground(null);
17521753
if (t != null) {
1753-
final StringWriter out = new StringWriter();
1754-
final PrintWriter writer = new PrintWriter(out);
1755-
t.printStackTrace(writer);
1756-
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
1757-
stacktrace.setBackground(null);
1758-
stacktrace.setEditable(false);
1759-
scroll = new JScrollPane(stacktrace);
1760-
scroll.setPreferredSize(new Dimension(250, 300));
1761-
scroll.setBorder(BorderFactory
1754+
try (final StringBuilderWriter out = new StringBuilderWriter();
1755+
final PrintWriter writer = new PrintWriter(out)) {
1756+
t.printStackTrace(writer);
1757+
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
1758+
stacktrace.setBackground(null);
1759+
stacktrace.setEditable(false);
1760+
scroll = new JScrollPane(stacktrace);
1761+
scroll.setPreferredSize(new Dimension(250, 300));
1762+
scroll.setBorder(BorderFactory
17621763
.createTitledBorder(Messages.getString("ClientFrame.215"))); //$NON-NLS-1$
1764+
}
17631765
}
17641766
final JOptionPane optionPane = new JOptionPane();
17651767
optionPane.setMessage(new Object[]{msgArea, scroll});
@@ -1783,7 +1785,7 @@ public static int showErrorMessageQuery(final String message, final Throwable t)
17831785

17841786
JScrollPane scrollStacktrace = null;
17851787
if (t != null) {
1786-
try (final StringWriter out = new StringWriter();
1788+
try (final StringBuilderWriter out = new StringBuilderWriter();
17871789
final PrintWriter writer = new PrintWriter(out)) {
17881790
t.printStackTrace(writer);
17891791
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
@@ -1795,8 +1797,6 @@ public static int showErrorMessageQuery(final String message, final Throwable t)
17951797
scrollStacktrace.setPreferredSize(new Dimension(600, 300));
17961798
scrollStacktrace.setBorder(BorderFactory
17971799
.createTitledBorder(Messages.getString("ClientFrame.218"))); //$NON-NLS-1$
1798-
} catch (final IOException ioe) {
1799-
ioe.printStackTrace();
18001800
}
18011801
}
18021802

exist-core/src/main/java/org/exist/client/DocumentView.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import javax.swing.border.BevelBorder;
8484
import javax.xml.transform.OutputKeys;
8585

86+
import org.apache.commons.io.output.StringBuilderWriter;
8687
import org.exist.security.Account;
8788
import org.exist.storage.ElementIndex;
8889
import org.exist.util.ProgressIndicator;
@@ -186,16 +187,17 @@ private static void showErrorMessage(String message, Throwable t) {
186187
msgArea.setEditable(false);
187188
msgArea.setBackground(null);
188189
if (t != null) {
189-
final StringWriter out = new StringWriter();
190-
final PrintWriter writer = new PrintWriter(out);
191-
t.printStackTrace(writer);
192-
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
193-
stacktrace.setBackground(null);
194-
stacktrace.setEditable(false);
195-
scroll = new JScrollPane(stacktrace);
196-
scroll.setPreferredSize(new Dimension(250, 300));
197-
scroll.setBorder(BorderFactory
190+
try (final StringBuilderWriter out = new StringBuilderWriter();
191+
final PrintWriter writer = new PrintWriter(out)) {
192+
t.printStackTrace(writer);
193+
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
194+
stacktrace.setBackground(null);
195+
stacktrace.setEditable(false);
196+
scroll = new JScrollPane(stacktrace);
197+
scroll.setPreferredSize(new Dimension(250, 300));
198+
scroll.setBorder(BorderFactory
198199
.createTitledBorder("Exception Stacktrace:")); //$NON-NLS-1$
200+
}
199201
}
200202
final JOptionPane optionPane = new JOptionPane();
201203
optionPane.setMessage(new Object[]{msgArea, scroll});

exist-core/src/main/java/org/exist/client/QueryDialog.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import javax.swing.event.PopupMenuListener;
8787
import javax.xml.transform.OutputKeys;
8888

89+
import org.apache.commons.io.output.StringBuilderWriter;
8990
import org.exist.security.PermissionDeniedException;
9091
import org.exist.util.Holder;
9192
import org.exist.xmldb.EXistXQueryService;
@@ -538,9 +539,10 @@ private void compileQuery() {
538539
tCompiled = t1 - t0;
539540

540541
// In this way we can see the parsed structure meanwhile the query is
541-
final StringWriter writer = new StringWriter();
542-
service.dump(compiled, writer);
543-
exprDisplay.setText(writer.toString());
542+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
543+
service.dump(compiled, writer);
544+
exprDisplay.setText(writer.toString());
545+
}
544546
resultTabs.setSelectedComponent(exprDisplayScrollPane);
545547

546548
statusMessage.setText(Messages.getString(QUERY_DIALOG_COMPILATION) + ": " + tCompiled + "ms");
@@ -610,9 +612,10 @@ public void run() {
610612
tCompiled = t1 - t0;
611613

612614
// In this way we can see the parsed structure meanwhile the query is
613-
StringWriter writer = new StringWriter();
614-
service.dump(compiled, writer);
615-
exprDisplay.setText(writer.toString());
615+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
616+
service.dump(compiled, writer);
617+
exprDisplay.setText(writer.toString());
618+
}
616619

617620
result = service.execute(compiled);
618621
tResult = System.currentTimeMillis() - t1;
@@ -623,9 +626,10 @@ public void run() {
623626
}
624627

625628
// jmfg: Is this still needed? I don't think so
626-
writer = new StringWriter();
627-
service.dump(compiled, writer);
628-
exprDisplay.setText(writer.toString());
629+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
630+
service.dump(compiled, writer);
631+
exprDisplay.setText(writer.toString());
632+
}
629633

630634
statusMessage.setText(Messages.getString("QueryDialog.retrievingmessage"));
631635
final int howmany = count.getNumber().intValue();

exist-core/src/main/java/org/exist/config/Configurator.java

Lines changed: 34 additions & 11 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
*
@@ -47,6 +71,7 @@
4771
import javax.xml.parsers.SAXParser;
4872
import javax.xml.parsers.SAXParserFactory;
4973

74+
import org.apache.commons.io.output.StringBuilderWriter;
5075
import org.apache.logging.log4j.LogManager;
5176
import org.apache.logging.log4j.Logger;
5277
import org.exist.Database;
@@ -1267,24 +1292,22 @@ public static DocumentImpl save(final DBBroker broker, final Configurable instan
12671292
protected static final Set<FullXmldbURI> saving = new ConcurrentSkipListSet<>();
12681293

12691294
public static DocumentImpl save(final Configurable instance, final DBBroker broker, final Collection collection, final XmldbURI uri) throws IOException, ConfigurationException {
1270-
1271-
final StringWriter writer = new StringWriter();
1272-
final SAXSerializer serializer = new SAXSerializer(writer, null);
1273-
1274-
try {
1295+
final String data;
1296+
try (final StringBuilderWriter writer = new StringBuilderWriter()) {
1297+
final SAXSerializer serializer = new SAXSerializer(writer, null);
1298+
12751299
serializer.startDocument();
12761300
serialize(instance, serializer);
12771301
serializer.endDocument();
1278-
1302+
1303+
data = writer.toString();
1304+
if (data == null || data.isEmpty()) {
1305+
return null;
1306+
}
12791307
} catch (final SAXException saxe) {
12801308
throw new ConfigurationException(saxe.getMessage(), saxe);
12811309
}
12821310

1283-
final String data = writer.toString();
1284-
if (data == null || data.length() == 0) {
1285-
return null;
1286-
}
1287-
12881311
FullXmldbURI fullURI = null;
12891312
final BrokerPool pool = broker.getBrokerPool();
12901313
final TransactionManager transact = pool.getTransactionManager();

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

Lines changed: 60 additions & 8 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
*
@@ -46,6 +70,26 @@ public boolean add(final Node node) {
4670
return super.add(node);
4771
}
4872

73+
/**
74+
* Add all elements of the other NodeListImpl to
75+
* this NodeListImpl.
76+
*
77+
* @param other NodeListImpl to add.
78+
*
79+
* @return true if the list was modified, false otherwise.
80+
*/
81+
public boolean addAll(final NodeListImpl other) {
82+
if (other == null) {
83+
return false;
84+
}
85+
86+
if (other.isEmpty()) {
87+
return false;
88+
}
89+
90+
return addAll((ArrayList<Node>) other);
91+
}
92+
4993
/**
5094
* Add all elements of the other NodeList to
5195
* this NodeList
@@ -54,18 +98,26 @@ public boolean add(final Node node) {
5498
* if none or only some were added.
5599
*/
56100
public boolean addAll(final NodeList other) {
101+
if (other == null) {
102+
return false;
103+
}
104+
105+
if (other instanceof NodeListImpl) {
106+
return addAll((NodeListImpl) other);
107+
}
108+
57109
if (other.getLength() == 0) {
58110
return false;
59-
} else {
60-
boolean result = true;
61-
for(int i = 0; i < other.getLength(); i++) {
62-
if(!add(other.item(i))) {
63-
result = false;
64-
break;
65-
}
111+
}
112+
113+
boolean result = true;
114+
for (int i = 0; i < other.getLength(); i++) {
115+
if (!add(other.item(i))) {
116+
result = false;
117+
break;
66118
}
67-
return result;
68119
}
120+
return result;
69121
}
70122

71123
@Override

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

Lines changed: 24 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
*
@@ -280,11 +304,6 @@ public String getStringValue() {
280304
return getData();
281305
}
282306

283-
@Override
284-
public Node getFirstChild() {
285-
return null;
286-
}
287-
288307
@Override
289308
public void selectAttributes(final NodeTest test, final Sequence result)
290309
throws XPathException {

0 commit comments

Comments
 (0)