| 1 |
/** |
| 2 |
* ======================================== |
| 3 |
* JFreeReport : a free Java report library |
| 4 |
* ======================================== |
| 5 |
* |
| 6 |
* Project Info: http://reporting.pentaho.org/ |
| 7 |
* |
| 8 |
* (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. |
| 9 |
* |
| 10 |
* This library is free software; you can redistribute it and/or modify it under the terms |
| 11 |
* of the GNU Lesser General Public License as published by the Free Software Foundation; |
| 12 |
* either version 2.1 of the License, or (at your option) any later version. |
| 13 |
* |
| 14 |
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 |
* See the GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License along with this |
| 19 |
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
* |
| 22 |
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
| 23 |
* in the United States and other countries.] |
| 24 |
* |
| 25 |
* ------------ |
| 26 |
* $Id: StreamingReportProcessor.java 10756 2009-12-02 15:58:24Z tmorgner $ |
| 27 |
* ------------ |
| 28 |
* (C) Copyright 2000-2005, by Object Refinery Limited. |
| 29 |
* (C) Copyright 2005-2007, by Pentaho Corporation. |
| 30 |
*/ |
| 31 |
package org.jfree.report.flow.streaming; |
| 32 |
|
| 33 |
import org.jfree.layouting.DefaultLayoutProcess; |
| 34 |
import org.jfree.layouting.LayoutProcess; |
| 35 |
import org.jfree.layouting.output.OutputProcessor; |
| 36 |
import org.jfree.report.DataSourceException; |
| 37 |
import org.jfree.report.ReportDataFactoryException; |
| 38 |
import org.jfree.report.ReportProcessingException; |
| 39 |
import org.jfree.report.flow.AbstractReportProcessor; |
| 40 |
import org.jfree.report.flow.LibLayoutReportTarget; |
| 41 |
import org.jfree.report.flow.ReportJob; |
| 42 |
import org.pentaho.reporting.libraries.resourceloader.ResourceKey; |
| 43 |
import org.pentaho.reporting.libraries.resourceloader.ResourceManager; |
| 44 |
|
| 45 |
/** |
| 46 |
* This is written to use LibLayout. It will never work with other report |
| 47 |
* targets. |
| 48 |
* |
| 49 |
* @author Thomas Morgner |
| 50 |
*/ |
| 51 |
public class StreamingReportProcessor extends AbstractReportProcessor |
| 52 |
{ |
| 53 |
private OutputProcessor outputProcessor; |
| 54 |
|
| 55 |
public StreamingReportProcessor() |
| 56 |
{ |
| 57 |
} |
| 58 |
|
| 59 |
public OutputProcessor getOutputProcessor() |
| 60 |
{ |
| 61 |
return outputProcessor; |
| 62 |
} |
| 63 |
|
| 64 |
public void setOutputProcessor(final OutputProcessor outputProcessor) |
| 65 |
{ |
| 66 |
this.outputProcessor = outputProcessor; |
| 67 |
} |
| 68 |
|
| 69 |
public void processReport(final ReportJob job) |
| 70 |
throws ReportDataFactoryException, DataSourceException, ReportProcessingException |
| 71 |
{ |
| 72 |
if (job == null) |
| 73 |
{ |
| 74 |
throw new NullPointerException(); |
| 75 |
} |
| 76 |
|
| 77 |
synchronized (job) |
| 78 |
{ |
| 79 |
// first, compute the globals |
| 80 |
processReportRun(job, createTarget(job)); |
| 81 |
// second, paginate (this splits the stream into flows) |
| 82 |
processReportRun(job, createTarget(job)); |
| 83 |
// third, generate the content. |
| 84 |
processReportRun(job, createTarget(job)); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
protected LibLayoutReportTarget createTarget(final ReportJob job) |
| 89 |
throws ReportProcessingException |
| 90 |
{ |
| 91 |
if (outputProcessor == null) |
| 92 |
{ |
| 93 |
throw new IllegalStateException( |
| 94 |
"OutputProcessor is invalid."); |
| 95 |
} |
| 96 |
final LayoutProcess layoutProcess = |
| 97 |
new DefaultLayoutProcess(outputProcessor); |
| 98 |
final ResourceManager resourceManager = job.getReportStructureRoot().getResourceManager(); |
| 99 |
final ResourceKey resourceKey = job.getReportStructureRoot().getBaseResource(); |
| 100 |
|
| 101 |
return new LibLayoutReportTarget |
| 102 |
(job, resourceKey, resourceManager, layoutProcess); |
| 103 |
} |
| 104 |
} |