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.rtf.StreamRTFOutputProcessor;
22: import org.jfree.report.modules.output.table.base.StreamReportProcessor;
23:
24: /**
25: * Creation-Date: 07.07.2006, 20:42:17
26: *
27: * @author Thomas Morgner
28: */
29: public class JFreeReportRTFComponent extends
30: AbstractGenerateStreamContentComponent {
31: private static final long serialVersionUID = -4095237855917616138L;
32:
33: public JFreeReportRTFComponent() {
34: }
35:
36: protected String getMimeType() {
37: return "application/rtf"; //$NON-NLS-1$
38: }
39:
40: protected String getExtension() {
41: return ".rtf"; //$NON-NLS-1$
42: }
43:
44: protected boolean performExport(final JFreeReport report,
45: final OutputStream outputStream) {
46: try {
47: final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor(
48: report.getConfiguration(), outputStream);
49: final StreamReportProcessor proc = new StreamReportProcessor(
50: report, target);
51: final int yieldRate = getYieldRate();
52: if (yieldRate > 0) {
53: proc.addReportProgressListener(new YieldReportListener(
54: yieldRate));
55: }
56: proc.processReport();
57: proc.close();
58: outputStream.close();
59: close();
60: return true;
61: } catch (ReportProcessingException e) {
62: return false;
63: } catch (IOException e) {
64: return false;
65: }
66: }
67: }
|