Java calls the script dataset set by Birt.

Source: Internet
Author: User

Step 1: Define Java and class (see the attachment below)
Step 2: define a list
Step 3: Enter
Count = 0;
Cf = new packages. User. contactlistfactory ();
C = Cf. createcontactlist ();
In the dataset event of the Birt report (close), enter
Cf = NULL; C = NULL;
In the dataset event (FETCH) of the Birt report, enter
If (count <= C. Length-1 ){
Row ["columnfirstname"] = C [count]. getfname ();
Row ["columnlastname"] = C [count]. getlname ();
Row ["columnphonenumber"] = C [count]. getphone ();
Count ++; return true ;}
Return false;
-

######################################## #######

Attachment

######################################## ########

Two Java class codes in step 1 are issued:
A: Package user;
Public class contact {
String fname;
String lname;
String phone;
Public contact (string fname, string lname, string phone ){
This. fname = fname;
This. lname = lname;
This. Phone = phone;
}
/*
*
* @ Return returns the fname.
*/
Public String getfname (){
Return fname;
}
/**
* @ Param fname the fname to set.
*/
Public void setfname (string fname ){
This. fname = fname;
}
/**
* @ Return returns the lname.
*/
Public String getlname (){
Return lname;
}
/**
* @ Param lname the lname to set.
*/
Public void setlname (string lname ){
This. lname = lname;
}
/**
* @ Return returns the phone.
*/
Public String getphone (){
Return phone;
}
/**
* @ Param phone the phone to set.
*/
Public void setphone (string phone ){
This. Phone = phone;
}
}


B:
Package user;
Public class contactlistfactory {
Public contact [] createcontactlist (){
Contact [] C = new contact [5];
C [0] = new contact ("Stavros", "kounis", "2310886269 ");
C [1] = new contact ("Dimitris", "kounis", "2310888270 ");
C [2] = new contact ("Dimitris", "Adamos", "2310998417 ");
C [3] = new contact ("Nikos", "koufotolis", "2321013770 ");
C [4] = new contact ("Yan", "Liang", "13824745919 ");
Return C;
}
}

Note: After the release, place the classes generated by the two Java classes in
C:/Eclipse/plugins/org. Eclipse. Birt. Report. viewer_2.1.0.N20060628-1351/Birt/WEB-INF/classes/user directory,
User is the package during development.

Write a Java Project
The code for calling the preceding report is as follows:

Package user;
Import javax. Swing. joptionpane;
Import user. executereport;
Public class reporttest {
Public static void main (string ARGs []) {
Try {
Executereport mreport = new executereport ();
Mreport.exe cutereport ();
} Catch (exception e ){
E. printstacktrace ();
}
/* System. Out. println ("people's solutions of China ");
Joptionpane. showmessagedialog (null, "Chinese people's solutions ");
System. Exit (0 );
*/
}
}


Main Code Java:

Package user;
Import java. util. collection;
Import java. util. hashmap;
Import java. util. Logging. level;
Import javax.swing.text.html. htmldocument. iterator;
Import org. Eclipse. Birt. Core. Framework. Platform;
Import org. Eclipse. Birt. Report. Engine. API. engineconfig;
Import org. Eclipse. Birt. Report. Engine. API. engineconstants;
Import org. Eclipse. Birt. Report. Engine. API. engineexception;
Import org. Eclipse. Birt. Report. Engine. API. htmlactionhandler;
Import org. Eclipse. Birt. Report. Engine. API. htmlemitterconfig;
Import org. Eclipse. Birt. Report. Engine. API. htmlrendercontext;
Import org. Eclipse. Birt. Report. Engine. API. htmlrenderoption;
Import org. Eclipse. Birt. Report. Engine. API. htmlserverimagehandler;
Import org. Eclipse. Birt. Report. Engine. API. igetparameterdefinitiontask;
Import org. Eclipse. Birt. Report. Engine. API. iparameterdefnbase;
Import org. Eclipse. Birt. Report. Engine. API. iparametergroupdefn;
Import org. Eclipse. Birt. Report. Engine. API. iparameterselectionchoice;
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. Engine. API. iscalarparameterdefn;
Public class executereport {
Static void executereport () throws engineexception {
Ireportengine engine = NULL;
Engineconfig Config = NULL;
Try {
// Configure the engine and start the Platform
Config = new engineconfig ();
Config. setenginehome ("C:/Eclipse/workspace/reportdrive/birt-runtime-2_1_0/reportengine ");
Config. setlogconfig (null, level. Fine );
Platform. startup (config );
Ireportenginefactory factory = (ireportenginefactory) platform. createfactoryobject (ireportenginefactory. extension_report_engine_factory );
Engine = factory. createreportengine (config );
Engine. changeloglevel (level. Warning );
} Catch (exception ex ){
Ex. printstacktrace ();
}
Ireportrunnable design = NULL;
// Open the report Design
Design = engine. openreportdesign ("C:/Eclipse/workspace/html/kenscripdataset. rptdesign ");
Irunandrendertask task = engine. createrunandrendertask (Design );
// Set rendering options-such as file or stream output,
// Output format, whether it is embeddable, etc
Htmlrenderoption Options = new htmlrenderoption ();
/*************************************** ***********/

Hashmap parameters = new hashmap ();
String name = "myreportname ";
String pvalue = "customer product process table ";
Parameters. Put (name, pvalue );
Task. setparametervalues (parameters );
Task. validateparameters ();
/*************************************** ***********/

Options. setoutputfilename ("C:/Eclipse/workspace/html/kenscripdatasettings ");
// Set output format options. setoutputformat ("pdf ");
Task. setrenderoption (options );
// Run the report and destroy the engine
// Note-if the program stays resident do not shutdown the platform or the engine
Task. Run ();
Task. Close ();
Engine. Shutdown ();
Platform. Shutdown ();
System. Out. println ("finished ");
System. Exit (0 );
}
}

----------------------------------------
Add it to the path build of eclispe 3.2
Birt com. IBM. icu_3.4.4.1. Jar Birt
Engineapi. Jar Birt coreapi. Jar Birt Js. Jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.