| 
						
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -1,6 +1,7 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				package info.bukova.isspst.reporting;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import java.io.IOException;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import java.io.OutputStream;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import javax.servlet.ServletOutputStream;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				import javax.servlet.http.HttpServletResponse;
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -16,38 +17,46 @@ public class ReportController {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					private ReportDefinition reportDefinition;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					@Autowired
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					private GeneratorFactory factory;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					private static final String ERROR_MESSAGE = "<html><body><b>Generator returned no data!</b><br/>%s</body></html>";
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					@RequestMapping("report.pdf")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					public void pdfReport(HttpServletResponse response) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Generator gen = factory.createGenerator(reportDefinition);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						byte[] data = gen.generate();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						String contentType = "application/pdf";
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						ServletOutputStream os = null;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					private void writeError(OutputStream stream, Throwable e) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						writeError(stream, e.toString());
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					private void writeError(OutputStream stream, String message) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						String err =  String.format(ERROR_MESSAGE, message);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						try {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							os = response.getOutputStream();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							stream.write(err.getBytes(), 0, err.getBytes().length);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						} catch (IOException e1) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							e1.printStackTrace();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							return;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					@RequestMapping("report.pdf")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					public void pdfReport(HttpServletResponse response) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						final String contentType = "application/pdf";
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//		if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//			writeError(os, "Definition is null");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//			return;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//		}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						ServletOutputStream os = null;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						response.setContentType(contentType);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						response.setContentLength(data.length);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						try {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							os = response.getOutputStream();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								throw new ReportException("Definition is null");
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							Generator gen = factory.createGenerator(reportDefinition);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							byte[] data = gen.generate();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							response.setContentType(contentType);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							response.setContentLength(data.length);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							os.write(data, 0, data.length);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							os.flush();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							os.close();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						} catch (IOException e) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							e.printStackTrace();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//		} catch (ReportException e) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				//			writeError(os, e);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						} catch (ReportException e) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							writeError(os, e);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						} finally {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
							if (os != null) {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
								try {
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |