Skip to content

Commit be1531b

Browse files
committed
[refactor] dom.peristent.ElementImpl
- refactor calculateBaseURI to use getAttributeNodeNS to differentiate between unset and empty attribute value - annotate functions with Nonnull that override Nonnull methods from org.w3c.dom.ElementImpl - remove deprecated function _getAttributeNS, - return "" instead on misleading constant in getAttributeNS
1 parent a097a28 commit be1531b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import javax.xml.XMLConstants;
5555
import javax.xml.stream.XMLStreamConstants;
5656
import javax.xml.stream.XMLStreamException;
57+
import javax.annotation.Nonnull;
5758
import java.io.DataInputStream;
5859
import java.io.DataOutputStream;
5960
import java.io.IOException;
@@ -795,22 +796,17 @@ public void setAttributes(final short attribNum) {
795796
}
796797

797798
@Override
799+
@Nonnull
798800
public String getAttribute(final String name) {
799801
final Attr attr = findAttribute(name);
800802
return attr != null ? attr.getValue() : "";
801803
}
802804

803805
@Override
806+
@Nonnull
804807
public String getAttributeNS(final String namespaceURI, final String localName) {
805808
final Attr attr = findAttribute(new QName(localName, namespaceURI));
806-
return attr != null ? attr.getValue() : XMLConstants.NULL_NS_URI;
807-
//XXX: if not present must return null
808-
}
809-
810-
@Deprecated //move as soon as getAttributeNS null issue resolved
811-
public String _getAttributeNS(final String namespaceURI, final String localName) {
812-
final Attr attr = findAttribute(new QName(localName, namespaceURI));
813-
return attr != null ? attr.getValue() : null;
809+
return attr != null ? attr.getValue() : "";
814810
}
815811

816812
@Override
@@ -951,6 +947,7 @@ public boolean hasChildNodes() {
951947
}
952948

953949
@Override
950+
@Nonnull
954951
public NodeList getChildNodes() {
955952
final int childNodesLen = children - attributes;
956953
final org.exist.dom.NodeListImpl childList = new org.exist.dom.NodeListImpl(childNodesLen);
@@ -1008,6 +1005,7 @@ private void getChildren(final boolean includeAttributes, final org.exist.dom.No
10081005
}
10091006

10101007
@Override
1008+
@Nonnull
10111009
public NodeList getElementsByTagName(final String name) {
10121010
if(name != null && name.equals(QName.WILDCARD)) {
10131011
return getElementsByTagName(new QName.WildcardLocalPartQName(XMLConstants.DEFAULT_NS_PREFIX));
@@ -1021,6 +1019,7 @@ public NodeList getElementsByTagName(final String name) {
10211019
}
10221020

10231021
@Override
1022+
@Nonnull
10241023
public NodeList getElementsByTagNameNS(final String namespaceURI, final String localName) {
10251024
final boolean wildcardNS = namespaceURI != null && namespaceURI.equals(QName.WILDCARD);
10261025
final boolean wildcardLocalPart = localName != null && localName.equals(QName.WILDCARD);
@@ -1977,9 +1976,9 @@ public String getBaseURI() {
19771976
private XmldbURI calculateBaseURI() {
19781977
XmldbURI baseURI = null;
19791978

1980-
final String nodeBaseURI = _getAttributeNS(Namespaces.XML_NS, "base");
1979+
final Node nodeBaseURI = getAttributeNodeNS(Namespaces.XML_NS, "base");
19811980
if(nodeBaseURI != null) {
1982-
baseURI = XmldbURI.create(nodeBaseURI, false);
1981+
baseURI = XmldbURI.create(nodeBaseURI.getNodeValue(), false);
19831982
if(baseURI.isAbsolute()) {
19841983
return baseURI;
19851984
}
@@ -1991,7 +1990,7 @@ private XmldbURI calculateBaseURI() {
19911990
baseURI = ((ElementImpl) parent).calculateBaseURI();
19921991
} else {
19931992
XmldbURI parentsBaseURI = ((ElementImpl) parent).calculateBaseURI();
1994-
if(nodeBaseURI.isEmpty()) {
1993+
if(nodeBaseURI.getNodeValue().isEmpty()) {
19951994
baseURI = parentsBaseURI;
19961995
} else {
19971996
if(parentsBaseURI.toString().endsWith("/") || !parentsBaseURI.toString().contains("/")){

0 commit comments

Comments
 (0)