1 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 ; 29 import java.io.FileOutputStream ; 30 import java.io.IOException ; 31 import java.io.OutputStream ; 32 import java.util.HashMap ; 33 import java.util.Map ; 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 46 public static void genReport(String reportDef, File pdfFile) 47 throws JRException 48 { 49 genReport(reportDef,pdfFile,new HashMap ()); 50 } 51 52 58 public static void genReport(String reportDef, File pdfFile, Map 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 .class))); 68 logger.debug("Exporting report "+print); 69 JasperExportManager.exportReportToPdfFile(print,pdfFile.getPath()); 70 logger.debug("Done"); 71 } 72 73 80 public static void genReport(String reportDef, OutputStream out, 81 Map 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 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 |