KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > outputs > JFreeReportExcelComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * 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 JavaDoc;
16 import java.io.InputStream JavaDoc;
17 import java.io.OutputStream JavaDoc;
18
19 import org.jfree.report.JFreeReport;
20 import org.jfree.report.ReportProcessingException;
21 import org.jfree.report.modules.output.table.xls.ExcelProcessor;
22 import org.pentaho.messages.Messages;
23 import org.pentaho.plugin.jfreereport.helper.YieldReportListener;
24
25 /**
26  * Creation-Date: 07.07.2006, 20:42:17
27  *
28  * @author Thomas Morgner
29  */

30 public class JFreeReportExcelComponent extends AbstractGenerateStreamContentComponent {
31     private static final long serialVersionUID = -2130145967763406737L;
32
33
34     public JFreeReportExcelComponent() {
35     }
36
37     protected String JavaDoc getMimeType() {
38         return "application/vnd.ms-excel"; //$NON-NLS-1$
39
}
40
41     protected String JavaDoc getExtension() {
42         return ".xls"; //$NON-NLS-1$
43
}
44
45     protected boolean performExport(final JFreeReport report, final OutputStream JavaDoc outputStream) {
46         try {
47             ExcelProcessor processor = new ExcelProcessor(report);
48             processor.setOutputStream(outputStream);
49
50             if (isDefinedInput(WORKBOOK_PARAM)) {
51                 try {
52                     InputStream JavaDoc inputStream = getInputStream(WORKBOOK_PARAM);
53                     processor.setInputStream(inputStream);
54                 } catch (Exception JavaDoc e) {
55                     error(Messages.getString("JFreeReportExcelComponent.ERROR_0037_ERROR_READING_REPORT_INPUT"), e); //$NON-NLS-1$
56
return false;
57                 }
58             }
59
60             processor.processReport();
61             final int yieldRate = getYieldRate();
62             if (yieldRate > 0) {
63                 processor.addRepaginationListener(new YieldReportListener(yieldRate));
64             }
65             outputStream.close();
66             return true;
67         } catch (ReportProcessingException e) {
68             return false;
69         } catch (IOException JavaDoc e) {
70             return false;
71         }
72     }
73 }
74
Popular Tags