Skip to content

Commit 39df32e

Browse files
authored
Merge pull request #31 from evolvedbinary/6.x.x/hotfix/all-document-children
[6.x.x] Make sure that all Child Nodes of a Document Node are accessible
2 parents 9118e60 + ec16cce commit 39df32e

File tree

108 files changed

+3442
-1052
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

+3442
-1052
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;
@@ -1782,16 +1783,17 @@ public static void showErrorMessage(final String message, final Throwable t) {
17821783
msgArea.setEditable(false);
17831784
msgArea.setBackground(null);
17841785
if (t != null) {
1785-
final StringWriter out = new StringWriter();
1786-
final PrintWriter writer = new PrintWriter(out);
1787-
t.printStackTrace(writer);
1788-
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
1789-
stacktrace.setBackground(null);
1790-
stacktrace.setEditable(false);
1791-
scroll = new JScrollPane(stacktrace);
1792-
scroll.setPreferredSize(new Dimension(250, 300));
1793-
scroll.setBorder(BorderFactory
1786+
try (final StringBuilderWriter out = new StringBuilderWriter();
1787+
final PrintWriter writer = new PrintWriter(out)) {
1788+
t.printStackTrace(writer);
1789+
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
1790+
stacktrace.setBackground(null);
1791+
stacktrace.setEditable(false);
1792+
scroll = new JScrollPane(stacktrace);
1793+
scroll.setPreferredSize(new Dimension(250, 300));
1794+
scroll.setBorder(BorderFactory
17941795
.createTitledBorder(Messages.getString("ClientFrame.215"))); //$NON-NLS-1$
1796+
}
17951797
}
17961798
final JOptionPane optionPane = new JOptionPane();
17971799
optionPane.setMessage(new Object[]{msgArea, scroll});
@@ -1815,7 +1817,7 @@ public static int showErrorMessageQuery(final String message, final Throwable t)
18151817

18161818
JScrollPane scrollStacktrace = null;
18171819
if (t != null) {
1818-
try (final StringWriter out = new StringWriter();
1820+
try (final StringBuilderWriter out = new StringBuilderWriter();
18191821
final PrintWriter writer = new PrintWriter(out)) {
18201822
t.printStackTrace(writer);
18211823
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
@@ -1827,8 +1829,6 @@ public static int showErrorMessageQuery(final String message, final Throwable t)
18271829
scrollStacktrace.setPreferredSize(new Dimension(600, 300));
18281830
scrollStacktrace.setBorder(BorderFactory
18291831
.createTitledBorder(Messages.getString("ClientFrame.218"))); //$NON-NLS-1$
1830-
} catch (final IOException ioe) {
1831-
ioe.printStackTrace();
18321832
}
18331833
}
18341834

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;
@@ -185,16 +186,17 @@ private static void showErrorMessage(String message, Throwable t) {
185186
msgArea.setEditable(false);
186187
msgArea.setBackground(null);
187188
if (t != null) {
188-
final StringWriter out = new StringWriter();
189-
final PrintWriter writer = new PrintWriter(out);
190-
t.printStackTrace(writer);
191-
final JTextArea stacktrace = new JTextArea(out.toString(), 20, 50);
192-
stacktrace.setBackground(null);
193-
stacktrace.setEditable(false);
194-
scroll = new JScrollPane(stacktrace);
195-
scroll.setPreferredSize(new Dimension(250, 300));
196-
scroll.setBorder(BorderFactory
189+
try (final StringBuilderWriter out = new StringBuilderWriter();
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
197198
.createTitledBorder("Exception Stacktrace:")); //$NON-NLS-1$
199+
}
198200
}
199201
final JOptionPane optionPane = new JOptionPane();
200202
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;
@@ -537,9 +538,10 @@ private void compileQuery() {
537538
tCompiled = t1 - t0;
538539

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

545547
statusMessage.setText(Messages.getString("QueryDialog.Compilation") + ": " + tCompiled + "ms");
@@ -611,9 +613,10 @@ public void run() {
611613
tCompiled = t1 - t0;
612614

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

618621
result = service.execute(compiled);
619622
tResult = System.currentTimeMillis() - t1;
@@ -624,9 +627,10 @@ public void run() {
624627
}
625628

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

631635
statusMessage.setText(Messages.getString("QueryDialog.retrievingmessage"));
632636
Resource resource;

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;
@@ -1268,24 +1293,22 @@ public static DocumentImpl save(final DBBroker broker, final Configurable instan
12681293
protected static final Set<FullXmldbURI> saving = new ConcurrentSkipListSet<>();
12691294

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

1284-
final String data = writer.toString();
1285-
if (data == null || data.length() == 0) {
1286-
return null;
1287-
}
1288-
12891312
FullXmldbURI fullURI = null;
12901313
final BrokerPool pool = broker.getBrokerPool();
12911314
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)