From 4c8a18e4a5e33f473150b9e2f4a91461cb67cce9 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Fri, 14 Jan 2011 11:15:16 +0000 Subject: [PATCH] Relative URIs in the configuration file are evaluated relative to the base URI of the configuration file git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1058945 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/trunk/configuration.xml | 3 ++ src/java/org/apache/fop/apps/FopFactory.java | 10 ++++ .../fop/apps/FopFactoryConfigurator.java | 52 +++++++++++++++++-- .../fop/fonts/FontManagerConfigurator.java | 19 ++++++- status.xml | 4 ++ test/test-no-xml-metrics.xconf | 2 +- 6 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/documentation/content/xdocs/trunk/configuration.xml b/src/documentation/content/xdocs/trunk/configuration.xml index 3ef8795b7..26707edbf 100644 --- a/src/documentation/content/xdocs/trunk/configuration.xml +++ b/src/documentation/content/xdocs/trunk/configuration.xml @@ -89,6 +89,9 @@ disabled + + Relative URIs for the above three properties are evaluated relative to the base URI of the configuration file. If the configuration is provided programmatically, the base URI can be set with FopFactory.setUserConfigBaseURI; default is the current working directory. + hyphenation-pattern String, attribute lang, attribute country (optional) diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index b86c52cf6..181bc85da 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.net.MalformedURLException; +import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -700,6 +701,15 @@ public class FopFactory implements ImageContext { config.setUserConfig(userConfig); } + /** + * Set the base URI for the user configuration + * Useful for programmatic configurations + * @param baseURI the base URI + */ + public void setUserConfigBaseURI(URI baseURI) { + config.setBaseURI(baseURI); + } + /** * Get the user configuration. * @return the user configuration diff --git a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java index 161bd4a8f..6c1986cb2 100644 --- a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java +++ b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java @@ -22,6 +22,8 @@ package org.apache.fop.apps; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; @@ -78,6 +80,9 @@ public class FopFactoryConfigurator { /** Fop factory configuration */ private Configuration cfg = null; + /** The base URI of the configuration file **/ + private URI baseURI = null; + /** * Default constructor * @param factory fop factory @@ -130,17 +135,23 @@ public class FopFactoryConfigurator { // base definitions for relative path resolution if (cfg.getChild("base", false) != null) { + String path = cfg.getChild("base").getValue(null); + if (baseURI != null) { + path = baseURI.resolve(path).normalize().toString(); + } try { - factory.setBaseURL( - cfg.getChild("base").getValue(null)); + factory.setBaseURL(path); } catch (MalformedURLException mfue) { LogUtil.handleException(log, mfue, strict); } } if (cfg.getChild("hyphenation-base", false) != null) { + String path = cfg.getChild("hyphenation-base").getValue(null); + if (baseURI != null) { + path = baseURI.resolve(path).normalize().toString(); + } try { - factory.setHyphenBaseURL( - cfg.getChild("hyphenation-base").getValue(null)); + factory.setHyphenBaseURL(path); } catch (MalformedURLException mfue) { LogUtil.handleException(log, mfue, strict); } @@ -259,7 +270,7 @@ public class FopFactoryConfigurator { } // configure font manager - new FontManagerConfigurator(cfg).configure(factory.getFontManager(), strict); + new FontManagerConfigurator(cfg, baseURI).configure(factory.getFontManager(), strict); // configure image loader framework configureImageLoading(cfg.getChild("image-loading", false), strict); @@ -339,6 +350,7 @@ public class FopFactoryConfigurator { */ public void setUserConfig(Configuration cfg) throws FOPException { this.cfg = cfg; + setBaseURI(); configure(this.factory); } @@ -349,4 +361,34 @@ public class FopFactoryConfigurator { public Configuration getUserConfig() { return this.cfg; } + + /** + * @return the baseURI + */ + public URI getBaseURI() { + return baseURI; + } + + /** + * @param baseURI the baseURI to set + */ + public void setBaseURI(URI baseURI) { + this.baseURI = baseURI; + } + + private void setBaseURI() throws FOPException { + String[] locationParts = cfg.getLocation().split(":"); + try { + if (locationParts != null && locationParts.length >= 2 + && "file".equals(locationParts[0])) { + baseURI = new URI(locationParts[0], locationParts[1], null); + } + if (baseURI == null) { + baseURI = new File(System.getProperty("user.dir")).toURI(); + } + } catch (URISyntaxException 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 421c99051..6935df7e3 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -21,6 +21,7 @@ package org.apache.fop.fonts; import java.io.File; import java.net.MalformedURLException; +import java.net.URI; import java.util.List; import java.util.regex.Pattern; @@ -43,6 +44,8 @@ public class FontManagerConfigurator { private final Configuration cfg; + private URI baseURI = null; + /** * Main constructor * @param cfg the font manager configuration object @@ -51,6 +54,16 @@ public class FontManagerConfigurator { this.cfg = cfg; } + /** + * Main constructor + * @param cfg the font manager configuration object + * @param baseURI the base URI of the configuration + */ + public FontManagerConfigurator(Configuration cfg, URI baseURI) { + this.cfg = cfg; + this.baseURI = baseURI; + } + /** * Initializes font settings from the user configuration * @param fontManager a font manager @@ -74,8 +87,12 @@ public class FontManagerConfigurator { } } if (cfg.getChild("font-base", false) != null) { + String path = cfg.getChild("font-base").getValue(null); + if (baseURI != null) { + path = baseURI.resolve(path).normalize().toString(); + } try { - fontManager.setFontBaseURL(cfg.getChild("font-base").getValue(null)); + fontManager.setFontBaseURL(path); } catch (MalformedURLException mfue) { LogUtil.handleException(log, mfue, true); } diff --git a/status.xml b/status.xml index 16054217d..c80ba0668 100644 --- a/status.xml +++ b/status.xml @@ -49,6 +49,7 @@ + @@ -58,6 +59,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Bugfix: relative URIs in the configuration file (base, font-base, hyphenation-base) are evaluated relative to the base URI of the configuration file. + Bugfix: correct behavior of keep-together.within-line in case there are nested inlines diff --git a/test/test-no-xml-metrics.xconf b/test/test-no-xml-metrics.xconf index beb24c0ef..6005eac94 100644 --- a/test/test-no-xml-metrics.xconf +++ b/test/test-no-xml-metrics.xconf @@ -7,7 +7,7 @@ ./ - ./test/resources/fonts + ./resources/fonts -- 2.39.5