_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());
}
*/
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);
}
/**
--- /dev/null
+/*
+ * $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()));
+ }
+}
+
--- /dev/null
+/*
+ * $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;
+ }
+}
+
*/
private Renderer renderer;
+ /**
+ * The formatting results to be handed back to the caller.
+ */
+ private FormattingResults results = new FormattingResults();
+
/**
The FontInfo for this renderer.
*/
return idReferences;
}
+ public FormattingResults getResults() {
+ return this.results;
+ }
+
public void addExtension(ExtensionObj ext) {
extensions.addElement(ext);
}
} 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)
this.streamRenderer = streamRenderer;
}
+ public StreamRenderer getStreamRenderer() {
+ return this.streamRenderer;
+ }
+
/**
* add a mapping from element name to maker.
*
}
public int getCurrentPageNumber() {
- return currentPageNumber;
+ return currentPageNumber;
+ }
+
+ public int getPageCount() {
+ return this.pageCount;
}
private void forcePage(AreaTree areaTree, int firstAvailPageNumber) {