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