From 090c6205eeedae7990499540c879a8f00773b978 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 10 Mar 2009 07:55:20 +0000 Subject: [PATCH] AreaTreeParser redirecting image loading exceptions to event subsystem. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@752010 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/AreaTreeParser.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java index 8a6198cb6..ec47d2083 100644 --- a/src/java/org/apache/fop/area/AreaTreeParser.java +++ b/src/java/org/apache/fop/area/AreaTreeParser.java @@ -21,6 +21,8 @@ package org.apache.fop.area; import java.awt.Color; import java.awt.geom.Rectangle2D; +import java.io.FileNotFoundException; +import java.io.IOException; import java.nio.CharBuffer; import java.util.List; import java.util.Map; @@ -41,6 +43,7 @@ import org.w3c.dom.Document; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; @@ -48,6 +51,7 @@ import org.xml.sax.helpers.DefaultHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.image.loader.ImageSessionContext; @@ -68,6 +72,7 @@ import org.apache.fop.area.inline.SpaceArea; import org.apache.fop.area.inline.TextArea; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.WordArea; +import org.apache.fop.events.ResourceEventProducer; import org.apache.fop.fo.Constants; import org.apache.fop.fo.ElementMappingRegistry; import org.apache.fop.fo.expr.PropertyException; @@ -149,6 +154,7 @@ public class AreaTreeParser { private Stack delegateStack = new Stack(); private ContentHandler delegate; private DOMImplementation domImplementation; + private Locator locator; public Handler(AreaTreeModel treeModel, FOUserAgent userAgent, @@ -223,6 +229,15 @@ public class AreaTreeParser { return (Viewport)findAreaType(Viewport.class); } + /** {@inheritDoc} */ + public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + + private Locator getLocator() { + return this.locator; + } + /** {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { @@ -1056,8 +1071,21 @@ public class AreaTreeParser { = userAgent.getImageSessionContext(); ImageInfo info = manager.getImageInfo(uri, sessionContext); bkg.setImageInfo(info); - } catch (Exception e) { - log.error("Background image not available: " + uri, e); + } catch (ImageException e) { + ResourceEventProducer eventProducer + = ResourceEventProducer.Provider.get( + this.userAgent.getEventBroadcaster()); + eventProducer.imageError(this, uri, e, getLocator()); + } catch (FileNotFoundException fnfe) { + ResourceEventProducer eventProducer + = ResourceEventProducer.Provider.get( + this.userAgent.getEventBroadcaster()); + eventProducer.imageNotFound(this, uri, fnfe, getLocator()); + } catch (IOException ioe) { + ResourceEventProducer eventProducer + = ResourceEventProducer.Provider.get( + this.userAgent.getEventBroadcaster()); + eventProducer.imageIOError(this, uri, ioe, getLocator()); } String repeat = attributes.getValue("bkg-repeat"); -- 2.39.5