Guest
Public paste!

icetap

By: a guest | Mar 22nd, 2010 | Syntax: Java 5 | Size: 1.89 KB | Hits: 55 | Expires: Never
Copy text to clipboard
  1. public class RaportyServlet extends HttpServletBean {
  2.  
  3.         @Autowired
  4.         private IRaportyService raportyService;
  5.  
  6.         @Autowired
  7.         private IGenericServiceFacade genericRead;
  8.  
  9.         @Override
  10.         protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  11.                 Set<IServiceInvocationDTO> odczyty = new HashSet<IServiceInvocationDTO>();
  12.                 Map<ServiceFacadeIdEnum, IBaseDTO> genericRead2 = genericRead.genericRead(odczyty);
  13.  
  14.                 // TODO : utworzyc zbiorcze DTO
  15.                 IBaseDTO dane = new IBaseDTO() {
  16.                 };
  17.  
  18.                 // TODO : pobrac z request format wydruku i raporty
  19.                 String reportFormatStr = request.getParameter("format");
  20.                 ReportFormatEnum reportFormat = ReportFormatEnum.valueOf(reportFormatStr);
  21.                
  22.                 String sectionsStr = request.getParameter("sections");
  23.                 StringTokenizer stringTokenizer = new StringTokenizer(sectionsStr, ",");
  24.                 ReportTemplateEnum[] reportTemplates = new ReportTemplateEnum[stringTokenizer.countTokens()];
  25.                
  26.                 int i=0;
  27.                 String reportTemplate;
  28.                 while (stringTokenizer.hasMoreTokens()) {
  29.                         reportTemplate = stringTokenizer.nextToken();
  30.                         reportTemplates[i++] = ReportTemplateEnum.valueOf(reportTemplate);
  31.                 }
  32.                
  33.                 byte[] report = raportyService.generateReport(dane, reportFormat, request.getLocale().getLanguage(), reportTemplates);
  34.  
  35.                 ByteArrayOutputStream beos = new ByteArrayOutputStream(report.length);
  36.                 beos.write(report);
  37.                
  38.                 writeExportToResponseStream(reportFormat.getContentType(), response, beos);
  39.         }
  40.  
  41.         private final void writeExportToResponseStream(String contentType, HttpServletResponse response, ByteArrayOutputStream beos) {
  42.                 response.setContentType(contentType);
  43.                 response.setContentLength(beos.size());
  44.  
  45.                 try {
  46.                         ServletOutputStream out1 = response.getOutputStream();
  47.                         beos.writeTo(out1);
  48.                         out1.flush();
  49.  
  50.                 }
  51.                 catch (final Exception e) {
  52.                         throw new ReportGenerationException("todo");
  53.                 }
  54.         }
  55.  
  56. }