adam Retter created FOP-2758: -------------------------------- Summary: [PATCH] Font Detection fails for custom URI schemes Key: FOP-2758 URL: https://issues.apache.org/jira/browse/FOP-2758 Project: FOP Issue Type: Bug Affects Versions: 2.2 Reporter: adam Retter Attachments: fop-font-detector-factory.patch
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: {code} 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); {code} Our FOP config file looks like: {code} <fop version="1.0"> <renderers> <renderer mime="application/pdf"> <fonts> <auto-detect/> </fonts> </renderer> </renderers> </fop> {code} The error occurs because of these lines in {{org.apache.fop.fonts.FontDetectorFactory}}: {code} URI fontBaseURI = fontManager.getResourceResolver().getBaseURI(); File fontBase = FileUtils.toFile(fontBaseURI.toURL()); {code} 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. -- This message was sent by Atlassian JIRA (v6.4.14#64029)