quick how to
 version 0.5.2
 
 

 
 

INDEX

 
  1. Main classes
2. Compiling a report design
3. Ant task for compiling report designs
4. Viewing a report design
5. Filling a report
6. Viewing a report
7. Printing a report
8. Exporting to PDF, HTML, XLS, CSV or XML format

         
 1. Main classestop 
 
 Main classes to use when working with JasperReports
 
 dori.jasper.engine.JasperCompileManager
 dori.jasper.engine.JasperFillManager
 dori.jasper.engine.JasperPrintManager
 dori.jasper.engine.JasperExportManager
 This classes represent a fa栤e to the JasperReports engine. They have various static methods that simplify the access to the API functionality and can be used to compile an XML report design, to fill a report, to print it, or to export to PDF, HTML and XML files.
 
 dori.jasper.view.JasperViewer
 This can be used to view the generated reports.
 
 dori.jasper.view.JasperDesignViewer
 This can be used to view the report design.
 
 2. Compiling a report designtop 
 A report design is represented by an XML file that has the structure defined in the jasperreport.dtd file.
 In order to generate reports according to such a report design, it needs to be compiled.
 Report design compilation can be done using the compileReportXXX() methods exposed by dori.jasper.engine.JasperCompileManager class.
 
 When compiling a report design, the engine first performs a validation to ensure that the template is consistent and then transforms all the report expressions, so that they are stored in a ready-to-evaluate form, inside the resulting .jasper file.
 This transformation implies either the on-the-fly compilation of a Java class file that will be associated with the report template, or the generation of a BeanShell script to use when evaluating report expressions during the report filling process.
 
 To make report design compilation process as flexible as possible, a special interface called dori.jasper.engine.design.JRCompiler was introduced.
 As seen above, there are two main types of classes implementing this interface and thus performing report compilation:
 
 1. Java class generating report compilers. These report compilers generate and compile a Java class containing the report expressions evaluating methods;
 
 2. The BeanShell report compiler that generates a script for runtime report expressions evaluation, without requiring bytecode Java compilation.
 
 System properties to customize report compilation:
 
 jasper.reports.compiler.class
 By default, when compiling report designs, the library tries to identify the Java generating class type of a report compiler that is compatible with the Java compiler available on the running platform in this order: JDK 1.3 compatible compiler, JDK 1.2 compatible compiler and the command-line javac.exe compiler.
 To override this default behavior, you can specify the name of a class that implements the dori.jasper.engine.design.JRCompiler interface to be used to compile the report design by supplying it to the jasper.reports.compiler.class system property.
 The library comes with 5 built-in implementations of this interface:
 
 dori.jasper.engine.design.JRBshCompiler
 dori.jasper.engine.design.JRJavacCompiler
 dori.jasper.engine.design.JRJdk12Compiler
 dori.jasper.engine.design.JRJdk13Compiler
 dori.jasper.engine.design.JRJikesCompiler
 
 Note that the classes implementing the JRCompiler interface can also be used directly in the programs without the need to call them through the fa栤e JasperCompilerManager class.
 
 jasper.reports.compilation.xml.validation
 The XML validation, which is ON by default, can be turned off by setting the system property called jasper.reports.compilation.xml.validation to false.
 
 
 When working with a Java class generating type of a report compiler, further customizations can be made using the following system properties, which only apply to them:
 
 jasper.reports.compile.class.path
 By default, JasperReports uses the current JVM classpath to compile the report class (java.class.path system property). To customize this report compilation process, JasperReports lets you override the default behavior by supplying a value to the jasper.reports.compile.class.path system property, which will be used as classpath for the report class compilation.
 
 jasper.reports.compile.temp
 The temporary location for the files generated on-the-fly is by default the current working directory. It can be changed by supplying a value to the jasper.reports.compile.temp system property.
 
 jasper.reports.compile.keep.java.file
 Sometimes, for debugging purposes, it is useful to have the generated .java file in order to fix the compilation problems related to report expressions. By default, the engine deletes this file after report compilation, along with its corresponding .class file. To keep it however, you can set the system property jasper.reports.compile.keep.java.file to true.
 
 3. Ant task for compiling report designstop 
 Since the report design compilation process is more like a design-time job than a runtime one, an Ant task was provided with the library in order to simplify development.
 
 This Ant task is implemented by the dori.jasper.ant.JRAntCompileTask and is very similar to the <javac> Ant built-in task, as far as syntax and behavior are concerned.
 
 The report design compilation task can be declared like this, in a project's build.xml file:
 
 
<taskdef name="jrc" classname="dori.jasper.ant.JRAntCompileTask"> 
  <classpath>
    <fileset dir="./lib">
      <include name="**/*.jar"/>
    </fileset>
  </classpath>
</taskdef>
  
 In the example above, the lib should contain the jasperreports.jar file along with its required libraries.
 
 This user-defined Ant task can be then used to compile multiple XML report design files in a single operation, by specifying the root directory that contains those files or by selecting them using file patterns.
 
 Attributes of the report design compilation task:
 
 srcdir
 Location of the XML report design files to compile. Required unless nested <src> elements are present.
 
 destdir
 Location to store the compiled report design files (the same as the source directory by default).
 
 compiler
 Name of the class that implements the dori.jasper.engine.design.JRCompiler interface (optional).
 
 xmlvalidation
 Flag to indicate if the XML validation should be performed on the source report design files (true by default).
 
 tempdir
 Location to store the temporary generated files (the current working directory by default).
 
 keepjava
 Flag to indicate if the temporary Java files generated on-the-fly should be kept and not deleted automatically (false by default).
 
 The report design compilation task supports nested <src> and <classpath> elements, just like the Ant <javac> built-in task.
 
 To see this in action, check the "antcompile" sample provided with the project source files.
 
 4. Viewing a report designtop 
 Reports designs can be viewed using the dori.jasper.view.JasperDesignViewer application.
 In its main() method, it receives the name of the file which contains the report design to view.
 This can be the XML file itself, or the compiled report design.
 
 5. Filling a reporttop 
 A compiled report design can be used to generate reports by calling the fillReportXXX() methods of the dori.jasper.engine.JasperFillManager class.
 
 6. Viewing a reporttop 
 Generated reports can be viewed using the dori.jasper.view.JasperViewer application.
 In its main() method, it receives the name of the file which contains the report to view.
 
 7. Printing a reporttop 
 Generated reports can be printed using the printReport(), printPage() or printPages() static methods exposed by the doriJasper.engine.JasperPrintManager class.
 
 8. Exporting to PDF, HTML, XLS, CSV or XML formattop 
 After having filled a report, we can also export it in PDF, HTML or XML format using the exportReportXXX() methods of the dori.jasper.engine.JasperExportManager class.
 



Copyright © 2001-2004 Teodor Danciu teodord@users.sourceforge.net