Skip to content

Commit 7af41bd

Browse files
committed
[bugfix] Fix DOM compliance of in-memory DOM so that Element#getAttribute(String) and Element#getAttributeNS(String, String) return an empty string (and not null) if the attribute does not exist
Closes eXist-db/exist#5672
1 parent 081eaa2 commit 7af41bd

File tree

66 files changed

+1998
-362
lines changed

Some content is hidden

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

66 files changed

+1998
-362
lines changed

exist-core/pom.xml

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

exist-core/src/main/java/org/exist/backup/restore/AppRestoreUtils.java

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

24-
import org.apache.commons.lang3.StringUtils;
2548
import org.apache.logging.log4j.LogManager;
2649
import org.apache.logging.log4j.Logger;
2750
import org.exist.Namespaces;
@@ -44,6 +67,8 @@
4467
import java.io.IOException;
4568
import java.util.*;
4669

70+
import static org.exist.util.StringUtil.isNullOrEmpty;
71+
4772
/**
4873
* Utility to compare the applications contained in a backup with the already
4974
* installed applications in the package repo.
@@ -141,7 +166,7 @@ public void startElement(String uri, String localName, String qName, Attributes
141166
if (PKG_NAMESPACE.equals(uri) && "package".equals(localName)) {
142167
final String version = attributes.getValue("version");
143168
final String name = attributes.getValue("name");
144-
if (StringUtils.isEmpty(version) || StringUtils.isEmpty(name)) {
169+
if (isNullOrEmpty(version) || isNullOrEmpty(name)) {
145170
LOG.warn("Invalid package descriptor for {}", app.getSymbolicPath());
146171
return;
147172
}

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

Lines changed: 25 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
*
@@ -160,7 +184,7 @@ protected void read(final DBBroker broker, final Document doc, final boolean che
160184
} else if (VALIDATION_ELEMENT.equals(node.getLocalName())) {
161185
final Element elem = (Element) node;
162186
final String mode = elem.getAttribute(VALIDATION_MODE_ATTR);
163-
if (mode == null) {
187+
if (mode.isEmpty()) {
164188
LOG.debug("Unable to determine validation mode in {}", srcCollectionURI);
165189
validationMode = XMLReaderObjectFactory.VALIDATION_SETTING.UNKNOWN;
166190
} else {

exist-core/src/main/java/org/exist/collections/triggers/XQueryStartupTrigger.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
*
@@ -23,7 +47,6 @@
2347

2448
import java.util.*;
2549

26-
import org.apache.commons.lang3.StringUtils;
2750
import org.apache.logging.log4j.LogManager;
2851
import org.apache.logging.log4j.Logger;
2952
import org.exist.collections.Collection;
@@ -45,6 +68,9 @@
4568
import org.exist.xquery.XQueryContext;
4669
import org.exist.xquery.value.Sequence;
4770

71+
import static org.exist.util.StringUtil.endsWith;
72+
import static org.exist.util.StringUtil.substringBeforeLast;
73+
4874
/**
4975
* Startup Trigger to fire XQuery scripts during database startup.
5076
*
@@ -124,7 +150,7 @@ private List<String> getScriptsInStartupCollection(DBBroker broker) {
124150

125151
if (isPermissionsOK(document)) {
126152

127-
if (StringUtils.endsWithAny(docPath, XQUERY_EXTENSIONS)) {
153+
if (endsWith(docPath, XQUERY_EXTENSIONS)) {
128154
paths.add(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + docPath);
129155

130156
} else {
@@ -255,7 +281,7 @@ private void executeQuery(DBBroker broker, String path) {
255281
context = new XQueryContext(broker.getBrokerPool());
256282

257283
// Allow use of modules with relative paths
258-
String moduleLoadPath = StringUtils.substringBeforeLast(path, "/");
284+
String moduleLoadPath = substringBeforeLast(path, "/");
259285
context.setModuleLoadPath(moduleLoadPath);
260286

261287
// Compile query

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

Lines changed: 25 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
*
@@ -342,7 +366,7 @@ public Long getPropertyLong(final String name, final Long defaultValue, final bo
342366

343367
public Integer getPropertyMegabytes(String name, Integer defaultValue) {
344368
String cacheMem = element.getAttribute(name);
345-
if (cacheMem != null) {
369+
if (!cacheMem.isEmpty()) {
346370
if (cacheMem.endsWith("M") || cacheMem.endsWith("m")) {
347371
cacheMem = cacheMem.substring(0, cacheMem.length() - 1);
348372
}

0 commit comments

Comments
 (0)