Skip to content

Commit 4b411fc

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

File tree

8 files changed

+102
-11
lines changed

8 files changed

+102
-11
lines changed

exist-core/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@
744744
<include>src/test/resources/log4j2.xml</include>
745745
<include>src/test/resources-filtered/conf.xml</include>
746746
<include>src/test/resources-filtered/org/exist/storage/statistics/conf.xml</include>
747-
<include>src/test/resources-filtered/org/exist/xquery/functions/transform/conf.xml</include>
747+
<include>src/test/resources-filtered/org/exist/xquery/functions/transform/transform-from-pkg-test.conf.xml</include>
748748
<include>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</include>
749749
<include>src/main/java/org/exist/client/ClientFrame.java</include>
750750
<include>src/main/java/org/exist/client/Connection.java</include>
@@ -828,7 +828,9 @@
828828
<include>src/test/java/org/exist/management/JmxRemoteTest.java</include>
829829
<include>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</include>
830830
<include>src/test/java/org/exist/xquery/XQueryFunctionsTest.java</include>
831+
<include>src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java</include>
831832
<include>src/test/java/org/exist/xquery/value/Base64BinaryValueTypeTest.java</include>
833+
<include>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</include>
832834
<include>src/test/resources/org/exist/validation/catalog.xml</include>
833835
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
834836
<include>src/test/xquery/util/util.xml</include>
@@ -861,7 +863,7 @@
861863
<exclude>src/test/resources/log4j2.xml</exclude>
862864
<exclude>src/test/resources-filtered/conf.xml</exclude>
863865
<exclude>src/test/resources-filtered/org/exist/storage/statistics/conf.xml</exclude>
864-
<exclude>src/test/resources-filtered/org/exist/xquery/functions/transform/conf.xml</exclude>
866+
<exclude>src/test/resources-filtered/org/exist/xquery/functions/transform/transform-from-pkg-test.conf.xml</exclude>
865867
<exclude>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</exclude>
866868
<exclude>src/main/java/org/exist/client/ClientFrame.java</exclude>
867869
<exclude>src/main/java/org/exist/client/Connection.java</exclude>
@@ -947,7 +949,9 @@
947949
<exclude>src/test/java/org/exist/management/JmxRemoteTest.java</exclude>
948950
<exclude>src/test/java/org/exist/xmldb/CreateCollectionsTest.java</exclude>
949951
<exclude>src/test/java/org/exist/xquery/XQueryFunctionsTest.java</exclude>
952+
<exclude>src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java</exclude>
950953
<exclude>src/test/java/org/exist/xquery/value/Base64BinaryValueTypeTest.java</exclude>
954+
<exclude>src/main/java/org/exist/xslt/XsltURIResolverHelper.java</exclude>
951955
<exclude>src/test/resources/org/exist/validation/catalog.xml</exclude>
952956
<exclude>src/test/resources/standalone-webapp/WEB-INF/web.xml</exclude>
953957
<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;
@@ -68,18 +69,26 @@
6869

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

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

7780
final BrokerPool db;
7881
final String basePath;
82+
final boolean fallbackToUrlStreamSource;
7983

8084
public EXistURIResolver(final BrokerPool db, final String docPath) {
85+
this(db, docPath, false);
86+
}
87+
88+
public EXistURIResolver(final BrokerPool db, final String docPath, final boolean fallbackToUrlStreamSource) {
8189
this.db = db;
8290
this.basePath = normalize(docPath);
91+
this.fallbackToUrlStreamSource = fallbackToUrlStreamSource;
8392
if (LOG.isDebugEnabled()) {
8493
LOG.debug("EXistURIResolver base path set to {}", basePath);
8594
}
@@ -145,7 +154,7 @@ private String normalizePath(final String path) {
145154
}
146155

147156
@Override
148-
public Source resolve(final String href, String base) throws TransformerException {
157+
public @Nullable Source resolve(final String href, String base) throws TransformerException {
149158
String path;
150159

151160
if (href.isEmpty()) {
@@ -182,8 +191,12 @@ public Source resolve(final String href, String base) throws TransformerExceptio
182191
if (path.startsWith("/")) {
183192
path = normalizePath(path);
184193
return databaseSource(path);
185-
} else {
194+
195+
} else if (fallbackToUrlStreamSource) {
186196
return urlSource(path);
197+
198+
} else {
199+
return null;
187200
}
188201
}
189202

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 & 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
*
@@ -30,9 +54,9 @@
3054
import java.nio.file.Path;
3155
import java.nio.file.Paths;
3256

33-
import static com.ibm.icu.impl.Assert.fail;
3457
import static org.junit.Assert.assertEquals;
3558
import static org.junit.Assert.assertNotNull;
59+
import static org.junit.Assert.fail;
3660

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

4771
try {
48-
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());
4973
} catch (final URISyntaxException e) {
50-
fail(e);
74+
fail(e.getMessage());
5175
return null;
5276
}
5377
}
File renamed without changes.

extensions/modules/xslfo/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
<include>src/test/resources-filtered/conf.xml</include>
186186
<include>src/test/resources/log4j2.xml</include>
187187
<include>src/main/java/org/exist/xquery/modules/xslfo/ApacheFopProcessorAdapter.java</include>
188+
<include>src/main/java/org/exist/xquery/modules/xslfo/RenderXXepProcessorAdapter.java</include>
188189
</includes>
189190
</licenseSet>
190191

@@ -198,6 +199,7 @@
198199
<exclude>src/test/resources-filtered/conf.xml</exclude>
199200
<exclude>src/test/resources/log4j2.xml</exclude>
200201
<exclude>src/main/java/org/exist/xquery/modules/xslfo/ApacheFopProcessorAdapter.java</exclude>
202+
<exclude>src/main/java/org/exist/xquery/modules/xslfo/RenderXXepProcessorAdapter.java</exclude>
201203
</excludes>
202204
</licenseSet>
203205

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)