xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r596724 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/LazyFont.java src/java/org/apache/fop/render/PrintRendererConfigurator.java status.xml
Date Tue, 20 Nov 2007 15:56:33 GMT
Author: jeremias
Date: Tue Nov 20 07:56:33 2007
New Revision: 596724

URL: http://svn.apache.org/viewvc?rev=596724&view=rev
Log:
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.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java?rev=596724&r1=596723&r2=596724&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java Tue Nov 20 07:56:33
2007
@@ -27,10 +27,12 @@
 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 @@
                             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 {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java?rev=596724&r1=596723&r2=596724&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java Tue
Nov 20 07:56:33 2007
@@ -27,12 +27,15 @@
 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 @@
             }
         }
     }
-        
+
+    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 @@
             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;
-            }
-            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 (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;
+                }
+            }
+            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);
                         

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=596724&r1=596723&r2=596724&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Tue Nov 20 07:56:33 2007
@@ -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>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message