Search in sources :

Example 1 with ManagedProcess

use of com.adobe.acs.commons.mcp.model.ManagedProcess in project acs-aem-commons by Adobe-Consulting-Services.

the class ProcessErrorReportExcelServlet method doGet.

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    ManagedProcess report = request.getResource().adaptTo(ManagedProcess.class);
    if (report != null) {
        String title = report.getName();
        String fileName = JcrUtil.createValidName(title) + ".xlsx";
        Workbook workbook = createSpreadsheet(report);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        try (ServletOutputStream out = response.getOutputStream()) {
            workbook.write(out);
            out.flush();
        } catch (Exception ex) {
            LOG.error("Error generating excel export for " + request.getResource().getPath(), ex);
            throw ex;
        }
    } else {
        LOG.error("Unable to process report stored at " + request.getResource().getPath());
        throw new ServletException("Unable to process report stored at " + request.getResource().getPath());
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletOutputStream(javax.servlet.ServletOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ManagedProcess(com.adobe.acs.commons.mcp.model.ManagedProcess)

Aggregations

ManagedProcess (com.adobe.acs.commons.mcp.model.ManagedProcess)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1