aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo
diff options
context:
space:
mode:
authorWilliam Victor Mote <vmote@apache.org>2003-08-12 06:18:43 +0000
committerWilliam Victor Mote <vmote@apache.org>2003-08-12 06:18:43 +0000
commit194c471b1cf53892d5d1f0b0943b19a366221f91 (patch)
treedc91ace94ca7edf4ce1c385f27ae306ef028105b /src/java/org/apache/fop/fo
parent23fed6850260a52c4be20341773f68a62fe229cf (diff)
downloadxmlgraphics-fop-194c471b1cf53892d5d1f0b0943b19a366221f91.tar.gz
xmlgraphics-fop-194c471b1cf53892d5d1f0b0943b19a366221f91.zip
1. convert fo.FOTreeHandler to fire events when it completes a PageSequence or document object
2. move logic that starts layout from fo.FOTreeHandler to apps.Driver. 3. add logic to apps.Driver to handle the events fired from fo.FOTreeHandler 4. end result is that FOTreeHandler now allows other objects to handle page-sequence and document objects in a manner similar to the way SAX allows them to handle XML elements. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196787 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo')
-rw-r--r--src/java/org/apache/fop/fo/FOInputHandler.java6
-rw-r--r--src/java/org/apache/fop/fo/FOTreeHandler.java135
2 files changed, 74 insertions, 67 deletions
diff --git a/src/java/org/apache/fop/fo/FOInputHandler.java b/src/java/org/apache/fop/fo/FOInputHandler.java
index 5aeb8bf6b..a3734e465 100644
--- a/src/java/org/apache/fop/fo/FOInputHandler.java
+++ b/src/java/org/apache/fop/fo/FOInputHandler.java
@@ -58,6 +58,7 @@ import java.util.HashSet;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
// FOP
+import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.ExternalGraphic;
@@ -93,10 +94,13 @@ public abstract class FOInputHandler extends AbstractLogEnabled {
*/
private Set idReferences = new HashSet();
+ public Driver driver = null;
+
/**
* Main constructor
*/
- public FOInputHandler() {
+ public FOInputHandler(Driver driver) {
+ this.driver = driver;
}
/**
diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java
index b4d8cd464..67fe255d6 100644
--- a/src/java/org/apache/fop/fo/FOTreeHandler.java
+++ b/src/java/org/apache/fop/fo/FOTreeHandler.java
@@ -54,18 +54,17 @@ package org.apache.fop.fo;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
+import java.util.HashSet;
+import java.util.Iterator;
// SAX
import org.xml.sax.SAXException;
// FOP
+import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.area.AreaTree;
-import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.StorePagesModel;
-import org.apache.fop.area.Title;
import org.apache.fop.area.TreeExt;
-import org.apache.fop.fo.FOInputHandler;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.InstreamForeignObject;
@@ -134,10 +133,10 @@ public class FOTreeHandler extends FOInputHandler {
private FontInfo fontInfo = new FontInfo();
/**
- * The current AreaTree for the PageSequence being rendered.
+ * Collection of objects that have registered to be notified about
+ * FOTreeEvent firings.
*/
- private AreaTree areaTree;
- private AreaTreeModel atModel;
+ private HashSet foTreeListeners = new HashSet();
/**
* Main constructor
@@ -146,27 +145,15 @@ public class FOTreeHandler extends FOInputHandler {
* @param store if true then use the store pages model and keep the
* area tree in memory
*/
- public FOTreeHandler(OutputStream outputStream, Renderer renderer,
+ public FOTreeHandler(Driver driver, OutputStream outputStream, Renderer renderer,
boolean store) {
+ super(driver);
if (collectStatistics) {
runtime = Runtime.getRuntime();
}
this.outputStream = outputStream;
this.renderer = renderer;
- this.areaTree = new AreaTree();
- this.atModel = AreaTree.createRenderPagesModel(renderer);
- //this.atModel = new CachedRenderPagesModel(renderer);
- areaTree.setTreeModel(atModel);
- }
-
- /**
- * Get the area tree for this layout handler.
- *
- * @return the area tree for this document
- */
- public AreaTree getAreaTree() {
- return areaTree;
}
/**
@@ -205,13 +192,7 @@ public class FOTreeHandler extends FOInputHandler {
* @throws SAXException if there is some error
*/
public void endDocument() throws SAXException {
- try {
- //processAreaTree(atModel);
- areaTree.endDocument();
- renderer.stopRenderer();
- } catch (Exception e) {
- throw new SAXException(e);
- }
+ notifyDocumentComplete();
if (collectStatistics) {
if (MEM_PROFILE_WITH_GC) {
@@ -246,11 +227,6 @@ public class FOTreeHandler extends FOInputHandler {
* @param pageSeq the page sequence starting
*/
public void startPageSequence(PageSequence pageSeq) {
- Title title = null;
- if (pageSeq.getTitleFO() != null) {
- title = pageSeq.getTitleFO().getTitleArea();
- }
- areaTree.startPageSequence(title);
}
/**
@@ -275,7 +251,7 @@ public class FOTreeHandler extends FOInputHandler {
getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
}
}
- pageSequence.format(areaTree);
+ notifyPageSequenceComplete(pageSequence);
}
/**
@@ -497,44 +473,71 @@ public class FOTreeHandler extends FOInputHandler {
}
/**
- * Process an area tree.
- * If a store pages model is used this can read and send all the
- * pages to the renderer.
+ * Get the font information for the layout handler.
*
- * @param model the store pages model
- * @throws FOPException if there is an error
- */
- private void processAreaTree(StorePagesModel model) throws FOPException {
- int count = 0;
- int seqc = model.getPageSequenceCount();
- while (count < seqc) {
- Title title = model.getTitle(count);
- renderer.startPageSequence(title);
- int pagec = model.getPageCount(count);
- for (int c = 0; c < pagec; c++) {
- try {
- renderer.renderPage(model.getPage(count, c));
- } catch (IOException ioex) {
- throw new FOPException("I/O Error rendering page",
- ioex);
- }
- }
- count++;
+ * @return the font information
+ */
+ public FontInfo getFontInfo() {
+ return this.fontInfo;
+ }
+
+ /**
+ * Add an object to the collection of objects that should be notified about
+ * FOTreeEvent firings.
+ * @param listener the Object which should be notified
+ */
+ public void addFOTreeListener (FOTreeListener listener) {
+ if (listener == null) {
+ return;
}
- List list = model.getEndExtensions();
- for (count = 0; count < list.size(); count++) {
- TreeExt ext = (TreeExt)list.get(count);
- renderer.renderExtension(ext);
+ foTreeListeners.add(listener);
+ }
+
+ /**
+ * Remove an object from the collection of objects that should be notified
+ * about FOTreeEvent firings.
+ * @param listener the Object which should no longer be notified
+ */
+ public void removeFOTreeListener (FOTreeListener listener) {
+ if (listener == null) {
+ return;
}
+ foTreeListeners.remove(listener);
}
/**
- * Get the font information for the layout handler.
- *
- * @return the font information
+ * Notify all objects in the foTreeListeners that a "Page Sequence Complete"
+ * FOTreeEvent has been fired.
+ * @param eventType integer indicating which type of event is created
+ * @param event the Event object that should be passed to the listeners
*/
- public FontInfo getFontInfo() {
- return this.fontInfo;
+ private void notifyPageSequenceComplete(PageSequence pageSequence)
+ throws FOPException {
+ FOTreeEvent event = new FOTreeEvent(this);
+ event.setPageSequence(pageSequence);
+ Iterator iterator = foTreeListeners.iterator();
+ FOTreeListener foTreeListenerItem = null;
+ while (iterator.hasNext()) {
+ foTreeListenerItem = (FOTreeListener)iterator.next();
+ foTreeListenerItem.foPageSequenceComplete(event);
+ }
}
-}
+ /**
+ * Notify all objects in the foTreeListeners that a "Document Complete"
+ * FOTreeEvent has been fired.
+ * @param eventType integer indicating which type of event is created
+ * @param event the Event object that should be passed to the listeners
+ */
+ private void notifyDocumentComplete()
+ throws SAXException {
+ FOTreeEvent event = new FOTreeEvent(this);
+ Iterator iterator = foTreeListeners.iterator();
+ FOTreeListener foTreeListenerItem = null;
+ while (iterator.hasNext()) {
+ foTreeListenerItem = (FOTreeListener)iterator.next();
+ foTreeListenerItem.foDocumentComplete(event);
+ }
+ }
+
+}