From 1e010fd93695ea52901333c85ccb9ca96081f110 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 25 Nov 2014 11:46:16 -0500 Subject: [PATCH] IDEMPIERE-2340 zk - Exporting reports as SSV generates CSV --- .../report/jasper/ReportStarter.java | 7 +++++- .../webui/apps/form/WReportCustomization.java | 8 +++++- .../webui/panel/action/ReportAction.java | 8 +++++- .../adempiere/webui/window/ZkJRViewer.java | 25 ++++++++++++++++++- .../webui/window/ZkReportViewer.java | 8 +++++- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/org.adempiere.report.jasper/src/org/adempiere/report/jasper/ReportStarter.java b/org.adempiere.report.jasper/src/org/adempiere/report/jasper/ReportStarter.java index d704ea1cde..0e3cd5f497 100644 --- a/org.adempiere.report.jasper/src/org/adempiere/report/jasper/ReportStarter.java +++ b/org.adempiere.report.jasper/src/org/adempiere/report/jasper/ReportStarter.java @@ -60,6 +60,7 @@ import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.design.JRDesignQuery; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRCsvExporterParameter; import net.sf.jasperreports.engine.export.JRHtmlExporter; import net.sf.jasperreports.engine.export.JRPdfExporter; import net.sf.jasperreports.engine.export.JRPrintServiceExporter; @@ -714,8 +715,12 @@ public class ReportStarter implements ProcessCall, ClientProcess exporter = new JRPrintServiceExporter(ljrContext); else if (ext.equals("xml")) exporter = new JRXmlExporter(ljrContext); - else if (ext.equals("csv") || ext.equals("ssv")) + else if (ext.equals("csv")) exporter = new JRCsvExporter(ljrContext); + else if (ext.equals("ssv")) { + exporter = new JRCsvExporter(ljrContext); + exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ";"); + } else if (ext.equals("txt")) exporter = new JRTextExporter(ljrContext); else if (ext.equals("html") || ext.equals("htm")) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WReportCustomization.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WReportCustomization.java index d4f08a49ed..cf28bd4715 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WReportCustomization.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WReportCustomization.java @@ -468,12 +468,18 @@ public class WReportCustomization implements IFormController,EventListener re.createXML(sw); data = sw.getBuffer().toString().getBytes(); } - else if (ext.equals("csv") || ext.equals("ssv")) + else if (ext.equals("csv")) { StringWriter sw = new StringWriter(); re.createCSV(sw, ',', re.getPrintFormat().getLanguage()); data = sw.getBuffer().toString().getBytes(); } + else if (ext.equals("ssv")) + { + StringWriter sw = new StringWriter(); + re.createCSV(sw, ';', re.getPrintFormat().getLanguage()); + data = sw.getBuffer().toString().getBytes(); + } else if (ext.equals("txt")) { StringWriter sw = new StringWriter(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java index 95ac9db5e8..11bfd89bf2 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java @@ -14,6 +14,7 @@ import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRCsvExporterParameter; import net.sf.jasperreports.engine.export.JRHtmlExporter; import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; import net.sf.jasperreports.engine.export.JRPdfExporter; @@ -57,7 +58,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl /** * */ - private static final long serialVersionUID = -8378226782387071338L; + private static final long serialVersionUID = -1250003381099609830L; private JasperPrint jasperPrint; private Listbox previewType = new Listbox(); @@ -103,6 +104,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl previewType.appendItem("HTML", "HTML"); previewType.appendItem("Excel", "XLS"); previewType.appendItem("CSV", "CSV"); + previewType.appendItem("SSV", "SSV"); if ("PDF".equals(defaultType)) { previewType.setSelectedIndex(0); } else if ("HTML".equals(defaultType)) { @@ -111,6 +113,8 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl previewType.setSelectedIndex(2); } else if ("CSV".equals(defaultType)) { previewType.setSelectedIndex(3); + } else if ("SSV".equals(defaultType)) { + previewType.setSelectedIndex(4); } else { previewType.setSelectedIndex(0); log.info("Format not Valid: "+defaultType); @@ -126,6 +130,8 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl previewType.setSelectedIndex(0); // default to PDF if cannot export } else if ("CSV".equals(defaultType)) { previewType.setSelectedIndex(0); // default to PDF if cannot export + } else if ("SSV".equals(defaultType)) { + previewType.setSelectedIndex(0); // default to PDF if cannot export } else { previewType.setSelectedIndex(0); log.info("Format not Valid: "+defaultType); @@ -292,6 +298,23 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl exporter.exportReport(); media = new AMedia(m_title, "csv", "application/csv", file, true); + + }else if ("SSV".equals(reportType)) { + String path = System.getProperty("java.io.tmpdir"); + String prefix = makePrefix(jasperPrint.getName()); + if (log.isLoggable(Level.FINE)) + { + log.log(Level.FINE, "Path="+path + " Prefix="+prefix); + } + File file = File.createTempFile(prefix, ".ssv", new File(path)); + FileOutputStream fos = new FileOutputStream(file); + JRCsvExporter exporter= new JRCsvExporter(); + exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ";"); + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos); + exporter.exportReport(); + + media = new AMedia(m_title, "ssv", "application/ssv", file, true); } } finally { Thread.currentThread().setContextClassLoader(cl); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java index b2cbd67eb7..2d0a8ee37a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java @@ -948,12 +948,18 @@ public class ZkReportViewer extends Window implements EventListener, ITab m_reportEngine.createXML(sw); data = sw.getBuffer().toString().getBytes(); } - else if (ext.equals("csv") || ext.equals("ssv")) + else if (ext.equals("csv")) { StringWriter sw = new StringWriter(); m_reportEngine.createCSV(sw, ',', m_reportEngine.getPrintFormat().getLanguage()); data = sw.getBuffer().toString().getBytes(); } + else if (ext.equals("ssv")) + { + StringWriter sw = new StringWriter(); + m_reportEngine.createCSV(sw, ';', m_reportEngine.getPrintFormat().getLanguage()); + data = sw.getBuffer().toString().getBytes(); + } else if (ext.equals("txt")) { StringWriter sw = new StringWriter();