KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > Reports


1 /*
2   Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import dori.jasper.engine.JRDataSource;
22 import dori.jasper.engine.JRException;
23 import dori.jasper.engine.JasperCompileManager;
24 import dori.jasper.engine.JasperExportManager;
25 import dori.jasper.engine.JasperFillManager;
26 import dori.jasper.engine.JasperPrint;
27 import dori.jasper.engine.JasperReport;
28 import java.io.File JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Map JavaDoc;
34 import org.apache.log4j.Logger;
35 import org.objectweb.jac.aspects.gui.reports.JacDataSource;
36 import org.objectweb.jac.core.rtti.ClassRepository;
37
38 public class Reports {
39     static Logger logger = Logger.getLogger("report");
40
41     /**
42      * Generate a PDF report
43      * @param reportDef resource name of the XML report definition file
44      * @param pdfFile file where to store the resulting PDF document
45      */

46     public static void genReport(String JavaDoc reportDef, File JavaDoc pdfFile)
47         throws JRException
48     {
49         genReport(reportDef,pdfFile,new HashMap JavaDoc());
50     }
51
52     /**
53      * Generate a PDF report
54      * @param reportDef resource name of the XML report definition file
55      * @param pdfFile file where to store the resulting PDF document
56      * @param parameters the parameters to fill the report with
57      */

58     public static void genReport(String JavaDoc reportDef, File JavaDoc pdfFile, Map JavaDoc parameters)
59         throws JRException
60     {
61         JasperReport report = getJasperReport(reportDef);
62         logger.debug("Filling report "+report);
63         JasperPrint print =
64             JasperFillManager.fillReport(
65                 report,
66                 parameters,
67                 new JacDataSource(ClassRepository.get().getClass(Class JavaDoc.class)));
68         logger.debug("Exporting report "+print);
69         JasperExportManager.exportReportToPdfFile(print,pdfFile.getPath());
70         logger.debug("Done");
71     }
72
73     /**
74      * Generate a PDF report
75      * @param reportDef resource name of the XML report definition file
76      * @param out file where to store the resulting PDF document
77      * @param parameters the parameters to fill the report with
78      * @param dataSource the data source
79      */

80     public static void genReport(String JavaDoc reportDef, OutputStream JavaDoc out,
81                                  Map JavaDoc parameters, JRDataSource dataSource)
82         throws JRException
83     {
84         JasperReport report = getJasperReport(reportDef);
85         logger.debug("Filling report "+report);
86         JasperPrint print =
87             JasperFillManager.fillReport(
88                 report,
89                 parameters,
90                 dataSource);
91         logger.debug("Exporting report "+print);
92         JasperExportManager.exportReportToPdfStream(print,out);
93         logger.debug("Done");
94     }
95
96     public static JasperReport getJasperReport(String JavaDoc reportDef) throws JRException {
97         logger.debug("Compiling report file "+reportDef);
98         return
99             JasperCompileManager.compileReport(
100                 Actions.class.getClassLoader().getResourceAsStream(reportDef));
101     }
102 }
103
Popular Tags