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.JRTextExporter; |
26 | |
import net.sf.jasperreports.engine.export.JRTextExporterParameter; |
27 | |
import net.sf.jasperreports.engine.xml.JRXmlLoader; |
28 | |
import org.jtheque.core.managers.Managers; |
29 | |
import org.jtheque.core.managers.log.ILoggingManager; |
30 | |
import org.jtheque.films.persistence.od.FilmImpl; |
31 | |
import org.jtheque.films.services.impl.utils.search.Search; |
32 | |
import org.jtheque.films.utils.Constants.Files.FileType; |
33 | |
import org.jtheque.films.utils.Constants.Report; |
34 | |
import org.jtheque.films.utils.ReportUtils; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class TexteExporter extends AbstractExporter { |
42 | |
@Override |
43 | |
public boolean canExportTo(FileType fileType) { |
44 | 0 | return fileType == FileType.TXT; |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
@SuppressWarnings("unchecked") |
49 | |
public void export(String path) { |
50 | 0 | Search<FilmImpl> search = (Search<FilmImpl>) getSearch(); |
51 | |
|
52 | |
try { |
53 | 0 | JasperDesign jasperDesign = JRXmlLoader.load(getClass().getClassLoader().getResourceAsStream(Report.FORM001_TEXT)); |
54 | 0 | JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); |
55 | |
|
56 | 0 | JasperPrint jasperPrint = ReportUtils.configureForm001(jasperReport, search.getResults()); |
57 | |
|
58 | 0 | JRTextExporter textExporter = new JRTextExporter(); |
59 | 0 | textExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); |
60 | 0 | textExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, path); |
61 | 0 | textExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, 10); |
62 | 0 | textExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, 10); |
63 | 0 | textExporter.exportReport(); |
64 | 0 | } catch (JRException e) { |
65 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).exception(e); |
66 | 0 | } |
67 | 0 | } |
68 | |
} |