001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * StreamingRenderer.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout;
030:
031: import org.jfree.report.layout.model.LogicalPageBox;
032: import org.jfree.report.layout.output.ContentProcessingException;
033: import org.jfree.report.layout.output.IterativeOutputProcessor;
034: import org.jfree.report.layout.output.LayoutPagebreakHandler;
035: import org.jfree.report.layout.output.OutputProcessor;
036: import org.jfree.report.layout.output.OutputProcessorFeature;
037: import org.jfree.report.layout.process.ApplyAutoCommitPageHeaderStep;
038: import org.jfree.report.layout.process.CleanFlowBoxesStep;
039:
040: /**
041: * The streaming renderer streams all generated (and layouted) elements to the output processor. The output processor
042: * should mark the processed elements by setting the 'dirty' flag to false. Pagebreaks will be ignored, all content ends
043: * up in a single stream of data.
044: *
045: * @author Thomas Morgner
046: */
047: public class StreamingRenderer extends AbstractRenderer {
048: private CleanFlowBoxesStep cleanBoxesStep;
049: private ApplyAutoCommitPageHeaderStep applyAutoCommitPageHeaderStep;
050:
051: public StreamingRenderer(final OutputProcessor outputProcessor) {
052: super (outputProcessor);
053: this .cleanBoxesStep = new CleanFlowBoxesStep();
054: this .applyAutoCommitPageHeaderStep = new ApplyAutoCommitPageHeaderStep();
055: }
056:
057: protected boolean isPageFinished() {
058: if (getPageBox().isOpen()) {
059: return false;
060: }
061: return true;
062: }
063:
064: public void processIncrementalUpdate(final boolean performOutput)
065: throws ContentProcessingException {
066:
067: if (isDirty() == false) {
068: // Log.debug ("Not dirty, no update needed.");
069: return;
070: }
071: clearDirty();
072:
073: final OutputProcessor outputProcessor = getOutputProcessor();
074: if (outputProcessor instanceof IterativeOutputProcessor == false
075: || outputProcessor.getMetaData().isFeatureSupported(
076: OutputProcessorFeature.ITERATIVE_RENDERING) == false) {
077: // Log.debug ("No incremental system.");
078: return;
079: }
080:
081: // Log.debug ("Computing Incremental update.");
082:
083: final LogicalPageBox pageBox = getPageBox();
084: pageBox.setPageOffset(0);
085: pageBox.setPageEnd(pageBox.getHeight());
086: // shiftBox(pageBox, true);
087:
088: if (pageBox.isOpen()) {
089: final IterativeOutputProcessor io = (IterativeOutputProcessor) outputProcessor;
090: if (applyAutoCommitPageHeaderStep.compute(pageBox)) {
091: io.processIterativeContent(pageBox, performOutput);
092: cleanBoxesStep.compute(pageBox);
093: }
094: }
095: }
096:
097: protected boolean performPagination(
098: final LayoutPagebreakHandler handler,
099: final boolean performOutput)
100: throws ContentProcessingException {
101: if (performOutput == false) {
102: return false;
103: }
104:
105: final OutputProcessor outputProcessor = getOutputProcessor();
106: final LogicalPageBox pageBox = getPageBox();
107:
108: // This is fixed: The streaming renderers always use the whole page area ..
109: pageBox.setPageOffset(0);
110: pageBox.setPageEnd(pageBox.getHeight());
111:
112: if (pageBox.isOpen()) {
113: // Not finished and the output target is non-iterative, so we have to wait until everything is done..
114: return false;
115: }
116:
117: // the reporting finally came to an end. Lets process the content.
118: // shiftBox(pageBox, false);
119: applyAutoCommitPageHeaderStep.commitAll(pageBox);
120: outputProcessor.processContent(pageBox);
121: cleanBoxesStep.compute(pageBox);
122: debugPrint(pageBox);
123: outputProcessor.processingFinished();
124:
125: setPagebreaks(1);
126: return false;
127: }
128:
129: protected void debugPrint(final LogicalPageBox pageBox) {
130: // Log.debug("**** Start Printing Page: " + 1);
131: // ModelPrinter.print(pageBox);
132: // Log.debug("**** Done Printing Page: " + 1);
133: }
134:
135: public void createRollbackInformation() {
136: throw new UnsupportedOperationException(
137: "Streaming-Renderer do not implement the createRollbackInformation-method.");
138: }
139:
140: public void applyRollbackInformation() {
141: throw new UnsupportedOperationException(
142: "Streaming-Renderer do not implement the applyRollbackInformation method.");
143: }
144:
145: public void rollback() {
146: throw new UnsupportedOperationException(
147: "Streaming-Renderer do not implement the rollback method.");
148: }
149: }
|