SourceForge.net Logo

Connla is a Java library for creating data collections which can be exported to TXT, CSV, HTML, XHTML, XML, PDF and XLS formats.

Project

Everything about this project, including downloads, can be found on the Source Forge Connla project pages.

It is a fast and easy to use alternative to JasperReports.

Structure

Connla allows a programmer to construct a table-like two dimensional data structure of class Connla, with arrays or Vectors, which contain the data that needs to be presented. Here each data element is referred to as an instantiation of class Connlon. Such an object can hold a String and additional layout settings like font style as bold or text colour. After the data has been organised in an object of class Connla, by filling it with objects of class Connlon, one can export to several different output formats like TXT, CSV, HTML, PDF, XLS, etc.

Connla provides a simple and generic way of exporting to different output formats without the programmer has to be aware or use all the different specific APIs for these formats. It will save time and will make the code more generic and extendable when other output formats are required.

Example

Below is an example of the use of Connla.

Fill Connla with Connlon elements

First an instance of Connla is created and filled with elements of class Connlon. Note that headers and normal elements are created in a very similar way.
	Connlon[][] aConnlons = null;
	Connlon aConnlon = null;
	Connlon[] aHeaders = null;

	int n = 3;
	int m = 3;
	aHeaders = new Connlon[m];
	aConnlon = new Connlon("ID");
	aConnlon.setHeader();
	aHeaders[0] = aConnlon;
	aConnlon = new Connlon("Name");
	aConnlon.setHeader();
	aHeaders[1] = aConnlon;
	aConnlon = new Connlon("Value");
	aConnlon.setHeader();
	aConnlon.setAlignRight();
	aHeaders[2] = aConnlon;

	aConnlons = new Connlon[n][m];

	aConnlon = new Connlon("test00");
	aConnlon.setAlignRight();
	aConnlon.setForegroundColor("yellow");
	aConnlon.setBackgroundColor("red");
	aConnlon.setBold();
	aConnlon.setItalic();
	aConnlon.setStrikethru();
	aConnlon.setUnderline();
	aConnlons[0][0] = aConnlon;

	aConnlon = new Connlon("test10");
	aConnlon.setAlignRight();
	aConnlon.setForegroundColor("ffff00");
	aConnlon.setBackgroundColor("0000ff");
	aConnlon.setBold();
	aConnlon.setItalic();
	aConnlons[1][0] = aConnlon;

	aConnlon = new Connlon("test20");
	aConnlon.setAlignRight();
	aConnlon.setForegroundColor("000000");
	aConnlon.setBackgroundColor("00ff00");
	aConnlon.setBold();
	aConnlon.setItalic();
	aConnlon.setUnderline();
	aConnlons[2][0] = aConnlon;

	aConnlon = new Connlon("test02");
	aConnlon.setAlignCenter();
	aConnlons[0][2] = aConnlon;

	aConnlon = new Connlon("test12");
	aConnlon.setAlignCenter();
	aConnlons[1][2] = aConnlon;

	aConnlon = new Connlon("test22");
	aConnlon.setAlignCenter();
	aConnlons[2][2] = aConnlon;

	aConnlons[0][1] = new Connlon("42");
	aConnlons[1][1] = new Connlon("Test");
	aConnlon = new Connlon("Connla project page");
	aConnlon.setURL("http://www.sourceforge.net/projects/connla");
	aConnlon.showURLinPDF();
	aConnlons[2][1] = aConnlon;

	int[] aWidthsA = {10, 80, 10};

	aConnla = new Connla("Test", aWidthsA, aHeaders, aConnlons);
In order to distribute the columns in a sane way, an arrays with relative widths is being passed to the Connla constructor. Note that an instance of Connla can also be created from Vectors of Connlon as opposed to arrays of Connlon.

Exporting Connla to various formats

Below can be seen that once Connla has been filled with proper data it is very easy to export to the different output formats.
	aConnla.toCSV("test/out/test.csv");
	aConnla.toTXT("test/out/test.txt");
	aConnla.toHTML("test/out/test.html");
	aConnla.toPDF("test/out/test.pdf");
	aConnla.toXLS("test/out/test.xls");
Below is a screenshot of the different output formats.

Servlet example

On the file download page an war file can be downloaded with an example of how Connla can be used in a Java Application server like Tomcat to generate PDF in a new window from a HTML page. In this way one can implement a printer friendly button on a web page.