← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19780: Deprecation fixes for jasper reports

 

------------------------------------------------------------
revno: 19780
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-08-18 17:14:00 -0400
message:
  Deprecation fixes for jasper reports
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java	2015-08-18 20:10:50 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/JRExportUtils.java	2015-08-18 21:14:00 +0000
@@ -29,18 +29,14 @@
  */
 
 import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Map;
 
-import net.sf.jasperreports.engine.JRAbstractExporter;
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JRExporterParameter;
 import net.sf.jasperreports.engine.JasperPrint;
-import net.sf.jasperreports.engine.export.JRHtmlExporter;
-import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
 import net.sf.jasperreports.engine.export.JRPdfExporter;
-import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
 import net.sf.jasperreports.engine.export.JRXlsExporter;
+import net.sf.jasperreports.export.SimpleExporterInput;
+import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
+import net.sf.jasperreports.export.SimpleXlsReportConfiguration;
 
 /**
  * Supports PDF, HMTL and XLS exports.
@@ -51,15 +47,7 @@
 {
     public static final String TYPE_XLS = "xls";
     public static final String TYPE_PDF = "pdf";
-    public static final String TYPE_HTML = "html";
     
-    private static final Map<String, JRExportProvider> exporters = new HashMap<String, JRExportProvider>() {    
-    {
-        put( TYPE_XLS, new JRXlsExportProvider() );
-        put( TYPE_PDF, new JRPdfExportProvider() );
-        put( TYPE_HTML, new JRHtmlExportProvider() );
-    } };
-
     /**
      * Export the provided JasperPrint the format given by type.
      *
@@ -71,56 +59,28 @@
     public static void export( String type, OutputStream out, JasperPrint jasperPrint )
         throws JRException
     {
-        JRExportProvider provider = exporters.get( type );
-        
-        if ( provider != null )
-        {
-            JRAbstractExporter exporter = provider.provide();
-            
-            exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, out );
-            exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasperPrint );
-            exporter.exportReport();
-        }
-    }
-    
-    private interface JRExportProvider
-    {
-        JRAbstractExporter provide();
-    }
-    
-    private static class JRXlsExportProvider implements JRExportProvider
-    {
-        @Override
-        public JRAbstractExporter provide()
-        {
+        if ( TYPE_XLS.equals( type ) )
+        {
+            SimpleXlsReportConfiguration config = new SimpleXlsReportConfiguration();
+            
+            config.setDetectCellType( true );
+            config.setRemoveEmptySpaceBetweenRows( true );
+            config.setRemoveEmptySpaceBetweenRows( true );
+            config.setCollapseRowSpan( true );
+            config.setWhitePageBackground( false );
+            
             JRXlsExporter exporter = new JRXlsExporter();
-            exporter.setParameter( JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE );
-            exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE );
-            exporter.setParameter( JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE );
-            exporter.setParameter( JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE );
-            exporter.setParameter( JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE );
-            return exporter;
-        }
-    }
-    
-    private static class JRPdfExportProvider implements JRExportProvider
-    {
-        @Override
-        public JRAbstractExporter provide()
-        {
-            return new JRPdfExporter();
-        }
-    }
-    
-    private static class JRHtmlExportProvider implements JRExportProvider
-    {
-        @Override
-        public JRAbstractExporter provide()
-        {
-            JRHtmlExporter exporter = new JRHtmlExporter();
-            exporter.setParameter( JRHtmlExporterParameter.IMAGES_URI, "../jasperReports/img?image=" );
-            
-            return exporter;
+            exporter.setExporterInput( new SimpleExporterInput( jasperPrint ) );
+            exporter.setExporterOutput( new SimpleOutputStreamExporterOutput( out ) );
+            exporter.setConfiguration( config );
+            exporter.exportReport();
+        }
+        else if ( TYPE_PDF.equals( type ) )
+        {
+            JRPdfExporter exporter = new JRPdfExporter();
+            exporter.setExporterInput( new SimpleExporterInput( jasperPrint ) );
+            exporter.setExporterOutput( new SimpleOutputStreamExporterOutput( out ) );
+            exporter.exportReport();
         }
     }
 }