KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.print.DocFlavor JavaDoc;
16 import javax.print.PrintException JavaDoc;
17 import javax.print.PrintService JavaDoc;
18 import javax.print.PrintServiceLookup JavaDoc;
19
20 import org.jfree.report.JFreeReport;
21 import org.jfree.report.ReportProcessingException;
22 import org.jfree.report.ext.modules.java14print.Java14PrintUtil;
23 import org.jfree.report.modules.gui.print.PrintUtil;
24 import org.pentaho.plugin.core.StandardSettings;
25
26 /**
27  * Creation-Date: 07.07.2006, 20:06:56
28  *
29  * @author Thomas Morgner
30  */

31 public class JFreeReportPrintComponent extends AbstractGenerateContentComponent {
32     private static final long serialVersionUID = 3365941892457480119L;
33
34     public JFreeReportPrintComponent() {
35     }
36
37     private PrintService JavaDoc findPrintService(String JavaDoc name) {
38         final PrintService JavaDoc[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
39         for (int i = 0; i < services.length; i++) {
40             PrintService JavaDoc service = services[i];
41             if (service.getName().equals(name)) {
42                 return service;
43             }
44         }
45
46         if (services.length == 0) {
47             return null;
48         }
49         return services[0];
50     }
51
52     protected boolean performExport(final JFreeReport report) {
53         final String JavaDoc printerName = getInputStringValue(StandardSettings.PRINTER_NAME);
54         final Object JavaDoc jobName = getActionTitle();
55
56         if (jobName instanceof String JavaDoc) {
57             report.getReportConfiguration().setConfigProperty(PrintUtil.PRINTER_JOB_NAME_KEY, String.valueOf(jobName));
58         }
59
60         final PrintService JavaDoc printer = findPrintService(printerName);
61         try {
62             Java14PrintUtil.printDirectly(report, printer);
63         } catch (PrintException JavaDoc e) {
64             return false;
65         } catch (ReportProcessingException e) {
66             return false;
67         }
68         return true;
69     }
70 }
71
Popular Tags