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.InputStream;
17: import java.io.OutputStream;
18:
19: import org.jfree.report.JFreeReport;
20: import org.jfree.report.ReportProcessingException;
21: import org.jfree.report.layout.output.YieldReportListener;
22: import org.jfree.report.modules.output.table.xls.FlowExcelOutputProcessor;
23: import org.jfree.report.modules.output.table.base.FlowReportProcessor;
24: import org.pentaho.messages.Messages;
25:
26: /**
27: * Creation-Date: 07.07.2006, 20:42:17
28: *
29: * @author Thomas Morgner
30: */
31: public class JFreeReportExcelComponent extends
32: AbstractGenerateStreamContentComponent {
33: private static final long serialVersionUID = -2130145967763406737L;
34:
35: public JFreeReportExcelComponent() {
36: }
37:
38: protected String getMimeType() {
39: return "application/vnd.ms-excel"; //$NON-NLS-1$
40: }
41:
42: protected String getExtension() {
43: return ".xls"; //$NON-NLS-1$
44: }
45:
46: protected boolean performExport(final JFreeReport report,
47: final OutputStream outputStream) {
48: try {
49: final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(
50: report.getConfiguration(), outputStream);
51: final FlowReportProcessor reportProcessor = new FlowReportProcessor(
52: report, target);
53:
54: if (isDefinedInput(WORKBOOK_PARAM)) {
55: try {
56: final InputStream inputStream = getInputStream(WORKBOOK_PARAM);
57: target.setTemplateInputStream(inputStream);
58: } catch (Exception e) {
59: error(
60: Messages
61: .getString("JFreeReportExcelComponent.ERROR_0037_ERROR_READING_REPORT_INPUT"), e); //$NON-NLS-1$
62: return false;
63: }
64: }
65:
66: final int yieldRate = getYieldRate();
67: if (yieldRate > 0) {
68: reportProcessor
69: .addReportProgressListener(new YieldReportListener(
70: yieldRate));
71: }
72: reportProcessor.processReport();
73: reportProcessor.close();
74: outputStream.flush();
75: close();
76: return true;
77: } catch (ReportProcessingException e) {
78: return false;
79: } catch (IOException e) {
80: return false;
81: }
82: }
83: }
|