Skip to content

Commit bba9b3c

Browse files
committed
[bugfix] Fix issue with not being able to resolve XSLT import/include from EXPath Packages
1 parent cab6305 commit bba9b3c

File tree

8 files changed

+102
-14
lines changed

8 files changed

+102
-14
lines changed

exist-core/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
<include>src/test/resources/log4j2.xml</include>
699699
<include>src/test/resources-filtered/conf.xml</include>
700700
<include>src/test/resources-filtered/org/exist/storage/statistics/conf.xml</include>
701-
<include>src/test/resources-filtered/org/exist/xquery/functions/transform/conf.xml</include>
701+
<include>src/test/resources-filtered/org/exist/xquery/functions/transform/transform-from-pkg-test.conf.xml</include>
702702
<include>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</include>
703703
<include>src/main/java/org/exist/client/ClientFrame.java</include>
704704
<include>src/main/java/org/exist/client/Connection.java</include>
@@ -782,7 +782,9 @@
782782
<include>src/test/java/org/exist/management/JmxRemoteTest.java</include>
783783
<include>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</include>
784784
<include>src/test/java/org/exist/xquery/XQueryFunctionsTest.java</include>
785+
<include>src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java</include>
785786
<include>src/test/java/org/exist/xquery/value/Base64BinaryValueTypeTest.java</include>
787+
<include>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</include>
786788
<include>src/test/resources/org/exist/validation/catalog.xml</include>
787789
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
788790
<include>src/test/xquery/util/util.xml</include>
@@ -815,7 +817,7 @@
815817
<exclude>src/test/resources/log4j2.xml</exclude>
816818
<exclude>src/test/resources-filtered/conf.xml</exclude>
817819
<exclude>src/test/resources-filtered/org/exist/storage/statistics/conf.xml</exclude>
818-
<exclude>src/test/resources-filtered/org/exist/xquery/functions/transform/conf.xml</exclude>
820+
<exclude>src/test/resources-filtered/org/exist/xquery/functions/transform/transform-from-pkg-test.conf.xml</exclude>
819821
<exclude>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</exclude>
820822
<exclude>src/main/java/org/exist/client/ClientFrame.java</exclude>
821823
<exclude>src/main/java/org/exist/client/Connection.java</exclude>
@@ -900,7 +902,9 @@
900902
<exclude>src/test/java/org/exist/management/JmxRemoteTest.java</exclude>
901903
<exclude>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</exclude>
902904
<exclude>src/test/java/org/exist/xquery/XQueryFunctionsTest.java</exclude>
905+
<exclude>src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java</exclude>
903906
<exclude>src/test/java/org/exist/xquery/value/Base64BinaryValueTypeTest.java</exclude>
907+
<exclude>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</exclude>
904908
<exclude>src/test/resources/org/exist/validation/catalog.xml</exclude>
905909
<exclude>src/test/resources/standalone-webapp/WEB-INF/web.xml</exclude>
906910
<exclude>src/test/xquery/util/util.xml</exclude>

exist-core/src/main/java/org/exist/xslt/EXistURIResolver.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.net.URI;
5151
import java.net.URISyntaxException;
5252
import java.net.URL;
53+
import javax.annotation.Nullable;
5354
import javax.xml.transform.Source;
5455
import javax.xml.transform.TransformerException;
5556
import javax.xml.transform.URIResolver;
@@ -69,18 +70,26 @@
6970

