]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Formatting results patch to enable embedders to obtain info from render doc
authorKeiron Liddle <keiron@apache.org>
Thu, 3 Jan 2002 10:39:56 +0000 (10:39 +0000)
committerKeiron Liddle <keiron@apache.org>
Thu, 3 Jan 2002 10:39:56 +0000 (10:39 +0000)
Submitted by: Jeremias Maerki <jeremias.maerki@outline.ch>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@194614 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/apps/Driver.java
src/org/apache/fop/apps/FormattingResults.java [new file with mode: 0644]
src/org/apache/fop/apps/PageSequenceResults.java [new file with mode: 0644]
src/org/apache/fop/apps/StreamRenderer.java
src/org/apache/fop/fo/FOTreeBuilder.java
src/org/apache/fop/fo/pagination/PageSequence.java

index 203d062e14b4e38f6718848e6807b93b70333aef..28438d75ef7c5ab6a9fafe0ea7097852587cf892 100644 (file)
@@ -241,6 +241,19 @@ public class Driver implements Loggable {
         _treeBuilder.reset();
     }
 
+    /**
+     * Returns the results of the last rendering process. Information includes
+     * the total number of pages generated and the number of pages per
+     * page-sequence.
+     */
+    public FormattingResults getResults() {
+        try {
+            return _treeBuilder.getStreamRenderer().getResults();
+        } catch (NullPointerException e) {
+            return null;
+        }
+    }
+
     public boolean hasData() {
         return (_treeBuilder.hasData());
     }
@@ -483,19 +496,9 @@ public class Driver implements Loggable {
      */
     public synchronized void render(Document document)
     throws FOPException {
-
-        try {
-            DocumentInputSource source = new DocumentInputSource(document);
-            DocumentReader reader = new DocumentReader();
-            reader.setContentHandler(getContentHandler());
-            reader.parse(source);
-        } catch (SAXException e) {
-            throw new FOPException(e);
-        }
-        catch (IOException e) {
-            throw new FOPException(e);
-        }
-
+         DocumentInputSource source = new DocumentInputSource(document);
+         DocumentReader reader = new DocumentReader();
+         render(reader, source);
     }
 
     /**
diff --git a/src/org/apache/fop/apps/FormattingResults.java b/src/org/apache/fop/apps/FormattingResults.java
new file mode 100644 (file)
index 0000000..546a523
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.apps;
+
+import java.util.List;
+
+import org.apache.fop.fo.pagination.PageSequence;
+
+/**
+ * Class for reporting back formatting results to the calling application.
+ *
+ * @author    Jeremias Maerki
+ */
+public class FormattingResults {
+
+    private int pageCount = 0;
+    private List pageSequences = null;
+
+    /**
+     * Constructor for the FormattingResults object
+     */
+    public FormattingResults() {
+    }
+
+    /**
+     * Gets the number of pages rendered
+     *
+     * @return   The number of pages overall
+     */
+    public int getPageCount() {
+        return this.pageCount;
+    }
+
+    /**
+     * Gets the results for the individual page-sequences.
+     *
+     * @return   A List with PageSequenceResults objects
+     */
+    public List getPageSequences() {
+        return this.pageSequences;
+    }
+
+    /**
+     * Resets this object
+     */
+    public void reset() {
+        this.pageCount = 0;
+        if (this.pageSequences != null) {
+            this.pageSequences.clear();
+        }
+    }
+
+    /**
+     * Description of the Method
+     *
+     * @param pageSequence  Description of Parameter
+     */
+    public void haveFormattedPageSequence(PageSequence pageSequence) {
+        this.pageCount += pageSequence.getPageCount();
+        if (this.pageSequences == null) {
+            this.pageSequences = new java.util.ArrayList();
+        }
+        this.pageSequences.add(
+                new PageSequenceResults(pageSequence.getProperty("id").getString(),
+                                        pageSequence.getPageCount()));
+    }
+}
+
diff --git a/src/org/apache/fop/apps/PageSequenceResults.java b/src/org/apache/fop/apps/PageSequenceResults.java
new file mode 100644 (file)
index 0000000..eee11a0
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.apps;
+
+/**
+ * Class for reporting back formatting results to the calling application. This
+ * particular class is used to report the results of a single page-sequence.
+ *
+ * @author    Jeremias Maerki
+ */
+public class PageSequenceResults {
+
+    private String id;
+    private int pageCount;
+
+    /**
+     * Constructor for the PageSequenceResults object
+     *
+     * @param id         ID of the page-sequence, if available
+     * @param pageCount  The number of resulting pages
+     */
+    public PageSequenceResults(String id, int pageCount) {
+        this.id = id;
+        this.pageCount = pageCount;
+    }
+
+    /**
+     * Gets the ID of the page-sequence if one was specified.
+     *
+     * @return   The ID
+     */
+    public String getID() {
+        return this.id;
+    }
+
+    /**
+     * Gets the number of pages that resulted by processing the page-sequence.
+     *
+     * @return   The number of pages generated
+     */
+    public int getPageCount() {
+        return this.pageCount;
+    }
+}
+
index cb3da874489896025bf3a53df32ed7ad63356c7e..c463eceed83ff648a5b67e67e18b917e45c6e0ed 100644 (file)
@@ -65,6 +65,11 @@ public class StreamRenderer {
     */
     private Renderer renderer;
 
+    /**
+     * The formatting results to be handed back to the caller.
+     */
+    private FormattingResults results = new FormattingResults();
+
     /**
       The FontInfo for this renderer.
     */
@@ -102,6 +107,10 @@ public class StreamRenderer {
         return idReferences;
     }
 
+    public FormattingResults getResults() {
+        return this.results;
+    }
+
     public void addExtension(ExtensionObj ext) {
         extensions.addElement(ext);
     }
@@ -192,6 +201,8 @@ public class StreamRenderer {
         } catch (FOPException e) {
             throw new SAXException(e);
         }
+        this.results.haveFormattedPageSequence(pageSequence);
+        log.debug("Last page-sequence produced "+pageSequence.getPageCount()+" pages.");
     }
 
     public synchronized void queuePage(Page page)
index 4e4cefafe8d1c17335cd871d910146f8ca9eadbe..8adcc0141dfe202c5c6be7358c40f2bf40410e4c 100644 (file)
@@ -92,6 +92,10 @@ public class FOTreeBuilder extends DefaultHandler implements TreeBuilder {
         this.streamRenderer = streamRenderer;
     }
 
+    public StreamRenderer getStreamRenderer() {
+        return this.streamRenderer;
+    }
+
     /**
      * add a mapping from element name to maker.
      *
index b0dbfb43c30925b272d2009bf4ea7b93f27fbad7..36b3752a28378b9818ace2be9c48938369c9735e 100644 (file)
@@ -613,7 +613,11 @@ public class PageSequence extends FObj {
     }
 
     public int getCurrentPageNumber() {
-        return currentPageNumber;
+        return currentPageNumber; 
+    }
+
+    public int getPageCount() {
+       return this.pageCount;
     }
 
     private void forcePage(AreaTree areaTree, int firstAvailPageNumber) {