From db1b760fee89862bde170ff1f40bd69e5437fb4d Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Sat, 30 Jul 2005 13:32:02 +0000 Subject: Bugzilla #35937: FormattingResults mechanism ported from maintenance branch to trunk. Submitted by: Manuel Mall Patch tweaked slightly to avoid the reference of Fop.java into the area package. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@226511 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/apps/Fop.java | 26 ++++++- .../org/apache/fop/apps/FormattingResults.java | 84 ++++++++++++++++++++++ .../org/apache/fop/apps/PageSequenceResults.java | 58 +++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 src/java/org/apache/fop/apps/FormattingResults.java create mode 100644 src/java/org/apache/fop/apps/PageSequenceResults.java (limited to 'src/java/org/apache/fop/apps') diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index 8e3938686..171a6ce2f 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -61,6 +61,9 @@ public class Fop implements Constants { // FOUserAgent object to set processing options private FOUserAgent foUserAgent = null; + // FOTreeBuilder object to maintain reference for access to results + private FOTreeBuilder foTreeBuilder = null; + /** * Constructor for use with already-created FOUserAgents * @param renderType the type of renderer to use. Must be one of @@ -133,7 +136,28 @@ public class Fop implements Constants { * @throws FOPException if setting up the DefaultHandler fails */ public DefaultHandler getDefaultHandler() throws FOPException { - return new FOTreeBuilder(renderType, foUserAgent, stream); + if (foTreeBuilder == null) { + this.foTreeBuilder = new FOTreeBuilder(renderType, foUserAgent, stream); + } + return this.foTreeBuilder; + } + + /** + * Returns the results of the rendering process. Information includes + * the total number of pages generated and the number of pages per + * page-sequence. Call this method only after the rendering process is + * finished. Note that the results are only available for output formats + * which make use of FOP's layout engine (PDF, PS, etc.). + * @return the results of the rendering process, or null for flow-oriented + * output formats like RTF and MIF. + */ + public FormattingResults getResults() { + if (foTreeBuilder == null) { + throw new IllegalStateException( + "Results are only available after calling getDefaultHandler()."); + } else { + return foTreeBuilder.getResults(); + } } /** diff --git a/src/java/org/apache/fop/apps/FormattingResults.java b/src/java/org/apache/fop/apps/FormattingResults.java new file mode 100644 index 000000000..53c2d816a --- /dev/null +++ b/src/java/org/apache/fop/apps/FormattingResults.java @@ -0,0 +1,84 @@ +/* + * Copyright 1999-2003,2005 The Apache Software Foundation. + * + * Licensed 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.apps; + +import java.util.List; + +import org.apache.fop.fo.pagination.PageSequence; + +/** + * Class for reporting back formatting results to the calling application. + */ +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(); + } + } + + /** + * Reports the result of one page sequence rendering + * back into this object. + * + * @param pageSequence the PageSequence which just completed rendering + * @param pageCount the number of pages rendered for that PageSequence + */ + public void haveFormattedPageSequence(PageSequence pageSequence, int pageCount) { + this.pageCount += pageCount; + if (this.pageSequences == null) { + this.pageSequences = new java.util.ArrayList(); + } + this.pageSequences.add( + new PageSequenceResults(pageSequence.getId(), + pageCount)); + } +} + diff --git a/src/java/org/apache/fop/apps/PageSequenceResults.java b/src/java/org/apache/fop/apps/PageSequenceResults.java new file mode 100644 index 000000000..1819840e3 --- /dev/null +++ b/src/java/org/apache/fop/apps/PageSequenceResults.java @@ -0,0 +1,58 @@ +/* + * Copyright 1999-2003,2005 The Apache Software Foundation. + * + * Licensed 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.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. + */ +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; + } +} -- cgit v1.2.3