Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions exist-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@
<include>src/test/resources/log4j2.xml</include>
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
<include>src/main/xjb/rest-api.xjb</include>
<include>src/test/xquery/base-uri.xql</include>
<include>src/test/xquery/parenthesizedLocationStep.xml</include>
<include>src/test/xquery/tail-recursion.xml</include>
<include>src/test/xquery/maps/maps.xqm</include>
Expand Down Expand Up @@ -893,6 +894,7 @@
<include>src/main/java/org/exist/dom/QName.java</include>
<include>src/main/java/org/exist/dom/memtree/AbstractCharacterData.java</include>
<include>src/main/java/org/exist/dom/memtree/AttrImpl.java</include>
<include>src/main/java/org/exist/dom/memtree/CommentImpl.java</include>
<include>src/main/java/org/exist/dom/memtree/DocumentBuilderReceiver.java</include>
<include>src/main/java/org/exist/dom/memtree/DocumentImpl.java</include>
<include>src/test/java/org/exist/dom/memtree/DocumentImplTest.java</include>
Expand Down Expand Up @@ -923,6 +925,7 @@
<include>src/main/java/org/exist/dom/persistent/EmptyNodeSet.java</include>
<include>src/main/java/org/exist/dom/persistent/LockToken.java</include>
<include>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</include>
<include>src/main/java/org/exist/dom/persistent/NodeImpl.java</include>
<include>src/main/java/org/exist/dom/persistent/NodeProxy.java</include>
<include>src/main/java/org/exist/dom/persistent/NodeSet.java</include>
<include>src/test/java/org/exist/dom/persistent/NodeTest.java</include>
Expand Down Expand Up @@ -1510,6 +1513,7 @@
<exclude>src/test/resources/log4j2.xml</exclude>
<exclude>src/test/resources/standalone-webapp/WEB-INF/web.xml</exclude>
<exclude>src/main/xjb/rest-api.xjb</exclude>
<exclude>src/test/xquery/base-uri.xql</exclude>
<exclude>src/test/xquery/binary-value.xqm</exclude>
<exclude>src/test/xquery/instance-of.xqm</exclude>
<exclude>src/test/xquery/operator-mapping.xqm</exclude>
Expand Down Expand Up @@ -1612,6 +1616,7 @@
<exclude>src/main/java/org/exist/dom/QName.java</exclude>
<exclude>src/main/java/org/exist/dom/memtree/AbstractCharacterData.java</exclude>
<exclude>src/main/java/org/exist/dom/memtree/AttrImpl.java</exclude>
<include>src/main/java/org/exist/dom/memtree/CommentImpl.java</include>
<exclude>src/main/java/org/exist/dom/memtree/DocumentBuilderReceiver.java</exclude>
<exclude>src/main/java/org/exist/dom/memtree/DocumentImpl.java</exclude>
<exclude>src/test/java/org/exist/dom/memtree/DocumentImplTest.java</exclude>
Expand Down Expand Up @@ -1650,6 +1655,7 @@
<exclude>src/main/java/org/exist/dom/persistent/EmptyNodeSet.java</exclude>
<exclude>src/main/java/org/exist/dom/persistent/LockToken.java</exclude>
<exclude>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</exclude>
<exclude>src/main/java/org/exist/dom/persistent/NodeImpl.java</exclude>
<exclude>src/main/java/org/exist/dom/persistent/NodeProxy.java</exclude>
<exclude>src/main/java/org/exist/dom/persistent/NodeSet.java</exclude>
<exclude>src/test/java/org/exist/dom/persistent/NodeTest.java</exclude>
Expand Down
8 changes: 5 additions & 3 deletions exist-core/src/main/java/org/exist/dom/memtree/AttrImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.exist.xquery.value.Type;
import org.w3c.dom.*;

import javax.annotation.Nullable;


