aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/area
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/area')
-rw-r--r--src/java/org/apache/fop/area/AreaEventProducer.java91
-rw-r--r--src/java/org/apache/fop/area/AreaTreeHandler.java5
-rw-r--r--src/java/org/apache/fop/area/AreaTreeObject.java10
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java2
-rw-r--r--src/java/org/apache/fop/area/CachedRenderPagesModel.java77
-rw-r--r--src/java/org/apache/fop/area/PageViewport.java16
-rw-r--r--src/java/org/apache/fop/area/RenderPagesModel.java45
7 files changed, 175 insertions, 71 deletions
diff --git a/src/java/org/apache/fop/area/AreaEventProducer.java b/src/java/org/apache/fop/area/AreaEventProducer.java
new file mode 100644
index 000000000..7747d2d79
--- /dev/null
+++ b/src/java/org/apache/fop/area/AreaEventProducer.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.area;
+
+import org.apache.fop.events.EventBroadcaster;
+import org.apache.fop.events.EventProducer;
+
+/**
+ * Event producer interface for events related to the area tree.
+ */
+public interface AreaEventProducer extends EventProducer {
+
+ /**
+ * Provider class for the event producer.
+ */
+ class Provider {
+
+ /**
+ * Returns an event producer.
+ * @param broadcaster the event broadcaster to use
+ * @return the event producer
+ */
+ public static AreaEventProducer get(EventBroadcaster broadcaster) {
+ return (AreaEventProducer)broadcaster.getEventProducerFor(
+ AreaEventProducer.class);
+ }
+ }
+
+ /**
+ * An unresolved ID reference was encountered.
+ * @param source the event source
+ * @param type the type of reference
+ * @param id the unresolved ID
+ * @event.severity WARN
+ */
+ void unresolvedIDReference(Object source, String type, String id);
+
+ /**
+ * An unresolved ID reference was encountered on a page.
+ * @param source the event source
+ * @param page the page the ID reference was found on
+ * @param id the unresolved ID
+ * @event.severity WARN
+ */
+ void unresolvedIDReferenceOnPage(Object source, String page, String id);
+
+ /**
+ * A page could not be loaded/deserialized from a file.
+ * @param source the event source
+ * @param page the page to be loaded
+ * @param e the original exception
+ * @event.severity ERROR
+ */
+ void pageLoadError(Object source, String page, Exception e);
+
+ /**
+ * A page could not be saved/serialized to a file.
+ * @param source the event source
+ * @param page the page to be serialized
+ * @param e the original exception
+ * @event.severity ERROR
+ */
+ void pageSaveError(Object source, String page, Exception e);
+
+ /**
+ * A page could not be rendered.
+ * @param source the event source
+ * @param page the page to be serialized
+ * @param e the original exception
+ * @event.severity ERROR
+ */
+ void pageRenderingError(Object source, String page, Exception e);
+
+}
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java
index 7454f4667..d3ea41554 100644
--- a/src/java/org/apache/fop/area/AreaTreeHandler.java
+++ b/src/java/org/apache/fop/area/AreaTreeHandler.java
@@ -325,8 +325,9 @@ public class AreaTreeHandler extends FOEventHandler {
if (pageVPList != null) {
res.resolveIDRef(ids[count], pageVPList);
} else {
- log.warn(odi.getName() + ": Unresolved id reference \""
- + ids[count] + "\" found.");
+ AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster());
+ eventProducer.unresolvedIDReference(this, odi.getName(), ids[count]);
idTracker.addUnresolvedIDRef(ids[count], res);
}
}
diff --git a/src/java/org/apache/fop/area/AreaTreeObject.java b/src/java/org/apache/fop/area/AreaTreeObject.java
index 94250deba..1c2269a01 100644
--- a/src/java/org/apache/fop/area/AreaTreeObject.java
+++ b/src/java/org/apache/fop/area/AreaTreeObject.java
@@ -23,7 +23,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
-import org.apache.fop.util.QName;
+import org.apache.xmlgraphics.util.QName;
/**
* Abstract base class for all area tree objects.
@@ -53,12 +53,12 @@ public abstract class AreaTreeObject {
if (atts.size() == 0) {
return;
}
- Iterator iter = atts.keySet().iterator();
+ Iterator iter = atts.entrySet().iterator();
while (iter.hasNext()) {
- QName qName = (QName)iter.next();
- String value = (String)atts.get(qName);
+ Map.Entry entry = (Map.Entry)iter.next();
+ String value = (String)entry.getValue();
//The casting is only to ensure type safety (too bad we can't use generics, yet)
- setForeignAttribute(qName, value);
+ setForeignAttribute((QName)entry.getKey(), value);
}
}
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index fafb99ed6..19edd3d5e 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -50,6 +50,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.util.QName;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Trait.Background;
@@ -78,7 +79,6 @@ import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
import org.apache.fop.util.DefaultErrorListener;
-import org.apache.fop.util.QName;
/**
* This is a parser for the area tree XML (intermediate format) which is used to reread an area
diff --git a/src/java/org/apache/fop/area/CachedRenderPagesModel.java b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
index 363fa02d1..b34a7e8d1 100644
--- a/src/java/org/apache/fop/area/CachedRenderPagesModel.java
+++ b/src/java/org/apache/fop/area/CachedRenderPagesModel.java
@@ -19,24 +19,27 @@
package org.apache.fop.area;
-import org.apache.commons.io.IOUtils;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.fonts.FontInfo;
-import org.xml.sax.SAXException;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.FileInputStream;
-import java.io.ObjectOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.OutputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedInputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.xml.sax.SAXException;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.events.ResourceEventProducer;
+import org.apache.fop.fonts.FontInfo;
/**
* A simple cached render pages model.
@@ -69,46 +72,39 @@ public class CachedRenderPagesModel extends RenderPagesModel {
*/
protected boolean checkPreparedPages(PageViewport newpage, boolean renderUnresolved) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
- PageViewport p = (PageViewport)iter.next();
- if (p.isResolved() || renderUnresolved) {
- if (p != newpage) {
+ PageViewport pageViewport = (PageViewport)iter.next();
+ if (pageViewport.isResolved() || renderUnresolved) {
+ if (pageViewport != newpage) {
try {
// load page from cache
- String name = (String)pageMap.get(p);
+ String name = (String)pageMap.get(pageViewport);
File tempFile = new File(baseDir, name);
log.debug("Loading page from: " + tempFile);
ObjectInputStream in = new ObjectInputStream(
new BufferedInputStream(
new FileInputStream(tempFile)));
try {
- p.loadPage(in);
+ pageViewport.loadPage(in);
} finally {
IOUtils.closeQuietly(in);
}
if (!tempFile.delete()) {
- log.warn("Temporary file could not be deleted: " + tempFile);
+ ResourceEventProducer eventProducer
+ = ResourceEventProducer.Provider.get(
+ renderer.getUserAgent().getEventBroadcaster());
+ eventProducer.cannotDeleteTempFile(this, tempFile);
}
- pageMap.remove(p);
+ pageMap.remove(pageViewport);
} catch (Exception e) {
- log.error(e);
+ AreaEventProducer eventProducer
+ = AreaEventProducer.Provider.get(
+ renderer.getUserAgent().getEventBroadcaster());
+ eventProducer.pageLoadError(this, pageViewport.getPageNumberString(), e);
}
}
- try {
- renderer.renderPage(p);
- if (!p.isResolved()) {
- String[] idrefs = p.getIDRefs();
- for (int count = 0; count < idrefs.length; count++) {
- log.warn("Page " + p.getPageNumberString()
- + ": Unresolved id reference \"" + idrefs[count]
- + "\" found.");
- }
- }
- } catch (Exception e) {
- // use error handler to handle this FOP or IO Exception
- log.error(e);
- }
- p.clear();
+ renderPage(pageViewport);
+ pageViewport.clear();
iter.remove();
} else {
if (!renderer.supportsOutOfOrder()) {
@@ -147,8 +143,11 @@ public class CachedRenderPagesModel extends RenderPagesModel {
if (log.isDebugEnabled()) {
log.debug("Page saved to temporary file: " + tempFile);
}
- } catch (Exception e) {
- log.error(e);
+ } catch (IOException ioe) {
+ AreaEventProducer eventProducer
+ = AreaEventProducer.Provider.get(
+ renderer.getUserAgent().getEventBroadcaster());
+ eventProducer.pageSaveError(this, page.getPageNumberString(), ioe);
}
}
diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java
index af557ade9..da7ef1def 100644
--- a/src/java/org/apache/fop/area/PageViewport.java
+++ b/src/java/org/apache/fop/area/PageViewport.java
@@ -21,14 +21,15 @@ package org.apache.fop.area;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
-import java.io.ObjectOutputStream;
+import java.io.IOException;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
-import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -516,9 +517,9 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* The map of unresolved references are set on the page so that
* the resolvers can be properly serialized and reloaded.
* @param out the object output stream to write the contents
- * @throws Exception if there is a problem saving the page
+ * @throws IOException in case of an I/O error while serializing the page
*/
- public void savePage(ObjectOutputStream out) throws Exception {
+ public void savePage(ObjectOutputStream out) throws IOException {
// set the unresolved references so they are serialized
page.setUnresolvedReferences(unresolvedIDRefs);
out.writeObject(page);
@@ -531,9 +532,10 @@ public class PageViewport extends AreaTreeObject implements Resolvable, Cloneabl
* if there are any unresolved references that were resolved
* while saved they will be resolved on the page contents.
* @param in the object input stream to read the page from
- * @throws Exception if there is an error loading the page
+ * @throws ClassNotFoundException if a class was not found while loading the page
+ * @throws IOException if an I/O error occurred while loading the page
*/
- public void loadPage(ObjectInputStream in) throws Exception {
+ public void loadPage(ObjectInputStream in) throws IOException, ClassNotFoundException {
page = (Page) in.readObject();
unresolvedIDRefs = page.getUnresolvedReferences();
if (unresolvedIDRefs != null && pendingResolved != null) {
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java
index e080e9cbe..b21566902 100644
--- a/src/java/org/apache/fop/area/RenderPagesModel.java
+++ b/src/java/org/apache/fop/area/RenderPagesModel.java
@@ -156,23 +156,7 @@ public class RenderPagesModel extends AreaTreeModel {
&& pageViewport.getPageSequence().isFirstPage(pageViewport)) {
renderer.startPageSequence(getCurrentPageSequence());
}
- try {
- renderer.renderPage(pageViewport);
- if (!pageViewport.isResolved()) {
- String[] idrefs = pageViewport.getIDRefs();
- for (int count = 0; count < idrefs.length; count++) {
- log.warn("Page " + pageViewport.getPageNumberString()
- + ": Unresolved id reference \"" + idrefs[count]
- + "\" found.");
- }
- }
- } catch (Exception e) {
- // use error handler to handle this FOP or IO Exception
- log.error("Error while rendering page " + pageViewport.getPageIndex(), e);
- if (e instanceof RuntimeException) {
- throw (RuntimeException)e;
- }
- }
+ renderPage(pageViewport);
pageViewport.clear();
iter.remove();
} else {
@@ -186,6 +170,33 @@ public class RenderPagesModel extends AreaTreeModel {
}
/**
+ * Renders the given page and notified about unresolved IDs if any.
+ * @param pageViewport the page to be rendered.
+ */
+ protected void renderPage(PageViewport pageViewport) {
+ try {
+ renderer.renderPage(pageViewport);
+ if (!pageViewport.isResolved()) {
+ String[] idrefs = pageViewport.getIDRefs();
+ for (int count = 0; count < idrefs.length; count++) {
+ AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
+ renderer.getUserAgent().getEventBroadcaster());
+ eventProducer.unresolvedIDReferenceOnPage(this,
+ pageViewport.getPageNumberString(), idrefs[count]);
+ }
+ }
+ } catch (Exception e) {
+ AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
+ renderer.getUserAgent().getEventBroadcaster());
+ eventProducer.pageRenderingError(this,
+ pageViewport.getPageNumberString(), e);
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException)e;
+ }
+ }
+ }
+
+ /**
* Prepare a page.
* An unresolved page can be prepared if the renderer supports
* it and the page will be rendered later.