aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMehdi Houshmand <mehdi@apache.org>2012-08-17 13:14:25 +0000
committerMehdi Houshmand <mehdi@apache.org>2012-08-17 13:14:25 +0000
commitc52db65ef80d7cd0e163f711117ef9a81f2fba34 (patch)
tree6beabec9976b6914bf5571d8965ed165b84cc569 /src
parent726e1ef3093bedfd6671c2e6471e0d62ef605be5 (diff)
downloadxmlgraphics-fop-c52db65ef80d7cd0e163f711117ef9a81f2fba34.tar.gz
xmlgraphics-fop-c52db65ef80d7cd0e163f711117ef9a81f2fba34.zip
Bugzilla#53751: Slightly restructured the way the FontCache creates a cache-file
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1374238 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/afp/util/AFPResourceAccessor.java2
-rw-r--r--src/java/org/apache/fop/cli/CommandLineOptions.java2
-rw-r--r--src/java/org/apache/fop/fonts/FontCacheManager.java18
-rw-r--r--src/java/org/apache/fop/fonts/FontCacheManagerFactory.java37
-rw-r--r--src/java/org/apache/fop/fonts/FontManager.java32
-rw-r--r--src/java/org/apache/fop/fonts/FontManagerConfigurator.java31
6 files changed, 62 insertions, 60 deletions
diff --git a/src/java/org/apache/fop/afp/util/AFPResourceAccessor.java b/src/java/org/apache/fop/afp/util/AFPResourceAccessor.java
index 46b09be21..f760e6c7c 100644
--- a/src/java/org/apache/fop/afp/util/AFPResourceAccessor.java
+++ b/src/java/org/apache/fop/afp/util/AFPResourceAccessor.java
@@ -106,7 +106,7 @@ public final class AFPResourceAccessor {
URI resolveURI(String uri);
}
- private final class NullBaseURIResolver implements URIResolver {
+ private static final class NullBaseURIResolver implements URIResolver {
public URI resolveURI(URI uri) {
return uri;
diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java
index 886e27527..7a11df71a 100644
--- a/src/java/org/apache/fop/cli/CommandLineOptions.java
+++ b/src/java/org/apache/fop/cli/CommandLineOptions.java
@@ -421,7 +421,7 @@ public class CommandLineOptions {
throw new FOPException("if you use '-cache', you must specify "
+ "the name of the font cache file");
} else {
- factory.getFontManager().setCacheFile(new File(args[i + 1]));
+ factory.getFontManager().setCacheFile(URI.create(args[i + 1]));
return 1;
}
}
diff --git a/src/java/org/apache/fop/fonts/FontCacheManager.java b/src/java/org/apache/fop/fonts/FontCacheManager.java
index fb0a0322b..a4acd43a4 100644
--- a/src/java/org/apache/fop/fonts/FontCacheManager.java
+++ b/src/java/org/apache/fop/fonts/FontCacheManager.java
@@ -19,7 +19,7 @@
package org.apache.fop.fonts;
-import java.io.File;
+import java.net.URI;
import org.apache.fop.apps.FOPException;
@@ -30,24 +30,26 @@ import org.apache.fop.apps.FOPException;
public interface FontCacheManager {
/**
+ * Sets the font cache file given the URI pointing to the file.
+ * @param fontCacheURI the font cache URI
+ */
+ void setCacheFile(URI fontCacheURI);
+
+ /**
* Loads the font cache into memory from the given file.
- * @param file the serialized font cache
* @return the de-serialized font cache
*/
- FontCache load(File file);
+ FontCache load();
/**
* Serializes the font cache to file.
- * @param file the file to serialize the font cache to
* @throws FOPException if an error occurs serializing the font cache
*/
- void save(File file) throws FOPException;
+ void save() throws FOPException;
/**
* Deletes the font cache from the file-system.
- * @param file delete the serialized font cache
* @throws FOPException if an error occurs deleting the font cache
*/
- void delete(File file) throws FOPException;
-
+ void delete() throws FOPException;
}
diff --git a/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java b/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java
index 0236effce..c1d736b0d 100644
--- a/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java
+++ b/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java
@@ -20,6 +20,7 @@
package org.apache.fop.fonts;
import java.io.File;
+import java.net.URI;
import org.apache.fop.apps.FOPException;
@@ -50,11 +51,14 @@ public final class FontCacheManagerFactory {
private static final class FontCacheManagerImpl implements FontCacheManager {
+ /** Provides a font cache file path **/
+ private File cacheFile;
+
private FontCache fontCache;
- public FontCache load(File cacheFile) {
+ public FontCache load() {
if (fontCache == null) {
- fontCache = FontCache.loadFrom(cacheFile);
+ fontCache = FontCache.loadFrom(getCacheFile(false));
if (fontCache == null) {
fontCache = new FontCache();
}
@@ -62,31 +66,46 @@ public final class FontCacheManagerFactory {
return fontCache;
}
- public void save(File cacheFile) throws FOPException {
+ public void save() throws FOPException {
if (fontCache != null && fontCache.hasChanged()) {
- fontCache.saveTo(cacheFile);
+ fontCache.saveTo(getCacheFile(true));
}
}
- public void delete(File cacheFile) throws FOPException {
- if (!cacheFile.delete()) {
+ public void delete() throws FOPException {
+ if (!getCacheFile(true).delete()) {
throw new FOPException("Failed to flush the font cache file '" + cacheFile + "'.");
}
}
+
+ private File getCacheFile(boolean forWriting) {
+ if (cacheFile != null) {
+ return cacheFile;
+ }
+ return FontCache.getDefaultCacheFile(forWriting);
+ }
+
+ public void setCacheFile(URI fontCacheURI) {
+ cacheFile = new File(fontCacheURI);
+ }
}
private static final class DisabledFontCacheManager implements FontCacheManager {
- public FontCache load(File cacheFile) {
+ public FontCache load() {
return null;
}
- public void save(File cacheFile) throws FOPException {
+ public void save() throws FOPException {
// nop
}
- public void delete(File cacheFile) throws FOPException {
+ public void delete() throws FOPException {
throw new FOPException("Font Cache disabled");
}
+
+ public void setCacheFile(URI fontCacheURI) {
+ // nop
+ }
}
}
diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java
index bff001f73..3df8a9078 100644
--- a/src/java/org/apache/fop/fonts/FontManager.java
+++ b/src/java/org/apache/fop/fonts/FontManager.java
@@ -19,7 +19,7 @@
package org.apache.fop.fonts;
-import java.io.File;
+import java.net.URI;
import java.util.List;
import org.apache.fop.apps.FOPException;
@@ -52,9 +52,6 @@ public class FontManager {
/** FontTriplet matcher for fonts that shall be referenced rather than embedded. */
private FontTriplet.Matcher referencedFontsMatcher;
- /** Provides a font cache file path **/
- private File cacheFile;
-
/**
* Main constructor
*
@@ -115,25 +112,10 @@ public class FontManager {
/**
* Sets the font cache file
- * @param cacheFile the font cache file
- */
- public void setCacheFile(File cacheFile) {
- this.cacheFile = cacheFile;
- }
-
- /**
- * Returns the font cache file
- * @return the font cache file
+ * @param cacheFileURI the URI of the font cache file
*/
- public File getCacheFile() {
- return getCacheFile(false);
- }
-
- private File getCacheFile(boolean writable) {
- if (cacheFile != null) {
- return cacheFile;
- }
- return FontCache.getDefaultCacheFile(writable);
+ public void setCacheFile(URI cacheFileURI) {
+ fontCacheManager.setCacheFile(resourceResolver.resolveFromBase(cacheFileURI));
}
/**
@@ -148,7 +130,7 @@ public class FontManager {
* @return the font cache
*/
public FontCache getFontCache() {
- return fontCacheManager.load(getCacheFile());
+ return fontCacheManager.load();
}
/**
@@ -157,7 +139,7 @@ public class FontManager {
* @throws FOPException fop exception
*/
public void saveCache() throws FOPException {
- fontCacheManager.save(getCacheFile());
+ fontCacheManager.save();
}
/**
@@ -165,7 +147,7 @@ public class FontManager {
* @throws FOPException if an error was thrown while deleting the cache
*/
public void deleteCache() throws FOPException {
- fontCacheManager.delete(getCacheFile(true));
+ fontCacheManager.delete();
}
/**
diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
index c4fe19444..cf9296826 100644
--- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
+++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
@@ -19,7 +19,6 @@
package org.apache.fop.fonts;
-import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
@@ -72,6 +71,19 @@ public class FontManagerConfigurator {
* @throws FOPException if an exception occurs while processing the configuration
*/
public void configure(FontManager fontManager, boolean strict) throws FOPException {
+ if (cfg.getChild("font-base", false) != null) {
+ try {
+ URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base")
+ .getValue(null));
+ fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
+ defaultBaseUri.resolve(fontBase), resourceResolver));
+ } catch (URISyntaxException use) {
+ LogUtil.handleException(log, use, true);
+ }
+ } else {
+ fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
+ defaultBaseUri, resourceResolver));
+ }
// caching (fonts)
if (cfg.getChild("use-cache", false) != null) {
try {
@@ -79,27 +91,14 @@ public class FontManagerConfigurator {
fontManager.disableFontCache();
} else {
if (cfg.getChild("cache-file", false) != null) {
- fontManager.setCacheFile(new File(cfg.getChild("cache-file").getValue()));
+
+ fontManager.setCacheFile(URI.create(cfg.getChild("cache-file").getValue()));
}
}
} catch (ConfigurationException mfue) {
LogUtil.handleException(log, mfue, true);
}
}
- if (cfg.getChild("font-base", false) != null) {
- try {
- URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base").getValue(
- null));
- fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
- defaultBaseUri.resolve(fontBase), resourceResolver));
- } catch (URISyntaxException use) {
- LogUtil.handleException(log, use, true);
- }
- } else {
- fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
- defaultBaseUri, resourceResolver));
- }
-
// [GA] permit configuration control over base14 kerning; without this,
// there is no way for a user to enable base14 kerning other than by
// programmatic API;