From: Jeremias Maerki Date: Tue, 20 Nov 2007 15:56:33 +0000 (+0000) Subject: Bugfix: Bugfix for URI resolution: Make StreamSources without system identifier work... X-Git-Tag: fop-0_95beta~268 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c363ede82375f42cd09c6ded9c89041774085ba4;p=xmlgraphics-fop.git Bugfix: Bugfix for URI resolution: Make StreamSources without system identifier work again. Bugfix: Close streams opened by test font resolution in font configuration (the font URIs will be resolved again later anyway). Better error message when the loading of font metric files doesn't work due to missing information in the returned Source instances. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@596724 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index cc05d31b8..e6ed7e881 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -27,10 +27,12 @@ import java.util.Set; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; +import org.xml.sax.InputSource; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.apache.fop.apps.FOPException; -import org.xml.sax.InputSource; /** * This class is used to defer the loading of a font until it is really used. @@ -95,8 +97,10 @@ public class LazyFont extends Typeface implements FontDescriptor { in = new java.net.URL(source.getSystemId()).openStream(); } if (in == null) { - String err = "Cannot load font: failed to create InputStream from" - + " Source for metrics file " + metricsFileName; + String err = "Cannot load font: After URI resolution, the returned" + + " Source object does not contain an InputStream" + + " or a valid URL (system identifier) for metrics file: " + + metricsFileName; if (fail) { throw new RuntimeException(err); } else { diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java index 23bc0a022..318e1b1dc 100644 --- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java +++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java @@ -27,12 +27,15 @@ import java.util.Iterator; import java.util.List; import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FopFactory; @@ -222,7 +225,15 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator } } } - + + private static void closeSource(Source src) { + if (src instanceof StreamSource) { + StreamSource streamSource = (StreamSource)src; + IOUtils.closeQuietly(streamSource.getInputStream()); + IOUtils.closeQuietly(streamSource.getReader()); + } + } + /** * Returns a font info from a font node Configuration definition * @@ -243,23 +254,27 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator LogUtil.handleError(log, "Font configuration without metric-url or embed-url", strict); return null; } - if (embedUrl != null) { - Source source = fontResolver.resolve(embedUrl); - if (source == null) { - LogUtil.handleError(log, - "Failed to resolve font with embed-url '" + embedUrl + "'", strict); - return null; + if (strict) { + //This section just checks early whether the URIs can be resolved + //Stream are immediately closed again since they will never be used anyway + if (embedUrl != null) { + Source source = fontResolver.resolve(embedUrl); + closeSource(source); + if (source == null) { + LogUtil.handleError(log, + "Failed to resolve font with embed-url '" + embedUrl + "'", strict); + return null; + } } - embedUrl = source.getSystemId(); // absolute path/url - } - if (metricsUrl != null) { - Source source = fontResolver.resolve(metricsUrl); - if (source == null) { - LogUtil.handleError(log, - "Failed to resolve font with metric-url '" + metricsUrl + "'", strict); - return null; + if (metricsUrl != null) { + Source source = fontResolver.resolve(metricsUrl); + closeSource(source); + if (source == null) { + LogUtil.handleError(log, + "Failed to resolve font with metric-url '" + metricsUrl + "'", strict); + return null; + } } - metricsUrl = source.getSystemId(); // absolute path/url } boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", true); diff --git a/status.xml b/status.xml index fc39f46e4..3e4ad4b55 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,9 @@ + + Bugfix for URI resolution: Make StreamSources without system identifier work again. + Avoid a NullPointerException in AreaTreeHandler.endDocument().