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