01: /*
02: * To change this template, choose Tools | Templates
03: * and open the template in the editor.
04: */
05:
06: package it.businesslogic.ireport.export;
07:
08: import it.businesslogic.ireport.util.Misc;
09: import java.io.File;
10: import java.io.IOException;
11: import net.sf.jasperreports.engine.JRAbstractExporter;
12: import net.sf.jasperreports.engine.JRException;
13: import net.sf.jasperreports.engine.JRExporterParameter;
14: import net.sf.jasperreports.engine.JasperPrint;
15: import net.sf.jasperreports.engine.util.JRLoader;
16: import net.sf.jasperreports.engine.util.JRSaver;
17: import net.sf.jasperreports.export.flex.JRSwfExporter;
18:
19: /**
20: *
21: * @author gtoffoli
22: */
23: public class FlashExporter extends JRAbstractExporter {
24:
25: public static void main(String[] args) {
26: // 1. jrprint
27: // 2. output file
28:
29: String sourceName = args[0];
30: String fileName = args[1];
31:
32: try {
33: File sourceFile = new File(sourceName);
34: JasperPrint jasperPrint = (JasperPrint) JRLoader
35: .loadObject(sourceFile);
36: JRSwfExporter exporter = new JRSwfExporter();
37: exporter.setParameter(JRExporterParameter.JASPER_PRINT,
38: jasperPrint);
39: exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
40: new File(fileName).getAbsolutePath());
41: exporter
42: .setParameter(
43: net.sf.jasperreports.export.flex.JRSwfExporterParameter.SUPPRESS_COMPILER_MESSAGES,
44: false);
45: //exporter.setParameter(JRSwfExporterParameter.IS_EMBEDDING_IMAGES, Boolean.FALSE);
46: //exporter.setParameter(JRSwfExporterParameter.IS_EMBEDDING_FONTS, Boolean.FALSE);
47: //exporter.setParameter(JRSwfExporterParameter.IS_USE_NETWORK, Boolean.TRUE);
48:
49: System.out.println("Exporting to file " + fileName);
50: System.out.flush();
51:
52: exporter.exportReport();
53: } catch (Exception e) {
54: e.printStackTrace();
55: }
56:
57: }
58:
59: public void exportReport() throws JRException {
60: try {
61:
62: JasperPrint jasperPrint = (JasperPrint) getParameter(JRExporterParameter.JASPER_PRINT);
63: String outputFileName = (String) getParameter(JRExporterParameter.OUTPUT_FILE_NAME);
64: outputFileName = Misc.changeFileExtension(outputFileName,
65: ".jrprint");
66:
67: String swfOutputFileName = (String) getParameter(JRExporterParameter.OUTPUT_FILE_NAME);
68: File swfOutputFile = new File(swfOutputFileName);
69: if (swfOutputFile.exists())
70: swfOutputFile.delete();
71:
72: JRSaver.saveObject(jasperPrint, outputFileName);
73: FlashExporterExecuter executer = new FlashExporterExecuter();
74: executer.setJrprintFile(outputFileName);
75: executer.setOutputFile(swfOutputFileName);
76: executer.execute();
77: // Delete the jrprint...
78: File f = new File(outputFileName);
79: if (f.exists())
80: f.delete();
81: if (!swfOutputFile.exists()) {
82: throw new JRException(
83: "Exception occurred. Unable to create the SWF file.");
84: }
85:
86: } catch (IOException ex) {
87: throw new JRException(ex);
88: }
89: }
90:
91: }
|