01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.plugin.jfreereport.outputs;
14:
15: import java.io.IOException;
16: import java.io.OutputStream;
17:
18: import org.jfree.report.JFreeReport;
19: import org.jfree.report.ReportProcessingException;
20: import org.jfree.report.layout.output.YieldReportListener;
21: import org.jfree.report.modules.output.table.base.StreamReportProcessor;
22: import org.jfree.report.modules.output.table.csv.StreamCSVOutputProcessor;
23:
24: /**
25: * Creation-Date: 07.07.2006, 20:42:17
26: *
27: * @author Thomas Morgner
28: */
29: public class JFreeReportCSVComponent extends
30: AbstractGenerateStreamContentComponent {
31: private static final long serialVersionUID = -6277594193744555596L;
32:
33: public JFreeReportCSVComponent() {
34: }
35:
36: protected String getMimeType() {
37: return "text/csv"; //$NON-NLS-1$
38: }
39:
40: protected String getExtension() {
41: return ".csv"; //$NON-NLS-1$
42: }
43:
44: protected boolean performExport(final JFreeReport report,
45: final OutputStream outputStream) {
46: try {
47: final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor(
48: report.getConfiguration(), outputStream);
49: final StreamReportProcessor reportProcessor = new StreamReportProcessor(
50: report, target);
51: final int yieldRate = getYieldRate();
52: if (yieldRate > 0) {
53: reportProcessor
54: .addReportProgressListener(new YieldReportListener(
55: yieldRate));
56: }
57: reportProcessor.processReport();
58: reportProcessor.close();
59: outputStream.flush();
60:
61: close();
62: return true;
63: } catch (ReportProcessingException e) {
64: return false;
65: } catch (IOException e) {
66: return false;
67: }
68: }
69: }
|