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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Store the report to generate
String rptdesignFile = request.getParameter("__report");
//Store the generation format
String outputFormat = request.getParameter("outputFormat");
//Store the mode of generation
String genMode = request.getParameter("genMode");
String reportPath = new String();
String imageDirectory = new String();
String birtReportEngine = new String();
try {
ConfXML settingParamatersconf = new ConfXML();
//Store the report directory path (where all rptdesign files arestored)
reportPath = settingParamatersconf.getTagValue("reports-path-directory");
imageDirectory = settingParamatersconf.getTagValue("image-directory");
birtReportEngine = settingParamatersconf.getTagValue("report-engine");
System.out.println("reportPath = "+reportPath);
} catch (Exception e) {
e.printStackTrace();
}
// Get the values set by the application for all parameters.
HashMap myParametersList = new HashMap();
// Store parameters values depending on reports
if (rptdesignFile.equals("priority_by_status.rptdesign")){
myParametersList.put("niveau_criticite", request.getParameter("niveau_criticite"));
myParametersList.put("issue_type", request.getParameter("issue_type"));
}
Editionv2 genrationRapport = new Editionv2();
//Initialization of Editionv2 instance
genrationRapport.initEdition(birtReportEngine,
reportPath+rptdesignFile,
myParametersList,
outputFormat,
(reportPath+rptdesignFile).replaceFirst( ".rptdesign", "."+outputFormat.toLowerCase()),
genMode,
imageDirectory,
request.getContextPath() );
//Generate
genrationRapport.run();
//set the appropriate MIME type according to the output format
if (outputFormat.equals("HTML") || genMode.equals("DEP")){
response.setContentType("text/html");
} else if ( outputFormat.equals("PDF")) {
response.setContentType("application/pdf");
} else if ( outputFormat.equals("XLS")) {
response.setContentType("application/vnd.ms-excel");
//response.setHeader("Content-disposition","inline; filename=nombre.csv");
} else if ( outputFormat.equals("DOC")) {
response.setContentType("application/msword");
} else {
response.setContentType("text/html");
}
response.setHeader("Cache-Control","must-revalidate");
if (genMode.equals("AFF")) {
//Get the output stream of the servlet
OutputStream outputStreamServlet = response.getOutputStream();
//Copy stream generating by the report into the output stream of the servlet
((ByteArrayOutputStream) genrationRapport.getOptions().getOutputStream()).writeTo(outputStreamServlet);
//Close the stream
outputStreamServlet.close();
}
} |
Partager