aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2007-11-13 12:44:29 +0000
committerJeremias Maerki <jeremias@apache.org>2007-11-13 12:44:29 +0000
commit99b18323d1cf85c0de7394e9fb1eddf7a2211913 (patch)
tree681cef45fa91f3330cd43f6635af1ea93eb2d806 /src/java
parentc2fcb031beda14484f893c5f09137a1527a5da44 (diff)
downloadxmlgraphics-fop-99b18323d1cf85c0de7394e9fb1eddf7a2211913.tar.gz
xmlgraphics-fop-99b18323d1cf85c0de7394e9fb1eddf7a2211913.zip
Filter single quotes from the filenames as this will interfere with font-family parsing.
Fixed bug: InputStream opened by URL.openConnection() wasn't closed which leads to "too many open files" when you have lots of fonts on Java 1.4. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594516 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
index 759327ad0..7c0b4fcfa 100644
--- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
+++ b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
@@ -21,11 +21,14 @@ package org.apache.fop.fonts.autodetect;
import java.io.IOException;
import java.net.URL;
+import java.net.URLConnection;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.regex.Pattern;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.fonts.CachedFontInfo;
@@ -62,7 +65,7 @@ public class FontInfoFinder {
}
// default style and weight triplet vales (fallback)
- String strippedName = customFont.getStrippedFontName();
+ String strippedName = stripQuotes(customFont.getStrippedFontName());
String subName = customFont.getFontSubName();
String searchName = strippedName.toLowerCase();
if (subName != null) {
@@ -74,7 +77,7 @@ public class FontInfoFinder {
//Full Name usually includes style/weight info so don't use these traits
//If we still want to use these traits, we have to make FontInfo.fontLookup() smarter
- String fullName = customFont.getFullName();
+ String fullName = stripQuotes(customFont.getFullName());
triplets.add(new FontTriplet(fullName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL));
if (!fullName.equals(strippedName)) {
triplets.add(new FontTriplet(strippedName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL));
@@ -82,12 +85,18 @@ public class FontInfoFinder {
Set familyNames = customFont.getFamilyNames();
Iterator iter = familyNames.iterator();
while (iter.hasNext()) {
- String familyName = (String)iter.next();
+ String familyName = stripQuotes((String)iter.next());
if (!fullName.equals(familyName)) {
triplets.add(new FontTriplet(familyName, style, weight));
}
}
}
+
+ private final Pattern quotePattern = Pattern.compile("'");
+
+ private String stripQuotes(String name) {
+ return quotePattern.matcher(name).replaceAll("");
+ }
private String guessStyle(CustomFont customFont, String fontName) {
// style
@@ -136,7 +145,13 @@ public class FontInfoFinder {
long fileLastModified = -1;
if (fontCache != null) {
try {
- fileLastModified = fontUrl.openConnection().getLastModified();
+ URLConnection conn = fontUrl.openConnection();
+ try {
+ fileLastModified = conn.getLastModified();
+ } finally {
+ //An InputStream is created even if it's not accessed, but we need to close it.
+ IOUtils.closeQuietly(conn.getInputStream());
+ }
} catch (IOException e) {
// Should never happen, because URL must be local
log.debug("IOError: " + e.getMessage());