Skip to content
Open
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
22 changes: 7 additions & 15 deletions exist-core/src/main/java/org/exist/dom/memtree/DocumentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1658,26 +1658,18 @@ public XQueryContext getContext() {

@Override
public String getBaseURI() {
final Element el = getDocumentElement();
if(el != null) {
final String baseURI = getDocumentElement().getAttributeNS(Namespaces.XML_NS, "base");
if(baseURI != null) {
return baseURI;
}
}
final String docURI = getDocumentURI();
if(docURI != null) {
return docURI;
} else {
if(context!=null && context.isBaseURIDeclared()) {
try {
return context.getBaseURI().getStringValue();
} catch(final XPathException e) {
//TODO : make something !
}
}
if(context != null && context.isBaseURIDeclared()) {
try {
return context.getBaseURI().getStringValue();
} catch(final XPathException e) {
//TODO : make something !
}
return XmldbURI.EMPTY_URI.toString();
}
return XmldbURI.EMPTY_URI.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ public void testGetInScopePrefix() throws IOException, ParserConfigurationExcept
assertEquals(Namespaces.XHTML_NS, namespaceUri);
}

@Test
public void getBaseURI_withDocumentURI() throws IOException, SAXException, ParserConfigurationException {
final DocumentImpl doc;
try(final InputStream is = new UnsynchronizedByteArrayInputStream("<root/>".getBytes(UTF_8))) {
doc = parseExist(is);
}
doc.setDocumentURI("file:///intranet/xsl/template.xsl");
assertEquals("file:///intranet/xsl/template.xsl", doc.getBaseURI());
}

@Test
public void getBaseURI_ignoresXmlBaseOnRoot() throws IOException, SAXException, ParserConfigurationException {
final DocumentImpl doc;
try(final InputStream is = new UnsynchronizedByteArrayInputStream(
"<root xml:base=\"http://example.org/\"/>".getBytes(UTF_8))) {
doc = parseExist(is);
}
doc.setDocumentURI("file:///intranet/xsl/template.xsl");
assertEquals("file:///intranet/xsl/template.xsl", doc.getBaseURI());
}

@Test
public void getBaseURI_noDocumentURI() throws IOException, SAXException, ParserConfigurationException {
final DocumentImpl doc;
try(final InputStream is = new UnsynchronizedByteArrayInputStream("<root/>".getBytes(UTF_8))) {
doc = parseExist(is);
}
assertEquals("", doc.getBaseURI());
}

private Document parseXerces(final InputStream is) throws ParserConfigurationException, SAXException, IOException {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Expand Down
Loading