diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/NaiveUserAgent.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/NaiveUserAgent.java index 14536b692..8fb6ca1af 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/NaiveUserAgent.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/NaiveUserAgent.java @@ -234,11 +234,12 @@ public ImageResource getImageResource(String uri) { BufferedImage image = ImageUtil.loadEmbeddedBase64Image(uri); ir = createImageResource(null, image); } else { - uri = resolveURI(uri); - ir = (ImageResource) _imageCache.get(uri); + String unresolvedUri = uri; + ir = (ImageResource) _imageCache.get(unresolvedUri); //TODO: check that cached image is still valid if (ir == null) { - InputStream is = resolveAndOpenStream(uri); + uri = resolveURI(uri); + InputStream is = resolveAndOpenStream(uri); if (is != null) { try { BufferedImage img = ImageIO.read(is); @@ -246,7 +247,7 @@ public ImageResource getImageResource(String uri) { throw new IOException("ImageIO.read() returned null"); } ir = createImageResource(uri, img); - _imageCache.put(uri, ir); + _imageCache.put(unresolvedUri, ir); } catch (FileNotFoundException e) { XRLog.exception("Can't read image file; image at URI '" + uri + "' not found"); } catch (IOException e) { diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/util/Configuration.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/util/Configuration.java index bd3c3c06b..c5f172d78 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/util/Configuration.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/util/Configuration.java @@ -85,7 +85,7 @@ public class Configuration { /** * The Singleton instance of the class. */ - private static Configuration sInstance; + private static Configuration sInstance = new Configuration(); /** * List of LogRecords for messages from Configuration startup; used to hold these @@ -762,10 +762,7 @@ public static boolean isFalse(String key, boolean defaultVal) { /** * @return The singleton instance of the class. */ - private static synchronized Configuration instance() { - if (Configuration.sInstance == null) { - Configuration.sInstance = new Configuration(); - } + private static Configuration instance() { return Configuration.sInstance; }// end main() diff --git a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextUserAgent.java b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextUserAgent.java index 8da54c5fd..5ace0038d 100644 --- a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextUserAgent.java +++ b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextUserAgent.java @@ -38,6 +38,8 @@ import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfReader; +import org.xhtmlrenderer.util.ImageUtil; + public class ITextUserAgent extends NaiveUserAgent { private static final int IMAGE_CACHE_CAPACITY = 32; @@ -62,16 +64,17 @@ private byte[] readStream(InputStream is) throws IOException { } public ImageResource getImageResource(String uriStr) { + String unresolvedUri = uriStr; ImageResource resource; if (!ImageUtil.isEmbeddedBase64Image(uriStr)) { uriStr = resolveURI(uriStr); } - resource = (ImageResource) _imageCache.get(uriStr); + resource = (ImageResource) _imageCache.get(unresolvedUri); if (resource == null) { if (ImageUtil.isEmbeddedBase64Image(uriStr)) { resource = loadEmbeddedBase64ImageResource(uriStr); - _imageCache.put(uriStr, resource); + _imageCache.put(unresolvedUri, resource); } else { InputStream is = resolveAndOpenStream(uriStr); if (is != null) { @@ -91,7 +94,7 @@ public ImageResource getImageResource(String uriStr) { scaleToOutputResolution(image); resource = new ImageResource(uriStr, new ITextFSImage(image)); } - _imageCache.put(uriStr, resource); + _imageCache.put(unresolvedUri, resource); } catch (Exception e) { XRLog.exception("Can't read image file; unexpected problem for URI '" + uriStr + "'", e); } finally {