...
Loading the report definition from an XML file hasnt hasn't changed much.
Instead of using the ReportFactory
, we now use a centralized ResourceManager
. That resource manager handles all load-operations. It keeps track of changes to the underlying files and tries to apply as much caching as possible. The resource-manager is contained in LibLoader.
...
The resource manager provides resource-objects, which grant access to some additional meta-data. The first parameter of the 'create' operation is the source object. This can be anything, like an URL, a File (or a string representation of those) or a byte containing the raw-data. Resources stored on the classpath can be accessed using the String "res:/package/file.name".
You may want to have a look at the sources of the libloader, especially the subpackages file, raw, resource and zip of the package org.jfree.resourceloader.loader and the code of the method org.jfree.resourceloader.ResourceManager.registerDefaultLoaders() in order to understand the resource handling better.
There are ResourceLoaders for reading from Files, from the Classloader, from given byte[] arrays and from zip archives (i.e. jar files). You can register your own implementations of ResourceLoader and AbstractResourceData in order to add other sources.
Code Block |
---|
Resource res = manager.createDirectly(source, JFreeReport.class); |
...
The name the Table-Model is registered with the report-data-factory must be the same as the query-name used in the report-object.
How can I format the output of number fields?
formating is now handled by the style system. So if you pass in a number or date object, it can be formated using a style rule. OK, no one wants to declare own rules, so there are some sane defaults:
This is the snipped of the default stylesheet that is responsible for formating values:
Code Block |
---|
@namespace url(http://jfreereport.sourceforge.net/namespaces/reports/flow); @namespace xml url(http://www.w3.org/XML/1998/namespace); @namespace report url(http://jfreereport.sourceforge.net/namespaces/engine); content[report|content] { content: attr("report|content"); display: inline; } content[report|content][report|isDate=true] { content: format(attr("report|content", date), date); } content[report|content][report|isDate=true][report|format] { content: format(attr("report|content", date), date, attr("report|format",string)); } content[report|content][report|isNumber=true] { content: format(attr("report|content", number), number, "#,##0.00"); } content[report|content][report|isNumber=true][report|format] { content: format(attr("report|content", number), number, attr("report|format",string)); } content[report|content][report|isNumber=true][report|isInteger=true] { content: format(attr("report|content", number), number, "#,##0"); } content[report|content][report|isNumber=true][report|isInteger=true][format] { content: format(attr("report|content", number), number, attr("report|format",string)); } |
In common wording: If you have an "flow:content" element (where flow is a namespace identifier pointing to the namespace uri "http://jfreereport.sourceforge.net/namespaces/reports/flow") that has a 'format' attribute, then the engine will take the value from the 'content' element's content attribute and format the value found there with the formatstring found in the 'format' attribute. The attributes of the namespace 'report' are automaticly filled in by the engine itself, you dont have to care about where they come from, simply assume that they are there whenever you refer to a ContentElement.
Example:
Code Block |
---|
<report:report xmlns:report="http://jfreereport.sourceforge.net/namespaces/reports/flow">
..
<report:content>
<report:value-expression formula="jfreereport:12345678" format="#.##0.00"/>
</report:content>
</report:report>
|