Thursday, 4 December 2008

The Definitive Guide to JasperReports - Final Part

Couple of Weeks back i started reading The Definitive Guide to JasperReports By Teodor Danciu , Lucian Chirita.

Nice book written by Teodor Danciu , Lucian Chirita.

I wanted to share few qoutations i found from this book found from the remaining chapters.

1) A crosstab is a special type of report element that summarizes data into a two-dimensional grid. Crosstabs usually display the joint distribution of two or more variables in the form of a table in which both rows and columns are dynamic, and in which the table cells use these variables to display aggregate data such as sums, counts, minimums, and maximums.

2) Data Grouping (Bucketing)

The original dataset data through which the crosstab calculation engine iterates to make the required data aggregation must be grouped in accordance with the declared rows and columns of the crosstab. Row and column groups in a crosstab rely on group items called buckets. A bucket definition consists of the following:

• An expression evaluated at runtime that obtains the group items (buckets) in which to place the aggregated information

• A comparator to sort the group items (buckets) in case the natural ordering of the values is not acceptable or even possible

3) Crosstab Governor

The crosstab calculation engine performs all calculations in memory. In case large volumes of data are processed, it could be possible to run out of memory due to the large number of totals and aggregation variables that the engine keeps track of.

To avoid the situation in which the JVM raises an OutOfMemory error, and thus triggers memory reclaim procedures with potentially serious effects on the application’s overall behavior, a crosstab governor has been put in place. This is basically a simple memory consumption test that the engine performs when filling a crosstab, to check whether a given memory threshold has been reached. When the limit is reached, the program raises an exception that can be caught and dealt within the caller program, preventing a more serious OutOfMemory error from occurring.

The governor threshold is given as an integer number representing the maximum number of cells multiplied by the number of measures in the generated crosstab. It can be set using the net.sf.jasperreports.crosstab.bucket.measure.limit configuration property. This property defaults to -1, meaning that the crosstab governor is disabled by default.

4) Crosstab Cells

A crosstab cell is a rectangular area at the intersection of a crosstab row and a crosstab column.The cell is a free-form element that can contain any kind of report element except subreports, charts, and crosstabs.

Crosstab cells are of two types:

• Detail crosstab cell: Both the row and the column correspond to bucket values, not totals.

• Total crosstab cell: Either the row or the column or both correspond to a group total

5) The proprietary document format used by JasperReports to generate and store final documents is represented by a net.sf.jasperreports.engine.JasperPrint object, which can be serialized for transfer over the network or permanent storage. However, when these documents must be sent to third-party consumers who do not have the proper tools to view and print them in the JasperReports proprietary format, the best solution is to export those documents to more popular formats like PDF, HTML, RTF, XLS, ODT, or CVS, for which there are specialized viewers available on almost all platforms.

6) PDF Exporter

Exporting to PDF was among the initial requirements for the JasperReports library. As its name indicates, PDF is a very precise and complex document format that ensures documents will look and print the same on all platforms.

This is why the PDF exporter implemented by the net.sf.jasperreports.engine.export. JRPdfExporter class in JasperReports is one of the best exporters. The output it produces is almost of the same quality as that produced by the net.sf.jasperreports.engine.export. JRGraphics2DExporter, which is always the reference.

The JRPdfExporter implementation uses iText, which is a specialized PDF-generating library. PDF is a binary document format that allows absolute positioning of the elements inside a page, so the existing PDF exporter does not have the limitations of a grid exporter. It also works very well in batch mode because it allows concatenation of multiple documents within the same PDF file, even if the files have different page sizes.

7) HTML Exporter

Among the first export formats supported by JasperReports was HTML. This is because HTML is a very popular document format and browsers are available on all platforms. Also, many Java applications requiring reporting functionality are web-based applications.

The net.sf.jasperreports.engine.export.JRHtmlExporter tries to produce high-quality HTML output by using the most common tags to ensure that the documents are compatible with the great majority of browsers, and that they look almost the same on all platforms. It is a grid-based exporter because it structures the layout of each document page using a table element, so all the limitations mentioned about grid exporters are applicable to this exporter,too.

Since JasperReports version 1.2.0, the built-in HTML exporter produces output that is compatible with the XHTML standard.

8) HTML Header

Since HTML content is usually sent directly to the browser as an individual document or stored on disk, the HTML exporter wraps the result inside document-level tags like html and body.

The default HTML header used by the JRHtmlExporter class is as follows:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
a {text-decoration: none}
</style>
</head>
<body text="#000000" link="#000000" alink="#000000" vlink="#000000">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td width="50%">&nbsp;</td><td align="center">
By default, the HTML result ends with this chunk:
</td><td width="50%">&nbsp;</td></tr>
</table>
</body>
</html>


You can customize both the header and the footer chunks used for wrapping the document pages by setting the desired HTML chunks as values for the HTML_HEADER and HTML_FOOTER exporter parameters. These two parameters enable you to make references to other resources, such as style sheet files, or even to suppress the header and footer completely if the resulting HTML content is used only for embedding into another web page that is part of a portal-like application.

About the Author

Teodor Danciu is the founder and architect of the JasperReports library, the most popular open source reporting tool, and is now working for JasperSoft. Before joining JasperSoft, Teodor worked for almost 8 years with several French IT companies as a software engineer and team leader on ERP and other medium-to-large database-related enterprise applications using mainly Java technologies and the J2EE platform. Teodor holds a B.S. in computer science from the Academy of Economic Studies in Bucharest.

Lucian Chirita joined Teodor Danciu at JasperSoft in the development of JasperReports library back in 2005, and he quickly became one of the main contributors to the project. Prior to joining JasperSoft, Lucian had 3 years of software engineering experience on several Java/J2EE products and applications. His contributions to JasperReports include support for crosstabs and integration with data query technologies such as Hibernate and OLAP. Lucian holds an M.S. in computer science from the University of Bucharest.

1 comment:

Anonymous said...

Awesome post.

my web blog diets That work