forked from sangkil/sangkilbiz3
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_bridge.php
88 lines (74 loc) · 2.66 KB
/
test_bridge.php
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
<?php require_once("java/Java.inc");
/**
* This example demonstrates how to use a complex library such as
* Eclipse BIRT. This library starts a number of threads, which must
* be terminated before the library is unloaded. This is usually done
* in the servlet's destroy() method or in the destroy() method of
* an associated ServletContextListener.
*
* To allow startup and shutdown of such libraries, the PHP/Java
* Bridge provides two convenience procedures, which allow one to run
* a synchronized init() and to register a close() hook with the
* servlet or the VM. Please see the API documentation of
* java_context()->init() and java_context()->onShutdown() for
* details.
*
* To use this sample, copy "report.php", "test.rptdesign" (and
* "Java.inc", if needed) to some directory, start the Java back- end
* (tomcat, or any other J2EE server) and type:
*
* php report.php >helloBirt.html
*
*/
// the report file to render
$myReport = "test.rptdesign";
// the output format
$myFormat = "html";
// load resources from the current working dir
$here = getcwd();
$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
function getOutputFormat($format)
{
$fmt = null;
switch ($format) {
case "pdf":
$fmt = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
$fmt->setOutputFormat("pdf");
header("Content-type: application/pdf");
break;
case "html":
$fmt = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$fmt->setOutputFormat("html");
$ih = new java( "org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
$fmt->setImageHandler($ih);
header("Content-type: text/html");
break;
case "msword":
$fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
$fmt->setOutputFormat("doc");
header("Content-type: application/msword");
break;
case "xls":
$fmt = new java("org.eclipse.birt.report.engine.api.RenderOption");
$fmt->setOutputFormat("xls");
header("Content-type: application/vnd.ms-excel");
break;
default: die("unknown output format $format");
}
return $fmt;
}
try {
$engine = $birtReportEngine->openReportDesign("${here}/${myReport}");
$task = $birtReportEngine->createRunAndRenderTask($engine);
$fmt = getOutputFormat($myFormat);
$fmt->setOutputStream($out=new java("java.io.ByteArrayOutputStream"));
$task->setRenderOption($fmt);
$task->run();
$task->close();
} catch (JavaException $e) {
echo $e;
}
echo java_values($out->toByteArray());
?>