| 1 | |
package org.jtheque.films.services.impl.utils.file.exports; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import net.sf.jasperreports.engine.JRException; |
| 20 | |
import net.sf.jasperreports.engine.JRExporterParameter; |
| 21 | |
import net.sf.jasperreports.engine.JasperCompileManager; |
| 22 | |
import net.sf.jasperreports.engine.JasperPrint; |
| 23 | |
import net.sf.jasperreports.engine.JasperReport; |
| 24 | |
import net.sf.jasperreports.engine.design.JasperDesign; |
| 25 | |
import net.sf.jasperreports.engine.export.JRCsvExporter; |
| 26 | |
import net.sf.jasperreports.engine.xml.JRXmlLoader; |
| 27 | |
import org.jtheque.core.managers.Managers; |
| 28 | |
import org.jtheque.core.managers.log.ILoggingManager; |
| 29 | |
import org.jtheque.films.persistence.od.able.Film; |
| 30 | |
import org.jtheque.films.utils.Constants.Files.FileType; |
| 31 | |
import org.jtheque.films.utils.Constants.Report; |
| 32 | |
import org.jtheque.films.utils.ReportUtils; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public final class CSVExporter extends AbstractExporter<Film> { |
| 40 | |
@Override |
| 41 | |
public boolean canExportTo(FileType fileType) { |
| 42 | 0 | return fileType == FileType.CSV; |
| 43 | |
} |
| 44 | |
|
| 45 | |
@Override |
| 46 | |
public void export(String path) { |
| 47 | |
try { |
| 48 | 0 | JasperDesign jasperDesign = JRXmlLoader.load(getClass().getClassLoader().getResourceAsStream(Report.FORM001_DATA)); |
| 49 | 0 | JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); |
| 50 | |
|
| 51 | 0 | JasperPrint jasperPrint = ReportUtils.configureForm001(jasperReport, getDatas()); |
| 52 | |
|
| 53 | 0 | JRCsvExporter cvsExporter = new JRCsvExporter(); |
| 54 | 0 | cvsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); |
| 55 | 0 | cvsExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, path); |
| 56 | |
|
| 57 | 0 | cvsExporter.exportReport(); |
| 58 | 0 | } catch (JRException e) { |
| 59 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).error(e); |
| 60 | 0 | } |
| 61 | 0 | } |
| 62 | |
} |