7071
/**
7172
* Implementation of URIResolver which
72-
* will resolve paths from the eXist database
73+
* will resolve paths from the Elemental database
74+
* if they cannot be found we can optionally fallback
75+
* to returning a StreamSource from a URL
7376
*/
7477
public class EXistURIResolver implements URIResolver {
7578

7679
private static final Logger LOG = LogManager.getLogger(EXistURIResolver.class);
7780

7881
final BrokerPool db;
7982
final String basePath;
83+
final boolean fallbackToUrlStreamSource;
8084

8185
public EXistURIResolver(final BrokerPool db, final String docPath) {
86+
this(db, docPath, false);
87+
}
88+
89+
public EXistURIResolver(final BrokerPool db, final String docPath, final boolean fallbackToUrlStreamSource) {
8290
this.db = db;
8391
this.basePath = normalize(docPath);
92+
this.fallbackToUrlStreamSource = fallbackToUrlStreamSource;
8493
if (LOG.isDebugEnabled()) {
8594
LOG.debug("EXistURIResolver base path set to {}", basePath);
8695
}
@@ -146,7 +155,7 @@ private String normalizePath(final String path) {
146155
}
147156

148157
@Override
149-
public Source resolve(final String href, String base) throws TransformerException {
158+
public @Nullable Source resolve(final String href, String base) throws TransformerException {
150159
String path;
151160

152161
if (href.isEmpty()) {
@@ -183,8 +192,12 @@ public Source resolve(final String href, String base) throws TransformerExceptio
183192
if (path.startsWith("/")) {
184193
path = normalizePath(path);
185194
return databaseSource(path);
186-
} else {
195+
196+
} else if (fallbackToUrlStreamSource) {
187197
return urlSource(path);
198+
199+
} else {
200+
return null;
188201
}
189202
}
190203

exist-core/src/main/java/org/exist/xslt/XsltURIResolverHelper.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
*
@@ -54,7 +78,7 @@ public class XsltURIResolverHelper {
5478

5579
if (base != null) {
5680
// database resolver
57-
resolvers.add(new EXistURISchemeURIResolver(new EXistURIResolver(brokerPool, base)));
81+
resolvers.add(new EXistURISchemeURIResolver(new EXistURIResolver(brokerPool, base, false)));
5882
}
5983

6084
// EXpath Pkg resolver

exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java

Lines changed: 27 additions & 6 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,21 +45,18 @@
2145
*/
2246
package org.exist.xquery.functions.transform;
2347

24-
import org.exist.config.TwoDatabasesTest;
25-
import org.exist.repo.AutoDeploymentTrigger;
2648
import org.exist.test.ExistXmldbEmbeddedServer;
2749
import org.junit.*;
2850
import org.xmldb.api.base.ResourceSet;
2951
import org.xmldb.api.base.XMLDBException;
3052

3153
import java.net.URISyntaxException;
32-
import java.net.URL;
3354
import java.nio.file.Path;
3455
import java.nio.file.Paths;
3556

36-
import static com.ibm.icu.impl.Assert.fail;
3757
import static org.junit.Assert.assertEquals;
3858
import static org.junit.Assert.assertNotNull;
59+
import static org.junit.Assert.fail;
3960

4061
/**
4162
* @author <a href="mailto:[email protected]">Adam Retter</a>
@@ -48,9 +69,9 @@ private static Path getConfigFile() {
4869
final String packagePath = TransformFromPkgTest.class.getPackage().getName().replace('.', separator);
4970

5071
try {
51-
return Paths.get(loader.getResource(packagePath + separator + "conf.xml").toURI());
72+
return Paths.get(loader.getResource(packagePath + separator + "transform-from-pkg-test.conf.xml").toURI());
5273
} catch (final URISyntaxException e) {
53-
fail(e);
74+
fail(e.getMessage());
5475
return null;
5576
}
5677
}
File renamed without changes.

extensions/modules/xslfo/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<include>src/test/resources-filtered/conf.xml</include>
190190
<include>src/test/resources/log4j2.xml</include>
191191
<include>src/main/java/org/exist/xquery/modules/xslfo/ApacheFopProcessorAdapter.java</include>
192+
<include>src/main/java/org/exist/xquery/modules/xslfo/RenderXXepProcessorAdapter.java</include>
192193
</includes>
193194
</licenseSet>
194195

@@ -202,6 +203,7 @@
202203
<exclude>src/test/resources-filtered/conf.xml</exclude>
203204
<exclude>src/test/resources/log4j2.xml</exclude>
204205
<exclude>src/main/java/org/exist/xquery/modules/xslfo/ApacheFopProcessorAdapter.java</exclude>
206+
<exclude>src/main/java/org/exist/xquery/modules/xslfo/RenderXXepProcessorAdapter.java</exclude>
205207
</excludes>
206208
</licenseSet>
207209

extensions/modules/xslfo/src/main/java/org/exist/xquery/modules/xslfo/ApacheFopProcessorAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private FOUserAgent setupFOUserAgent(final FOUserAgent foUserAgent, final Proper
185185
private ResourceResolver getResourceResolver(final DBBroker broker, final String baseUri) {
186186
final ResourceResolverFactory.SchemeAwareResourceResolverBuilder builder = ResourceResolverFactory.createSchemeAwareResourceResolverBuilder(ResourceResolverFactory.createDefaultResourceResolver());
187187
final URIResolverAdapter uriResolver = new URIResolverAdapter(
188-
new EXistURISchemeURIResolver(new EXistURIResolver(broker.getBrokerPool(), baseUri))
188+
new EXistURISchemeURIResolver(new EXistURIResolver(broker.getBrokerPool(), baseUri, true))
189189
);
190190
builder.registerResourceResolverForScheme("exist", uriResolver);
191191
builder.registerResourceResolverForScheme("http", uriResolver);

extensions/modules/xslfo/src/main/java/org/exist/xquery/modules/xslfo/RenderXXepProcessorAdapter.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
*
@@ -75,7 +99,7 @@ public Source resolve(final String href, final String base) throws TransformerEx
7599

76100
private static URIResolver init() throws EXistException {
77101
final BrokerPool brokerPool = BrokerPool.getInstance();
78-
return new EXistURISchemeURIResolver(new EXistURIResolver(brokerPool, DEFAULT_BASE_URI));
102+
return new EXistURISchemeURIResolver(new EXistURIResolver(brokerPool, DEFAULT_BASE_URI, true));
79103
}
80104
}
81105

0 commit comments

Comments
 (0)