Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.2
-
None
-
None
-
None
-
Patch
Description
If you are using a custom URI scheme with FOP, then auto-detection of fonts currently throws an exception, because it assumes the URI is convertible to a URL, however Java by default does not support the custom URIs.
With FOP in eXist-db we use the URI scheme exist for resolving resolving resources from the database.
Our FOP setup looks like this:
URI baseUri = new URI("exist://localhost" + configFile.getOwnerDocument().getBaseURI()); final ResourceResolverFactory.SchemeAwareResourceResolverBuilder resBuilder = ResourceResolverFactory.createSchemeAwareResourceResolverBuilder(ResourceResolverFactory.createDefaultResourceResolver()); final URIResolverAdapter uriResolver = new URIResolverAdapter( new ExistSchemeRewriter(new EXistURIResolver(broker.getBrokerPool(), baseUri)) ); resBuilder.registerResourceResolverForScheme("exist", uriResolver); final EnvironmentProfile environment = EnvironmentalProfileFactory.createDefault(baseUri, resBuilder.build()); FopFactoryBuilder builder = new FopFactoryBuilder(environment).setConfiguration(cfg);
Our FOP config file looks like:
<fop version="1.0"> <renderers> <renderer mime="application/pdf"> <fonts> <auto-detect/> </fonts> </renderer> </renderers> </fop>
The error occurs because of these lines in org.apache.fop.fonts.FontDetectorFactory:
URI fontBaseURI = fontManager.getResourceResolver().getBaseURI(); File fontBase = FileUtils.toFile(fontBaseURI.toURL());
In particular the fontBaseURI.toURL() generates a MalformedURLException. The URL is actually perfectly valid, it is just that Java does not have a handler for it.
The attached patch, simply wraps that in a try/catch and logs the exception as a warning, as this seems to be a non-critical path, after which system fonts can still be correctly be detected.