diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2013-11-15 07:13:53 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2013-11-15 07:13:53 +0000 |
commit | 2318d09b63a801f5d490d688c8636912aa785eb1 (patch) | |
tree | ec2fbb233ee0190571c251d469e7522dcd6373b0 /src/java/org/apache/fop | |
parent | 7d3dba6c3c2fc6caeeeaccbc8df159b87934e44a (diff) | |
download | xmlgraphics-fop-2318d09b63a801f5d490d688c8636912aa785eb1.tar.gz xmlgraphics-fop-2318d09b63a801f5d490d688c8636912aa785eb1.zip |
FOP-2312: font-base configuration setting not working as expected
Use the config file URI to resolve relative <base> / <font-base> URIs.
Fall back to default base URI only if the config input stream has no URI.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1542190 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r-- | src/java/org/apache/fop/apps/FopConfParser.java | 53 | ||||
-rw-r--r-- | src/java/org/apache/fop/cli/CommandLineOptions.java | 7 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/FontManagerConfigurator.java | 16 |
3 files changed, 47 insertions, 29 deletions
diff --git a/src/java/org/apache/fop/apps/FopConfParser.java b/src/java/org/apache/fop/apps/FopConfParser.java index b4918ef30..b0fa40f45 100644 --- a/src/java/org/apache/fop/apps/FopConfParser.java +++ b/src/java/org/apache/fop/apps/FopConfParser.java @@ -70,16 +70,7 @@ public class FopConfParser { */ public FopConfParser(InputStream fopConfStream, EnvironmentProfile enviro) throws SAXException, IOException { - DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); - Configuration cfg; - try { - cfg = cfgBuilder.build(fopConfStream); - } catch (ConfigurationException e) { - throw new FOPException(e); - } - // The default base URI is taken from the directory in which the fopConf resides - fopFactoryBuilder = new FopFactoryBuilder(enviro).setConfiguration(cfg); - configure(enviro.getDefaultBaseURI(), enviro.getResourceResolver(), cfg); + this(fopConfStream, enviro.getDefaultBaseURI(), enviro); } /** @@ -94,7 +85,8 @@ public class FopConfParser { */ public FopConfParser(InputStream fopConfStream, URI defaultBaseURI, ResourceResolver resourceResolver) throws SAXException, IOException { - this(fopConfStream, EnvironmentalProfileFactory.createDefault(defaultBaseURI, resourceResolver)); + this(fopConfStream, defaultBaseURI, + EnvironmentalProfileFactory.createDefault(defaultBaseURI, resourceResolver)); } /** @@ -123,6 +115,20 @@ public class FopConfParser { } /** + * Constructor that takes the FOP conf and a default base URI and uses the default URI resolver. + * + * @param fopConfFile the FOP conf file + * @param defaultBaseURI the default base URI + * @throws SAXException if a SAX error was thrown parsing the FOP conf + * @throws IOException if an I/O error is thrown while parsing the FOP conf + */ + public FopConfParser(File fopConfFile, URI defaultBaseURI) throws SAXException, IOException { + this(new FileInputStream(fopConfFile), fopConfFile.toURI(), + EnvironmentalProfileFactory.createDefault(defaultBaseURI, + ResourceResolverFactory.createDefaultResourceResolver())); + } + + /** * Constructor that parses the FOP conf and uses the URI resolver given. * * @param fopConfFile the FOP conf file @@ -132,11 +138,24 @@ public class FopConfParser { */ public FopConfParser(File fopConfFile, ResourceResolver resourceResolver) throws SAXException, IOException { - this(new FileInputStream(fopConfFile), - fopConfFile.getAbsoluteFile().getParentFile().toURI(), resourceResolver); + this(new FileInputStream(fopConfFile), fopConfFile.toURI(), resourceResolver); + } + + private FopConfParser(InputStream fopConfStream, URI baseURI, EnvironmentProfile enviro) + throws SAXException, IOException { + DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); + Configuration cfg; + try { + cfg = cfgBuilder.build(fopConfStream); + } catch (ConfigurationException e) { + throw new FOPException(e); + } + // The default base URI is taken from the directory in which the fopConf resides + fopFactoryBuilder = new FopFactoryBuilder(enviro).setConfiguration(cfg); + configure(baseURI, enviro.getResourceResolver(), cfg); } - private void configure(final URI defaultBaseURI, final ResourceResolver resourceResolver, + private void configure(final URI baseURI, final ResourceResolver resourceResolver, Configuration cfg) throws FOPException { if (log.isDebugEnabled()) { log.debug("Initializing FopFactory Configuration"); @@ -174,7 +193,7 @@ public class FopConfParser { if (cfg.getChild("base", false) != null) { try { URI confUri = InternalResourceResolver.getBaseURI(cfg.getChild("base").getValue(null)); - fopFactoryBuilder.setBaseURI(defaultBaseURI.resolve(confUri)); + fopFactoryBuilder.setBaseURI(baseURI.resolve(confUri)); } catch (URISyntaxException use) { LogUtil.handleException(log, use, strict); } @@ -242,8 +261,8 @@ public class FopConfParser { } // configure font manager - new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseURI(), resourceResolver).configure( - fopFactoryBuilder.getFontManager(), strict); + new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver) + .configure(fopFactoryBuilder.getFontManager(), strict); // configure image loader framework configureImageLoading(cfg.getChild("image-loading", false), strict); diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 41fcdcac5..ad8019a7d 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -21,10 +21,8 @@ package org.apache.fop.cli; // java import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.io.PrintStream; import java.net.URI; import java.util.Locale; @@ -47,7 +45,6 @@ import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FopFactoryBuilder; import org.apache.fop.apps.FopFactoryConfig; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.pdf.PDFAMode; import org.apache.fop.pdf.PDFEncryptionManager; import org.apache.fop.pdf.PDFEncryptionParams; @@ -1018,9 +1015,7 @@ public class CommandLineOptions { fopFactoryBuilder.setComplexScriptFeatures(useComplexScriptFeatures); } else { try { - InputStream userConfig = new FileInputStream(userConfigFile); - FopConfParser fopConfParser = new FopConfParser(userConfig, baseURI, - ResourceResolverFactory.createDefaultResourceResolver()); + FopConfParser fopConfParser = new FopConfParser(userConfigFile, baseURI); fopFactoryBuilder = fopConfParser.getFopFactoryBuilder(); } catch (SAXException e) { throw new FOPException(e); diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java index fc2ce06a6..72c1684b6 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -48,20 +48,24 @@ public class FontManagerConfigurator { private final Configuration cfg; - private final URI defaultBaseUri; + private final URI baseURI; + + private final URI fallbackURI; private final ResourceResolver resourceResolver; /** * Main constructor * @param cfg the font manager configuration object - * @param defaultBaseUri the default URI base to use for URI resolution + * @param baseURI the URI against which to resolve relative URIs + * @param fallbackURI the URI to use as a fallback if font-base is unspecified * @param resourceResolver the resource resolver */ - public FontManagerConfigurator(Configuration cfg, URI defaultBaseUri, + public FontManagerConfigurator(Configuration cfg, URI baseURI, URI fallbackURI, ResourceResolver resourceResolver) { this.cfg = cfg; - this.defaultBaseUri = defaultBaseUri; + this.baseURI = baseURI; + this.fallbackURI = fallbackURI; this.resourceResolver = resourceResolver; } @@ -77,13 +81,13 @@ public class FontManagerConfigurator { URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base") .getValue(null)); fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver( - defaultBaseUri.resolve(fontBase), resourceResolver)); + baseURI.resolve(fontBase), resourceResolver)); } catch (URISyntaxException use) { LogUtil.handleException(log, use, true); } } else { fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver( - defaultBaseUri, resourceResolver)); + fallbackURI, resourceResolver)); } // caching (fonts) if (cfg.getChild("use-cache", false) != null) { |