KickJava   Java API By Example, From Geeks To Geeks.

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


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.OutputStream JavaDoc;
16
17 import org.jfree.report.JFreeReport;
18 import org.jfree.report.ReportProcessingException;
19 import org.jfree.report.modules.output.pageable.base.OutputTargetException;
20 import org.jfree.report.modules.output.pageable.base.PageableReportProcessor;
21 import org.jfree.report.modules.output.pageable.pdf.PDFOutputTarget;
22 import org.pentaho.plugin.jfreereport.helper.YieldReportListener;
23
24 /**
25  * Creation-Date: 07.07.2006, 20:42:17
26  *
27  * @author Thomas Morgner
28  */

29 public class JFreeReportPdfComponent extends AbstractGenerateStreamContentComponent {
30     private static final long serialVersionUID = 3209507821690330555L;
31
32     public JFreeReportPdfComponent() {
33     }
34
35     protected String JavaDoc getMimeType() {
36         return "application/pdf"; //$NON-NLS-1$
37
}
38
39     protected String JavaDoc getExtension() {
40         return ".pdf"; //$NON-NLS-1$
41
}
42
43     protected boolean performExport(final JFreeReport report, final OutputStream JavaDoc outputStream) {
44         try {
45             PageableReportProcessor processor = new PageableReportProcessor(report);
46             PDFOutputTarget target = new PDFOutputTarget(outputStream);
47             target.configure(report.getReportConfiguration());
48             processor.setOutputTarget(target);
49             final int yieldRate = getYieldRate();
50             if (yieldRate > 0) {
51                 processor.addRepaginationListener(new YieldReportListener(yieldRate));
52             }
53             target.open();
54             processor.processReport();
55             target.close();
56             return true;
57         } catch (ReportProcessingException e) {
58             return false;
59         } catch (OutputTargetException e) {
60             return false;
61         }
62     }
63 }
64
Popular Tags