final URLImageContainer urlImageContainer = (URLImageContainer) reference;
final ResourceKey url = urlImageContainer.getResourceKey();
if (url != null && urlImageContainer.isLoadable())
{
identity = url;
final Image cached = (Image) cachedImages.get(identity);
if (cached != null)
{
return cached;
}
try
{
final ResourceData resourceData = resourceManager.load(url);
final byte[] data = resourceData.getResource(resourceManager);
final Image itextimage = Image.getInstance(data);
cachedImages.put(identity, itextimage);
return itextimage;
}
catch (ResourceException re)
{
RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", re);
}
catch (BadElementException be)
{
RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", be);
}
catch (IOException ioe)
{
RTFImageCache.logger.info("Unable to read the raw-data, will try to recode image-data.", ioe);
}
try
{
final Resource resource = resourceManager.create(url, null, Image.class);
image = (java.awt.Image) resource.getResource();
}
catch (ResourceException re)
{
RTFImageCache.logger.info("Caught illegal Image, will try to find local instance", re);
}
}
}
if (reference instanceof LocalImageContainer && image == null)
{
final LocalImageContainer localImageContainer =
(LocalImageContainer) reference;
image = localImageContainer.getImage();
if (image != null)
{
// check, if the content was cached ...
identity = localImageContainer.getIdentity();
if (identity != null)
{
final Image cachedImage = (Image) cachedImages.get(identity);
if (cachedImage != null)
{
return cachedImage;
}
}
}
}
if (image == null)
{
return null;
}
final WaitingImageObserver obs = new WaitingImageObserver(image);
obs.waitImageLoaded();
try
{
final byte[] data = RenderUtility.encodeImage(image);
final Image itextimage = Image.getInstance(data);
if (identity != null)
{
cachedImages.put(identity, itextimage);
}
return itextimage;