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: * PageableExcelOutputProcessor.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.output.table.xls;
030:
031: import java.io.InputStream;
032: import java.io.OutputStream;
033: import java.util.ArrayList;
034: import java.util.Collections;
035: import java.util.List;
036:
037: import org.jfree.report.layout.model.LogicalPageBox;
038: import org.jfree.report.layout.output.ContentProcessingException;
039: import org.jfree.report.layout.output.DisplayAllFlowSelector;
040: import org.jfree.report.layout.output.FlowSelector;
041: import org.jfree.report.layout.output.LogicalPageKey;
042: import org.jfree.report.layout.output.OutputProcessorMetaData;
043: import org.jfree.report.layout.output.PhysicalPageKey;
044: import org.jfree.report.modules.output.pageable.base.PageableOutputProcessor;
045: import org.jfree.report.modules.output.table.base.AbstractTableOutputProcessor;
046: import org.jfree.report.modules.output.table.base.TableContentProducer;
047: import org.jfree.report.modules.output.table.xls.helper.ExcelOutputProcessorMetaData;
048: import org.jfree.report.modules.output.table.xls.helper.ExcelPrinter;
049: import org.jfree.util.Configuration;
050:
051: /**
052: * Creation-Date: 09.05.2007, 14:36:28
053: *
054: * @author Thomas Morgner
055: */
056: public class PageableExcelOutputProcessor extends
057: AbstractTableOutputProcessor implements PageableOutputProcessor {
058: private List physicalPages;
059: private OutputProcessorMetaData metaData;
060: private ExcelPrinter printer;
061: private FlowSelector flowSelector;
062:
063: public PageableExcelOutputProcessor(
064: final Configuration configuration,
065: final OutputStream outputStream) {
066: this .physicalPages = new ArrayList();
067: this .metaData = new ExcelOutputProcessorMetaData(configuration,
068: ExcelOutputProcessorMetaData.PAGINATION_FULL);
069: this .flowSelector = new DisplayAllFlowSelector();
070:
071: this .printer = new ExcelPrinter();
072: this .printer.init(configuration, metaData, outputStream);
073: }
074:
075: public InputStream getTemplateInputStream() {
076: return printer.getTemplateInputStream();
077: }
078:
079: public void setTemplateInputStream(
080: final InputStream templateInputStream) {
081: printer.setTemplateInputStream(templateInputStream);
082: }
083:
084: protected void processingPagesFinished() {
085: super .processingPagesFinished();
086: physicalPages = Collections.unmodifiableList(physicalPages);
087: }
088:
089: public int getPhysicalPageCount() {
090: return physicalPages.size();
091: }
092:
093: public PhysicalPageKey getPhysicalPage(final int page) {
094: if (isPaginationFinished() == false) {
095: throw new IllegalStateException();
096: }
097:
098: return (PhysicalPageKey) physicalPages.get(page);
099: }
100:
101: protected LogicalPageKey createLogicalPage(final int width,
102: final int height) {
103: final LogicalPageKey key = super .createLogicalPage(width,
104: height);
105: for (int h = 0; h < key.getHeight(); h++) {
106: for (int w = 0; w < key.getWidth(); w++) {
107: physicalPages.add(key.getPage(w, h));
108: }
109: }
110: return key;
111: }
112:
113: public OutputProcessorMetaData getMetaData() {
114: return metaData;
115: }
116:
117: public FlowSelector getFlowSelector() {
118: return flowSelector;
119: }
120:
121: public void setFlowSelector(final FlowSelector flowSelector) {
122: this .flowSelector = flowSelector;
123: }
124:
125: protected void processTableContent(
126: final LogicalPageKey logicalPageKey,
127: final LogicalPageBox logicalPage,
128: final TableContentProducer contentProducer)
129: throws ContentProcessingException {
130: printer.print(logicalPageKey, logicalPage, contentProducer,
131: false);
132: }
133:
134: protected void processingContentFinished() {
135: printer.close();
136: }
137: }
|