-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBirt4Py.java
98 lines (79 loc) · 3.4 KB
/
Birt4Py.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.DocxRenderOption;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.model.api.SessionHandle;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.HashMap;
import java.io.*;
import java.net.URL;
public class Birt4Py {
private static String report;
private static IReportEngine engine = null;
private static EngineConfig config = null;
public static String getReport() {
return report;
}
public Birt4Py() throws BirtException {
// start up Platform
config = new EngineConfig( );
// Try to load JDBC Driver
config.getAppContext().put("OdaJDBCDriverClassPath", "/usr/lib/jvm/java-8-oracle/jre/lib/ext/postgresql-42.1.4.jar");
Platform.startup( config );
// create new Report Engine
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}
public void executeReport(ArrayList<String> params) throws EngineException {
/*
Params are passed through the /sirenaApp/data_helpers/report_extractor -> get_report_file() -> my_list:
1st: .rptdesign full path -> String
2nd: report file full path -> String
3rd: report extension -> String
*/
// open the report design
IReportRunnable design = null;
System.out.println(params);
design = engine.openReportDesign(params.get(0));
// create RunandRender Task
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// pass necessary parameters
task.validateParameters();
// set render options including output type
RenderOption options;
if (params.get(2) == "doc") {
options = new RenderOption();
}
else if (params.get(2) == "xls") {
options = new EXCELRenderOption();
}
else {
options = new HTMLRenderOption();
}
ByteArrayOutputStream outs = new ByteArrayOutputStream();
options.setOutputStream(outs);
options.setImageHandler(new HTMLServerImageHandler());
options.setOutputFileName(params.get(1));
options.setOutputFormat(params.get(2));
task.setRenderOption(options);
String output;
task.run();
output = outs.toString();
task.close();
report = output;
System.out.println(report);
}
}