]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugfix: Bugfix for URI resolution: Make StreamSources without system identifier work...
authorJeremias Maerki <jeremias@apache.org>
Tue, 20 Nov 2007 15:56:33 +0000 (15:56 +0000)
committerJeremias Maerki <jeremias@apache.org>
Tue, 20 Nov 2007 15:56:33 +0000 (15:56 +0000)
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

src/java/org/apache/fop/fonts/LazyFont.java
src/java/org/apache/fop/render/PrintRendererConfigurator.java
status.xml

index cc05d31b8dd0eb5472d524f6c8292a31754555a7..e6ed7e88107c7d3a09047a515e39c8a532bc16fa 100644 (file)
@@ -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 {
index 23bc0a022f3aa6a60f4de9383bc5708426429941..318e1b1dc2fda9988ddb66a5ad8c6fa8a7a5d69a 100644 (file)
@@ -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);
                         
index fc39f46e48dd9c32c8f68e9b257ea5f09c74e6f3..3e4ad4b55799b6ca24221eec7b7f6faef02a8e86 100644 (file)
@@ -28,6 +28,9 @@
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Code" dev="JM" type="fix">
+        Bugfix for URI resolution: Make StreamSources without system identifier work again.
+      </action>
       <action context="Code" dev="JM" type="fix" fixes-bug="43910" due-to="David Delbecq">
         Avoid a NullPointerException in AreaTreeHandler.endDocument().
       </action>