public class AttrImpl extends NodeImpl implements Attr {

Expand Down Expand Up @@ -90,9 +92,9 @@ public int getType() {
}

@Override
public String getBaseURI() {
final Node parent = document.getNode(document.attrParent[nodeNumber]);
if(parent == null) {
public @Nullable String getBaseURI() {
@Nullable final Node parent = document.getNode(document.attrParent[nodeNumber]);
if (parent == null) {
return null;
}
return parent.getBaseURI();
Expand Down
32 changes: 29 additions & 3 deletions exist-core/src/main/java/org/exist/dom/memtree/CommentImpl.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
/*
* Elemental
* Copyright (C) 2024, Evolved Binary Ltd
*
* admin@evolvedbinary.com
* https://www.evolvedbinary.com | https://www.elemental.xyz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
* The original license header is included below.
*
* =====================================================================
*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
Expand Down Expand Up @@ -29,6 +53,8 @@
import org.w3c.dom.Comment;
import org.w3c.dom.Node;

import javax.annotation.Nullable;

public class CommentImpl extends AbstractCharacterData implements Comment {

public CommentImpl(final DocumentImpl doc, final int nodeNumber) {
Expand All @@ -53,9 +79,9 @@ public AtomicValue atomize() throws XPathException {
}

@Override
public String getBaseURI() {
final Node parent = getParentNode();
if(parent == null) {
public @Nullable String getBaseURI() {
@Nullable final Node parent = getParentNode();
if (parent == null) {
return null;
}
return parent.getBaseURI();
Expand Down
22 changes: 12 additions & 10 deletions exist-core/src/main/java/org/exist/dom/memtree/DocumentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1657,26 +1657,28 @@ public XQueryContext getContext() {
}

@Override
public String getBaseURI() {
final Element el = getDocumentElement();
if(el != null) {
public @Nullable String getBaseURI() {
@Nullable final Element el = getDocumentElement();
if (el != null) {
final String baseURI = getDocumentElement().getAttributeNS(Namespaces.XML_NS, "base");
if(baseURI != null) {
if (!baseURI.isEmpty()) {
return baseURI;
}
}
final String docURI = getDocumentURI();
if(docURI != null) {

@Nullable final String docURI = getDocumentURI();
if (docURI != null) {
return docURI;
} else {
if(context!=null && context.isBaseURIDeclared()) {
if (context != null && context.isBaseURIDeclared()) {
try {
return context.getBaseURI().getStringValue();
} catch(final XPathException e) {
//TODO : make something !
} catch (final XPathException e) {
// no-op
}
}
return XmldbURI.EMPTY_URI.toString();

return null;
}
}

Expand Down
42 changes: 24 additions & 18 deletions exist-core/src/main/java/org/exist/dom/memtree/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.exist.xquery.value.ValueSequence;
import org.w3c.dom.*;

import javax.annotation.Nullable;
import javax.xml.XMLConstants;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -619,18 +620,18 @@ public int getItemType() {
}

@Override
public String getBaseURI() {
final XmldbURI baseURI = calculateBaseURI();
if(baseURI != null) {
public @Nullable String getBaseURI() {
@Nullable final XmldbURI baseURI = calculateBaseURI();
if (baseURI != null) {
return baseURI.toString();
}

return "";//UNDERSTAND: is it ok?
return null;
}

// NOTE(AR) please keep in sync with org.exist.dom.persistent.ElementImpl
private XmldbURI calculateBaseURI() {
XmldbURI baseURI = null;
private @Nullable XmldbURI calculateBaseURI() {
@Nullable XmldbURI baseURI = null;

final String nodeBaseURI = getAttributeNS(Namespaces.XML_NS, "base");
if (!nodeBaseURI.isEmpty()) {
Expand All @@ -648,27 +649,32 @@ private XmldbURI calculateBaseURI() {

if (parent != -1) {
if (nodeBaseURI.isEmpty()) {
baseURI = ((ElementImpl) document.getNode(parent))
.calculateBaseURI();
baseURI = ((ElementImpl) document.getNode(parent)).calculateBaseURI();
} else {
final XmldbURI parentsBaseURI = ((ElementImpl) document.getNode(parent)).calculateBaseURI();
if (parentsBaseURI.toString().endsWith("/") || !parentsBaseURI.toString().contains("/")) {
baseURI = parentsBaseURI.append(baseURI);
@Nullable final XmldbURI parentsBaseURI = ((ElementImpl) document.getNode(parent)).calculateBaseURI();
if (parentsBaseURI == null) {
baseURI = null;
} else {
// there is a filename, remove it
baseURI = parentsBaseURI.removeLastSegment().append(baseURI);
if (parentsBaseURI.toString().endsWith("/") || !parentsBaseURI.toString().contains("/")) {
baseURI = parentsBaseURI.append(baseURI);
} else {
// there is a filename, remove it
baseURI = parentsBaseURI.removeLastSegment().append(baseURI);
}
}
}
} else {
if (nodeBaseURI.isEmpty()) {
return XmldbURI.create(getOwnerDocument().getBaseURI(), false);
@Nullable final String docBaseURI = getOwnerDocument().getBaseURI();
if (docBaseURI == null) {
baseURI = null;
} else if (nodeBaseURI.isEmpty()) {
baseURI = XmldbURI.create(docBaseURI, false);
} else if (nodeNumber != 1) {
final String docBaseURI = getOwnerDocument().getBaseURI();
if (docBaseURI.endsWith("/")) {
baseURI = XmldbURI.create(getOwnerDocument().getBaseURI(), false);
baseURI = XmldbURI.create(docBaseURI, false);
baseURI.append(baseURI);
} else {
baseURI = XmldbURI.create(getOwnerDocument().getBaseURI(), false);
baseURI = XmldbURI.create(docBaseURI, false);
baseURI = baseURI.removeLastSegment();
baseURI.append(baseURI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public void removeDuplicates() {
}

@Override
public String getBaseURI() {
public @Nullable String getBaseURI() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;

import javax.annotation.Nullable;


public class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction {

Expand Down Expand Up @@ -102,37 +104,12 @@ public void setData(final String data) throws DOMException {
}

@Override
public String getBaseURI() {
String baseURI = "";
int parent = -1;
int test = document.getParentNodeFor(nodeNumber);

if(document.nodeKind[test] != Node.DOCUMENT_NODE) {
parent = test;
}

// fixme! Testa med 0/ljo
while((parent != -1) && (document.getNode(parent).getBaseURI() != null)) {

if(baseURI.isEmpty()) {
baseURI = document.getNode(parent).getBaseURI();
} else {
baseURI = document.getNode(parent).getBaseURI() + "/" + baseURI;
}

test = document.getParentNodeFor(parent);

if(document.nodeKind[test] == Node.DOCUMENT_NODE) {
return (baseURI);
} else {
parent = test;
}
}

if(baseURI.isEmpty()) {
baseURI = getOwnerDocument().getBaseURI();
public @Nullable String getBaseURI() {
@Nullable final Node parent = getParentNode();
if (parent == null) {
return null;
}
return (baseURI);
return parent.getBaseURI();
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions exist-core/src/main/java/org/exist/dom/memtree/TextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import org.exist.xquery.Expression;
import org.exist.xquery.value.Type;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.Text;

import javax.annotation.Nullable;


public class TextImpl extends AbstractCharacterData implements Text {

Expand All @@ -42,6 +45,15 @@ public int getItemType() {
return Type.TEXT;
}

@Override
public @Nullable String getBaseURI() {
@Nullable final Node parent = getParentNode();
if (parent == null) {
return null;
}
return parent.getBaseURI();
}

@Override
public Text splitText(final int offset) throws DOMException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.exist.xquery.Expression;
import org.w3c.dom.*;

import javax.annotation.Nullable;
import javax.xml.XMLConstants;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -421,9 +422,9 @@ public boolean isId() {
}

@Override
public String getBaseURI() {
final Element e = getOwnerElement();
if(e != null) {
public @Nullable String getBaseURI() {
@Nullable final Element e = getOwnerElement();
if (e != null) {
return e.getBaseURI();
}
return null;
Expand Down
12 changes: 12 additions & 0 deletions exist-core/src/main/java/org/exist/dom/persistent/CommentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.w3c.dom.Comment;
import org.w3c.dom.Node;

import javax.annotation.Nullable;

import static java.nio.charset.StandardCharsets.UTF_8;

public class CommentImpl extends AbstractCharacterData<CommentImpl> implements Comment {
Expand Down Expand Up @@ -86,6 +88,16 @@ public String toString() {
return "<!-- " + cdata.toString() + " -->";
}

@Override
public @Nullable String getBaseURI() {
@Nullable final Node parent = getParentNode();
if (parent != null) {
return parent.getBaseURI();
} else {
return null;
}
}

/**
* Serializes a (persistent DOM) Comment to a byte array
*
Expand Down
Loading
Loading