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.
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 {
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;
}
}
}
-
+
+ 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
*
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);