From b15c07b568d05a40271912074931dee9230754b6 Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Wed, 20 Aug 2003 16:35:27 +0000 Subject: [PATCH] move some fields and methods from Driver to Document git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196814 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/apps/Driver.java | 63 +++---------------- src/java/org/apache/fop/control/Document.java | 61 +++++++++++++++++- .../org/apache/fop/extensions/Bookmarks.java | 2 +- 3 files changed, 68 insertions(+), 58 deletions(-) diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index da23b989a..c93da0a39 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -59,8 +59,6 @@ import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.FOUserAgent; import org.apache.fop.fo.FOInputHandler; import org.apache.fop.fo.FOTreeHandler; -import org.apache.fop.fo.FOTreeListener; -import org.apache.fop.fo.FOTreeEvent; import org.apache.fop.area.Title; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.mif.MIFHandler; @@ -138,7 +136,7 @@ import java.io.OutputStream; * driver.render(parser, fileInputSource(args[0])); * */ -public class Driver implements LogEnabled, FOTreeListener { +public class Driver implements LogEnabled { /** * private constant to indicate renderer was not defined. @@ -236,12 +234,6 @@ public class Driver implements LogEnabled, FOTreeListener { private Logger log = null; private FOUserAgent userAgent = null; - /** - * The current AreaTree for the PageSequence being rendered. - */ - private AreaTree areaTree; - private AreaTreeModel atModel; - private Document currentDocument = null; /** @@ -597,11 +589,11 @@ public class Driver implements LogEnabled, FOTreeListener { try { if (foInputHandler instanceof FOTreeHandler) { FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; - foTreeHandler.addFOTreeListener(this); - this.areaTree = new AreaTree(); - this.atModel = AreaTree.createRenderPagesModel(renderer); + foTreeHandler.addFOTreeListener(currentDocument); + currentDocument.areaTree = new AreaTree(); + currentDocument.atModel = AreaTree.createRenderPagesModel(renderer); //this.atModel = new CachedRenderPagesModel(renderer); - areaTree.setTreeModel(atModel); + currentDocument.areaTree.setTreeModel(currentDocument.atModel); } /** The following statement triggers virtually all of the processing @@ -619,7 +611,7 @@ public class Driver implements LogEnabled, FOTreeListener { parser.parse(source); if (foInputHandler instanceof FOTreeHandler) { FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler; - foTreeHandler.removeFOTreeListener(this); + foTreeHandler.removeFOTreeListener(currentDocument); } } catch (SAXException e) { if (e.getException() instanceof FOPException) { @@ -661,7 +653,7 @@ public class Driver implements LogEnabled, FOTreeListener { initialize(); } - if (renderer == null && rendererType != RENDER_RTF + if (renderer == null && rendererType != RENDER_RTF && rendererType != RENDER_MIF) { setRenderer(RENDER_PDF); } @@ -683,46 +675,5 @@ public class Driver implements LogEnabled, FOTreeListener { } } - /** - * Required by the FOTreeListener interface. It handles an - * FOTreeEvent that is fired when a PageSequence object has been completed. - * @param event the FOTreeEvent that was fired - * @throws FOPException for errors in building the PageSequence - */ - public void foPageSequenceComplete (FOTreeEvent event) throws FOPException { - PageSequence pageSeq = event.getPageSequence(); - Title title = null; - if (pageSeq.getTitleFO() != null) { - title = pageSeq.getTitleFO().getTitleArea(); - } - areaTree.startPageSequence(title); - pageSeq.format(areaTree); - } - - /** - * Required by the FOTreeListener interface. It handles an FOTreeEvent that - * is fired when the Document has been completely parsed. - * @param event the FOTreeEvent that was fired - * @throws SAXException for parsing errors - */ - public void foDocumentComplete (FOTreeEvent event) throws SAXException { - //processAreaTree(atModel); - try { - areaTree.endDocument(); - renderer.stopRenderer(); - } catch (IOException ex) { - throw new SAXException(ex); - } - } - - /** - * Get the area tree for this layout handler. - * - * @return the area tree for this document - */ - public AreaTree getAreaTree() { - return areaTree; - } - } diff --git a/src/java/org/apache/fop/control/Document.java b/src/java/org/apache/fop/control/Document.java index 8096541a8..279dc49b3 100644 --- a/src/java/org/apache/fop/control/Document.java +++ b/src/java/org/apache/fop/control/Document.java @@ -52,19 +52,30 @@ package org.apache.fop.control; // Java import java.util.Map; +import java.io.IOException; // FOP +import org.apache.fop.area.AreaTree; +import org.apache.fop.area.AreaTreeModel; import org.apache.fop.apps.Driver; +import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FOTreeControl; +import org.apache.fop.fo.FOTreeEvent; +import org.apache.fop.fo.FOTreeListener; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.area.Title; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.layout.LayoutStrategy; +// SAX +import org.xml.sax.SAXException; + /** * Class storing information for the FOP Document being processed, and managing * the processing of it. */ -public class Document implements FOTreeControl { +public class Document implements FOTreeControl, FOTreeListener { /** The parent Driver object */ private Driver driver; @@ -85,6 +96,12 @@ public class Document implements FOTreeControl { */ private LayoutStrategy ls = null; + /** + * The current AreaTree for the PageSequence being rendered. + */ + public AreaTree areaTree; + public AreaTreeModel atModel; + /** * Main constructor */ @@ -290,5 +307,47 @@ public class Document implements FOTreeControl { public Driver getDriver() { return driver; } + + /** + * Required by the FOTreeListener interface. It handles an + * FOTreeEvent that is fired when a PageSequence object has been completed. + * @param event the FOTreeEvent that was fired + * @throws FOPException for errors in building the PageSequence + */ + public void foPageSequenceComplete (FOTreeEvent event) throws FOPException { + PageSequence pageSeq = event.getPageSequence(); + Title title = null; + if (pageSeq.getTitleFO() != null) { + title = pageSeq.getTitleFO().getTitleArea(); + } + areaTree.startPageSequence(title); + pageSeq.format(areaTree); + } + + /** + * Required by the FOTreeListener interface. It handles an FOTreeEvent that + * is fired when the Document has been completely parsed. + * @param event the FOTreeEvent that was fired + * @throws SAXException for parsing errors + */ + public void foDocumentComplete (FOTreeEvent event) throws SAXException { + //processAreaTree(atModel); + try { + areaTree.endDocument(); + driver.getRenderer().stopRenderer(); + } catch (IOException ex) { + throw new SAXException(ex); + } + } + + /** + * Get the area tree for this layout handler. + * + * @return the area tree for this document + */ + public AreaTree getAreaTree() { + return areaTree; + } + } diff --git a/src/java/org/apache/fop/extensions/Bookmarks.java b/src/java/org/apache/fop/extensions/Bookmarks.java index 1326a1553..d013028c0 100644 --- a/src/java/org/apache/fop/extensions/Bookmarks.java +++ b/src/java/org/apache/fop/extensions/Bookmarks.java @@ -113,7 +113,7 @@ public class Bookmarks extends ExtensionObj { if (foInputHandler instanceof FOTreeHandler) { FOTreeHandler foth = (FOTreeHandler)foInputHandler; Document doc = (Document)foth.foTreeControl; - AreaTree at = doc.getDriver().getAreaTree(); + AreaTree at = doc.getAreaTree(); at.addTreeExtension(data); data.setAreaTree(at); } -- 2.39.5