...
For the Java side of the reporting, I now assume that there is a a report definition file somewhere. To parse a report, you first need the URL to the report-definition (or a file-object, whatever you prefer), and then you feed that into the parser.
{{
Code Block |
---|
}} // from http://wiki.pentaho.org/display/Reporting/Pentaho+Reporting+XML+Definition+formats private JFreeReport parseReport(URL in) throws ReportDefinitionException { if (in == null) { throw new ReportDefinitionException("ReportDefinition Source is invalid"); } try { ResourceManager manager = new ResourceManager(); manager.registerDefaults(); Resource res = manager.createDirectly(in, JFreeReport.class); return (JFreeReport) res.getResource(); } catch(Exception e) { throw new ReportDefinitionException("Parsing failed", e); } } {{ |
}}
If your report-definition contained a data-source definition as well, this JFreeReport object can now be used for reporting.
To show the swing-preview-dialog: {{
Code Block |
---|
}} JFreeReport report; // created elsewhere .. final PreviewDialog frame = new PreviewDialog(report); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.setVisible(true); {{ |
...
or (you mentioned PDF) you can use this object to generate the desired content directly, for instance:{{
Code Block |
---|
}} PdfReportUtl.createPdf(report, "/tmp/report.pdf"); {{ |
}}
*ReportUtil classes are available for all export types; if they do not provide enough flexibility, you can instantiate and configure the report processors manually as well. To send the data directly to the HttpResponse, simply use the createPdf(..) method that accepts an output-stream. Cleaning temporary files is just ugly, so we better dont create them in the first place.
...
Extended-XML with embedded data-source {{
Code Block |
---|
}} <?xml version="1.0" encoding="ISO-8859-1"?> <report-definition xmlns="http://jfreereport.sourceforge.net/namespaces/reports/legacy/ext" name="Quadrant For Region" query="default"> .. <report-config> .. <data:sql-datasource xmlns:data="http://jfreereport.sourceforge.net/namespaces/datasources/sql"> <data:config label-mapping="true"/> <data:connection> <data:driver>org.hsqldb.jdbcDriver</data:driver> <data:url>jdbc:hsqldb:./sql/sampledata</data:url> <data:properties> <data:property name="user">sa</data:property> <data:property name="pass"></data:property> </data:properties> </data:connection> <data:query name="actuals-by-region"> SELECT QUADRANT_ACTUALS.REGION, QUADRANT_ACTUALS.DEPARTMENT, QUADRANT_ACTUALS.POSITIONTITLE, QUADRANT_ACTUALS.ACTUAL, QUADRANT_ACTUALS.BUDGET, QUADRANT_ACTUALS.VARIANCE FROM QUADRANT_ACTUALS WHERE REGION = ${REGION} ORDER BY REGION, DEPARTMENT, POSITIONTITLE </data:query> <data:query name="default"> SELECT DISTINCT QUADRANT_ACTUALS.REGION FROM QUADRANT_ACTUALS ORDER BY REGION </data:query> </data:sql-datasource> .. </report-config> {{ |
...
..
</report-definition>
|
Extended-XML with external data-source:
{{
Code Block |
---|
}} <?xml version="1.0" encoding="ISO-8859-1"?> <report-definition xmlns="http://jfreereport.sourceforge.net/namespaces/reports/legacy/ext" name="Quadrant For Region" query="default"> .. <report-config> <data-factory href="sql-subreport.sqlds"/> .. </report-config> .. </report-definition> {{ |
...
How to approach your reporting case
...