1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
/**
* Impression 1 : Fiche référence
* @param request
* @param response
* @param list
* @param parameters
* @param dtoContexte
* @throws Exception
* @author Olivier BUTTERLIN
*/
private void print1(HttpServletRequest request, HttpServletResponse response, List<DTOReference> list, Map<String, Object> parameters, DTOContexte dtoContexte) throws Exception
{
JasperPrint jasperPrint = null;
String jasperPath = null;
String jrxmlPath = null;
/*
* Compilation si besoin des fichiers
*/
jasperPath = request.getSession().getServletContext().getRealPath("/editions/references/referenceFicheElement.jasper");
jrxmlPath = request.getSession().getServletContext().getRealPath("/editions/references/referenceFicheElement.jrxml");
compileJrxml(jrxmlPath, jasperPath);
jasperPath = request.getSession().getServletContext().getRealPath("/editions/references/referenceFiche.jasper");
jrxmlPath = request.getSession().getServletContext().getRealPath("/editions/references/referenceFiche.jrxml");
compileJrxml(jrxmlPath, jasperPath);
JRDataSource jrDataSource = new JRBeanCollectionDataSource(list);
jasperPrint = JasperFillManager.fillReport(jasperPath, parameters, jrDataSource);
exportJasperPrint(request, response, jasperPrint);
}
/**
* Compilation du fichier source
* @param sourcePath
* @param targetPath
* @throws Exception
*/
private void compileJrxml(String jrxmlPath, String jasperPath) throws Exception
{
File fileJasper = new File(jasperPath);
if (!fileJasper.exists())
{
JasperDesign jasperDesign = JRXmlLoader.load(jrxmlPath);
JasperCompileManager.compileReportToFile(jasperDesign, jasperPath);
}
else
{
File fileJrxml = new File(jrxmlPath);
if (fileJrxml.exists() && fileJrxml.lastModified() > fileJasper.lastModified())
{
JasperDesign jasperDesign = JRXmlLoader.load(jrxmlPath);
JasperCompileManager.compileReportToFile(jasperDesign, jasperPath);
}
}
} |
Partager