18 package org.turro.zkoss.print;
21 import java.io.FileOutputStream;
22 import java.io.InputStream;
23 import java.util.Collection;
25 import java.util.function.Consumer;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import net.sf.jasperreports.engine.JRDataSource;
29 import net.sf.jasperreports.engine.JRException;
30 import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
31 import org.turro.action.MailAttachment;
32 import org.turro.action.MailSenders;
33 import org.turro.elephant.context.Application;
34 import org.turro.elephant.context.ElephantContext;
35 import org.turro.elephant.zkoss.Modal;
36 import org.turro.elephant.zkoss.ModalWindow;
37 import org.turro.plugin.contacts.IContact;
38 import org.zkoss.zkex.zul.Jasperreport;
46 private Jasperreport report;
52 public ReportPrint(String title, String border,
boolean closable)
throws InterruptedException {
53 super(title, border, closable);
64 public static void print(String title, Collection collection, Map parameters, String jasperFile,
65 String defaultFile, String type, String certificateStore)
throws JRException {
66 print(title,
new JRBeanCollectionDataSource(collection), parameters, jasperFile, defaultFile, type, certificateStore);
69 public static void print(String title, JRDataSource dataSource, Map parameters, String jasperFile,
70 String defaultFile, String type, String certificateStore)
throws JRException {
72 reportView.setTitle(title);
77 reportView.
getReport().setSrc(jasperFile);
79 reportView.
getReport().setSrc(defaultFile);
81 reportView.
getReport().setParameters(parameters);
82 reportView.
getReport().setDatasource(dataSource);
87 public static void send(String title, Collection collection, Map parameters, String jasperFile,
88 String defaultFile, String type, String certificateStore, Collection<IContact> contacts, String comment,
89 Collection<MailAttachment> attachments, Consumer onFinish)
throws JRException {
90 send(title,
new JRBeanCollectionDataSource(collection), parameters, jasperFile, defaultFile,
91 type, certificateStore, contacts, comment, attachments, onFinish);
94 public static void send(String title, JRDataSource dataSource, Map parameters, String jasperFile,
95 String defaultFile, String type, String certificateStore, Collection<IContact> contacts, String comment,
96 Collection<MailAttachment> attachments, Consumer onFinish)
throws JRException {
98 if(contacts ==
null)
return;
103 sr.setSrc(jasperFile);
105 sr.setSrc(defaultFile);
107 sr.setParameters(parameters);
108 sr.setDatasource(dataSource);
110 File attach = File.createTempFile(
"attach_",
"_mail");
111 FileOutputStream fos =
new FileOutputStream(attach);
112 InputStream is = sr.getReport().getStreamData();
114 byte[] bytes =
new byte[1024];
115 while ((read = is.read(bytes)) != -1) {
116 fos.write(bytes, 0, read);
127 .addMailAttachments(attachments)
129 .put(
"comment", comment)
131 .put(
"mas", attachments)
133 }
catch (Exception ex) {
static IMailSender getPool()
static Application getApplication()
static String getRealPath(String path)
static String getSiteName()
static String logMsg(String msg)
static int doModal(String file)
static ModalWindow getModal(String file)
void setReport(Jasperreport report)
static void print(String title, JRDataSource dataSource, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore)
static void send(String title, JRDataSource dataSource, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore, Collection< IContact > contacts, String comment, Collection< MailAttachment > attachments, Consumer onFinish)
static void print(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore)
ReportPrint(String title, String border, boolean closable)
static void send(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore, Collection< IContact > contacts, String comment, Collection< MailAttachment > attachments, Consumer onFinish)
void setCertificateStore(String certificateStore)
IMailSender setRoot(String root)