Understanding the Report Source
Because the Crystal Report viewer components are shared across both the Crystal Enterprise Embedded Edition and the Crystal Enterprise Professional/Premium editions, there must be a common interface defined so the viewer can display reports generated using both types of report processing engines. This interface is called the report source. The report source is an object that both the Embedded edition and Professional/Premium editions supply that the viewer in turn communicates with to render the reports to the various forms of HTML.
There are three types of report sources:
- Standalone Report Application Server: This is packaged as the Crystal Enterprise Embedded Edition.
- Clustered Report Application Server: This is packaged as part of Crystal Enterprise Professional/Premium edition. This is the Report Application Server running as a service on the Crystal Enterprise framework.
- Page Server: This is the primary report processing service as part of the Crystal Enterprise framework.
NOTE
Because of the special functionality of the Interactive and Grid viewers, they do not work with a Page Serverbased report source.
The Java code in Listing 32.1 illustrates the first scenario where a report source object is obtained from the standalone Report Application Server.
Listing 32.1. Obtaining a Report Source from a Report File
//First you must create a new ReportClientDocument object ReportClientDocument reportClientDoc = new ReportClientDocument(); //After the ReportClientDocument is created, you then need to //specify the report file that is to be used as the report //source: String path = "C:\Program Files\Crystal Decisions\Report Application Server" + " 10\Reports\Sample.rpt"; reportClientDoc.open(path, openReportOptions._openAsReadOnly); //Finally use the openReportSource method to return the report source object IReportSource reportSource = reportClientDoc.getReportSource();
NOTE
All the code listings provided in this chapter are provided in JSP/Java. Although the .NET/COM and the Java flavors of the RAS SDK share identical functionality, there are obviously language nuances associated with each of them. Code samples for additional language flavors are available for download from the www.usingcrystal.com Web site.
Listing 32.2 illustrates obtaining a report source when using the Report Application Server as part of Crystal Enterprise. Notice that the same ReportClientDocument object is used. The difference is in how the ReportClientDocument object is obtained.
Listing 32.2. Obtaining an EnterpriseSession Object
//Retrieve the IEnterpriseSession object previously stored in the users session. IEnterpriseSession enterpriseSession = (IEnterpriseSession) session.getAttribute("EnterpriseSession"); //Use enterpriseSession object to retrieve the reportAppFactory object IReportAppFactory reportAppFactory = (IReportAppFactory) enterpriseSession.getService("", "RASReportFactory"); //Open the report document by specifying the report ID ReportClientDocument reportClientDoc = reportAppFactory.openDocument(reportID, 0, Locale.ENGLISH); //Finally use the openReportSource method to return the report source object IReportSource reportSource = reportClientDoc.getReportSource();
An alternative way to do this is shown in Listing 32.3.
Listing 32.3. Alternative Method to Obtain an EnterpriseSession Object
//Retrieve the IEnterpriseSession object. IEnterpriseSession enterpriseSession = (IEnterpriseSession) session.getAttribute("EnterpriseSession"); //Use the IEnterpriseSession objects getService method to get //an IReportAppFactory object. IReportSourceFactory reportFactory = (IReportSourceFactory) enterpriseSession.getService("", "RASReportFactory"); //Use IReportAppFactory objects openReportSource method, passing it //the report ID to return the reportSource object IReportSource reportSource = reportFactory.openReportSource(reportID, Locale.ENGLISH);
Listing 32.4 illustrates obtaining a report source object from the Page Server service from Crystal Enterprise Professional/Premium.
Listing 32.4. Utilizing the Page Server to Open a Report
//Retrieve the IEnterpriseSession object previously stored in the users session. IEnterpriseSession enterpriseSession = (IEnterpriseSession) session.getAttribute("EnterpriseSession"); //Use the getService method of the EnterpriseSession object to obtain an //IReportAppFactory object: IReportSourceFactory reportFactory = (IReportSourceFactory) enterpriseSession.getService ("", "PSReportFactory"); //Finally use the openReportSource method to return the report source object IReportSource reportSource = reportFactory.openReportSource(reportID, Locale.ENGLISH) ;
Категории