Example 1: Working with ResultVersionView.java

ResultVersionView.java can be found in <server_install_root>\help\samples\APIClient\ViewReport. The Client API classes are included in <server_install_root>\lib\JRViewer.jar. To work with ResultVersionView.java to view a result version and export it to different formats, follow the steps below:

  1. Import the classes of the Client API by adding the following import statements at the beginning of your program.

    import jet.client.api.*;
    import jet.client.api.gui.*;

  2. Set the connection information with the methods in class jet.client.api.JRClient after obtaining the values of the command line arguments such as report URL, user, and password.
    1. Set the proxy information for the client using JRClient.setProxy(proxyHost, proxyPort);

      The method setProxy (String proxyHost, String proxyPort) sets 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 using 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 using JRClient.setPassword(password);

      The method setPassword(string password) sets the user password.

  3. Log onto the report server using JRClient.login(null, report);

    The method (Frame frame, string jrsvrURL) is used to log onto the report server jrsvrURL. A login dialog will be displayed for you to enter user ID and password.

    Parameters:

  4. Get result versions of the report using 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:

  5. 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 JReport result.
      localFilename + ".html", // To HTML.
      localFilename + ".pdf",  // To PDF.
      localFilename + ".xls",  // To Excel.
      localFilename + ".txt",  // To TEXT.
      localFilename + ".rtf",  // To RTF(Rich Text Format).
      localFilename + ".ps",   // To PostScript.
      false,  // isNormalText
      false,  // isRepeat
      ';',    // delimiter
      true,   // isMultiFiles
      true,   // isChartApplet
      true,   // hasHyperlink
      false,  // hasPageNumber
      false,  // useTable
      false,  // relFontSize
      0,      // webBrowser 0 - IE.
      false); // drilldown
    

    The method exportVersionResult() is used to export a version result to different formats. It returns whether or not it is successful.

    There are a couple of exportVersionResult methods with different parameters. The method being used in the demo contains the following parameters:

    Note: The method exportVersionResult() is deprecated. It has been 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).

  6. View the version in a thread using 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:

  7. Show the parameters of this result version using JRClientGUI.showVersionParamValues(null, report, ver.getVersionID(),"Parameters - " + ver.getCreatedTimeDisplayString());

    The method showVersionParamValues (Frame frame, String jrsvrURL, String versionID, String title) brings up a dialog to show the report parameter values of the result version.

    Parameters:

  8. Exit using vt.setSystemExitWhenWindowClosed();

    The method setSystemExitWhenWindowClosed() sets the system to exit when the result viewer is closed.

  9. Compile and run the demo program.

    Assume that the demo program is in C:\JReport\Server\help\samples\APIClient\ViewReport, and JReport Server has been installed to C:\JReport\Server.

    To compile and run the demo program, you should add certain files with their paths into the class path. For example, use the following command to compile the test program:

    C:\JReport\Server\help\samples\APIClient\ViewReport> javac 
    -classpath C:\JReport\Server\lib\JRViewer.jar;
    C:\JReport\Server\lib\log4j-1.2.8.jar 
    ResultVersionView.java
    

    When you run the programs, you should provide the following parameters.

    An example for running the program:

    C:\JReport\Server\help\samples\APIClient\ViewReport> java -classpath "C:\JReport\Server\lib\JRViewer.jar;
    C:\JReport\Server\lib\log4j-1.2.8.jar;" ResultVersionView java ResultVersionView -server=http://localhost:8888/jrserver -report=/SampleReports/CustomerAnalysis.cls "-params=p_StartDate=01/01/2006; p_EndDate=12/31/2007" -user=admin -password=admin

    By running the program, you can view the result of the report CustomerAnalysis.cls.