JReport Client API is intended for users who want to compile the program by themselves, or integrate JReport Enterprise Viewer with their own java application. JReport Enterprise Viewer and JReport Viewer Bean are all based on JReport Client API. Just like JReport Enterprise Viewer, JReport Client API allows users to view reports in the server and set up scheduled tasks.
When you install JReport Enterprise Viewer, JReport Client API will be installed at the same time. After installation, you should have the components <JREntViewer_Install_Dir>\lib\JREntViewer.zip.
Notes: Client API classes are stored in the archive files - JREntViewer.zip. You need to set the CLASSPATH environment variable before you compile and run the program. Append the following string to your CLASSPATH starting the client API:
<JREntViewer_Install_Dir>/lib/JREntViewer.zip;<JREntViewer_Install_Dir>/lib/log4j-1.2.8.jar
Client API mainly includes two packages: API package and GUI package. The API package offers methods for compiling the program, getting some information and viewing result versions etc., the GUI package offers the interface to view the report.
This package includes the following classes:
- APIUtil
Provides some static methods, such as getting error messages, returning URL strings, getting response message, getting task information etc.
- Active
Contains displaying information of an active task from the report server.
- Completed
Contains displaying information of a completed task from the report server.
- JRClient
Represents a client of JReport Enterprise Server. It provides methods to run reports, view result versions and create/edit schedules etc.
- NodeInfo
Contains information of a resource node in a report server for scanning catalogs or directories in the report server.
- ResourcePathInfo
Contains the path information of a resource node in a report server. The path information includes the servlet path, the path info, the catalog and the report of a resource in the report server. For example: for the URL http://server:8888/servlet/jrservlet/hsqlDemo/Tutorial.cat/invoice.cls
where
The servlet path is "/servlet/jrservlet".
The path info is "/hsqlDemo/Tutorial.cat/invoice.cls".
The catalog is "/hsqlDemo/Tutorial.cat".
The report is "invoice.cls".
- VersionRecord
Represents a result version record of a report from a report server.
This package includes the following interfaces and classes.
Reference Notes: For more details about methods, refer to JREntViewer javadoc jet.client package which includes all the documents generated by Javadoc. You can go to http://www.jinfonet.com/docs.htm for the manual related materials.
After you have installed JReport Enterprise Viewer, you will find the illustrative demo programs under <installroot>\help\viewer-material. Or you can find them at http://www.jinfonet.com/docs.htm with the manual related materials.
ReportBrowser.java - browse catalogs and their reports and view report results.
ResultVersionView.java - view a result version
ScheduleDialogs.java - create/edit scheduled tasks
ScheduleDemo.java - create/edit schedule tasks without GUI
TasksInfo.java - list scheduled tasks, active tasks and completed tasks
RunTaskDemoToEMail.java - run a task immediately. And demonstrates how to run a "Publish To EMail" task.
ViewerThreadDemo.java - about viewer thread
ExportResult.java - export report resultsBelow are two examples, with which we will explain how they work and how they use the methods provided with Client API.
ResultVersionView.java is designed to view a result version and export to different formats.
- Import
First of all, you should import the classes of Client API by adding the following import statements at the beginning of your program.
import jet.client.api.*;
import jet.client.api.gui.*;
- Set Connection Information
After getting the values of command line arguments such as report URL, user, password etc., set the connection information with the following methods in class jet.client.api.JRClient.
1. Set the proxy infomation for the client
JRClient.setProxy(proxyHost, proxyPort);
The methods setProxy (String proxyHost, String proxyPort) set the proxy for the client.
Parameters:
proxyHost - The proxy host name or IP address. If it is null, no proxy will be used.
proxyPort - The proxy port.
2. Set the user ID
JRClient.setUser(user);
The method setUser(string user) sets the user ID of the report server at the client end.
3. Set the client password
JRClient.setPassword(password);
The method setPassword(string password) sets the user password.
- Login
JRClient.login(null, report);
The method(Frame frame, string jrsvrURL) is used to login to the report server jrsvrURL. A login dialog box will pop up to enter user ID and password.
Parameters:
frame - The frame of the login dialog box. If the frame is null, JRClient would create a frame and the login dialog box would still pop up when a login is needed (a server returns the Unauthorized response or a proxy returns the Proxy Authentication Required response).
jrsvrURL - The URL string of the JRServlet. For examples: http://jrserver:8888/ or http://server:8888/servlet/jrservlet/ .
- Get Result Versions of the Report
Vector versions = JRClient.getResultVersions(null, report);
The method getResultVersions(Frame frame, String reportURL) returns the result versions of a report in a report server.
Parameters:
frame - The frame of the login dialog box. If the frame is null, JRClient would create a frame and the login dialog box would still pop up when a login is needed (a server returns the Unauthorized response or a proxy returns the Proxy Authentication Required response).
rptURL -The URL string of the report in a report server. For example: http://server:8888/servlet/jrservlet/hsqlDemo/Tutorial.cat/invoice.cls
- Export the Result to JReport Result, HTML, PDF, TEXT, Excel, Postscript and RTF
boolean[] succInfo = JRClient.exportVersionResult(report,
ver.getResultFilename(), // the result version
localFilename + ".rst", // To report result.
localFilename + ".html", // To HTML.
localFilename + ".pdf", // To PDF.
localFilename + ".txt", // To TEXT.
localFilename + ".xls", // To Excel.
localFilename + ".ps", // To Postscropt.
localFilename + ".rtf", // To RTF(Rich Text Format).
false, // isNormalText
false, // isRepeat
';', // delimiter
true, // isMultiFiles
true, // isChartApplet
true, // hasHyperlink
false, // hasPageNumber
false, // useTable
false, // relFontSize
0, // webBrowser 0 - IE, 1 - Netscape.
false); // drilldown
The method exportVersionResult is used to export a version result to different formats. It returns whether it is successful or not.
boolean[0]: if successfully exported to JReport result
boolean[1]: if successfully exported to HTML
boolean[2]: if successfully exported to PDF
boolean[3]: if successfully exported to TEXT
boolean[4]: if successfully exported to Excel
boolean[5]: if successfully exported to PS
There are a couple of exportVersionResult methods with different parameters. The method being used in the demo has following parameters:
rptURL - The URL string of the report in a report server.
versionResult - The version result filename of the report on the server side.
rstFile - The local filename with the full path, to which tempResult will be exported as a JReport result file.
htmlFile - the local filename with the full path, to which tempResult will be exported as an HTML file.
pdfFile - the local filename with the full path, to which tempResult will be exported as a PDF file.
txtFile - the local filename with the full path, to which tempResult will be exported as a TEXT file.
excelFile - the local filename with the full path, to which tempResult will be exported as an Excel file.
psFile - the local filename with the full path, to which tempResult will be exported as a PS file.
rtfFile - the local filename with the full path, to which tempResult will be exported as an RTF file.
isNormalText - Indicate whether this text file is in normal text format or not (To TEXT).
isRepeat - Indicate whether the same contents are repeated (To TEXT).
delimiter - A character which will be used in SDF (Standard Data Format) format. A delimiter could be a ',' (the CSV format) or any other characters. The default is ' ' (a blank), that is, the SSV format (To TEXT).
isMultiFiles - Indicate whether html is generated to a file or to multiple files (To HTML).
isChartApplet - Indicate whether the chart in html file is an applet (To HTML).
hasHyperlink - Indicate whether the hyperlink is generated (To HTML).
hasPageNumber - Indicate whether to generate page number (To HTML).
useTable - Indicate whether to use an HTML table to generate the HTML page (To HTML).
relFontSize - Indicate whether to generate HTML pages with relative font size (To HTML).
webBrowser - Indicate which Web browser HTML pages are being generated for (To HTML). 0 - IE; 1 - Netscape.
drilldown - Indicate whether to drilldown the HTML result (To HTML).
Note: The method exportVersionResult() is deprecated. Above JREntViewer version 3.0, it is replaced by exportVersionResult(String rptURL, String versionResult, String rstFile, String htmlFile, String pdfFile, String txtFile, String excelFile, String psFile, boolean isNormalText, boolean isRepeat, char delimiter, boolean isMultiFiles, boolean isChartApplet, boolean hasHyperlink, boolean hasPageNumber, boolean useTable, boolean relFontSize, int webBrowser).
- View theVersion in a Thread
ViewerThread vt = JRClientGUI.viewResultVersion(report,ver.getResultFilename(), "Result Version - " + ver.getCreatedTimeDisplayString());
The method viewResultVersion(String rptUrl, String resultVersion, String title) views a report result version and returns a ViewerThread object. A report viewer frame is brought up by the ViewerThread.
Parameters:
rptURL - The URL string of the report in a report server. For example: http://jrserver:8888/hsqlDemo/Tutorial.cat/invoice.cls
resultVersion - The result version name can be got from getResultFilename() of VersionRecord. The VersionRecord list of a report can be got from the method getVersionList(...) of this class.
title - The title of the report viewer that will be brought up.
- Show the Parameters of this Result Version
JRClientGUI.showVersionParamValues(null, report, ver.getVersionID(),"Parameters - " + ver.getCreatedTimeDisplayString());
The method showVersionParamValues(Frame frame, String jrsvrURL, String versionID, String title) brings up a dialog box to show the report parameter values of the result version.
Parameters:
frame - The frame of the login dialog box. If the frame is null, JRClient would create a frame and the login dialog box would still pop up when a login is needed (a server returns the Unauthorized response or a proxy returns the Proxy Authentication Required response).
jrsvrURL - The URL string of the JRServlet.
versionID - The result version ID can be got from getVersionID() of VersionRecord. The VersionRecord list of a report can be got from the method getVersionList(...) of this class.
title - The title of the dialog box.
- Exit
vt.setSystemExitWhenWindowClosed();
The method setSystemExitWhenWindowClosed() sets the system to exit when the result viewer is closed.
- Compile and Run
Assume that the demo program is under C:\JREntViewer\help\api, and JReport Enterprise Viewer is installed in c:\JREntViewer.
To compile and run the demo program, you should add the some files with their paths into the classpath. For example, use the following command to compile the test program:
C:\JREntViewer\help\api>javac -classpath c:\JREntViewer\lib\JREntViewer.zip;c:\JREntViewer\lib\log4j-1.2.8.jar ResultVersionView.java
When you run the programs, you should provide parameters.
-help: Display the usage of the program (optional).
-report: The report URL to view its result from command line.
-params: Parameters of the report to view its result from command line.
-user: The user ID (optional).
-password: The user password (optional).
-proxyhost: The proxy host (optional).
-proxyport: The proxy port (optional).
An example to run the program:
C:\JREntViewer\help\api>java -classpath c:\JREntViewer\lib\JREntViewer.zip;c:\JREntViewer\lib\log4j-1.2.8.jar;C:\JREntViewer\help\api ResultVersionView -reporthttp://jrserver:8888/hsqlDemo/Tutorial.cat/invoice.cls -paramsPToday5/21/98 -useradmin -passwordadmin
Running the program, you can view the result of report "invoice" and its parameter as shown below.
This example is designed to submit a schedule without GUI to generate a report version every hour from 9:00 to 17:00 daily. Also, the version manager will keep each of the generated results for 30 days from the day they are generated.
- Import
Import the classes of Client API by adding the following import statements at the beginning of your program.
import jet.client.api.*;
- Set Connection Information
After getting the values of command line arguments such as report URL, user, password etc., set the connection information with the same methods used in example one.
// set the HTTP proxy for the client.
if (proxyHost != null) {
JRClient.setProxy(proxyHost, proxyPort);
}
// set the user ID for the client.
JRClient.setUser(user);
// set the password for the client.
JRClient.setPassword(password);
- Login
Use the same method used in example one to login into the server.
JRClient.login(null, server);
- Set Properties of Task and Time
Hashtable htTask = new Hashtable();
//set properties about task info
htTask.put("jrs.task_class", "jet.server.schedule.jrtasks.UpdateRptTask");
htTask.put("jrs.catalog", "/hsqlDemo/Tutorial.cat");
htTask.put("jrs.report", "invoice.cls");
htTask.put("jrs.expire_days", "30");
htTask.put("jrs.if_print", "false");
//set parameter values
htTask.put("jrs.param$PToday", "May 20, 1998");
htTask.put("jrs.param$TermsDays", "31");
//set properties about time info
htTask.put("jrs.launch_type", "8");
htTask.put("jrs.days_id", "0");
htTask.put("jrs.day", "1");
htTask.put("jrs.is_weekday", "false");
htTask.put("jrs.is_hourly", "true");
htTask.put("jrs.hours", "1");
htTask.put("jrs.is_between", "true");
htTask.put("jrs.is_pm", "false");
htTask.put("jrs.hour", "9");
htTask.put("jrs.min", "0");
htTask.put("jrs.at_min", "0");
htTask.put("jrs.is_pm2", "true");
htTask.put("jrs.hour2", "5");
htTask.put("jrs.min2", "0");
- Get Scheduled Tasks from the Server
Vector tasks = JRClient.getScheduled(null, server);
The method getScheduled(Frame frame, String jrsvrURL) returns the scheduled tasks from the report server.
Parameters:
frame - The frame of the login dialog box. If the frame is null, JRClient would create a frame and the login dialog box would still pop up when a login is needed (a server returns the Unauthorized response or a proxy returns the Proxy Authentication Required response).
jrsvrURL - the URL string of the JRServlet.
- Compile and Run
Compile the demo program as you do in example one. For example, use the following command to compile:
C:\JREntViewer\help\api>javac -classpath c:\JREntViewer\lib\JREntViewer.zip;c:\JREntViewer\lib\log4j-1.2.8.jar ScheduleDemo.java
When you run the programs, you should provide the parameter "-server" which indicates the server URL. For example, use the following command to run the demo program.
C:\JREntViewer\help\api>java -classpath c:\JREntViewer\lib\JREntViewer.zip;c:\JREntViewer\lib\log4j-1.2.8.jar;C:\JREntViewer\help\api ScheduleDemo -serverhttp://jrserver:8888
There are also the following optional parameters:
-help: Display the usage of the program
-user: The user ID
-password: The user password
-proxyhost: The proxy host
-proxyport: The proxy port
Running the program, you will submit a schedule task and get the information about this task.