@Test public void testCreateParentFolder() { String filename = getTestDirectory() + "/" + "testfile.xlsx"; MasterReport report = Mockito.mock( MasterReport.class ); ModifiableConfiguration conf = Mockito.spy( new DefaultConfiguration() ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.xls.FileName", filename ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.xls.CreateParentFolder", "true" ); Mockito.doReturn(conf).when(report).getConfiguration(); File file = null; File directory; try { file = new File( filename ).getCanonicalFile(); directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == true ) { directory.delete(); } } Assert.assertFalse( directory.exists() ); ExcelExportTask task = new ExcelExportTask( report, null, null ); task.run(); } catch (Exception e1) { e1.printStackTrace(); } directory = file.getParentFile(); Assert.assertTrue( directory != null ); Assert.assertTrue( directory.exists() ); file.delete(); directory.delete(); }
@Override public void run() { OutputStream out = null; File file = null; try { file = new File( fileName ).getCanonicalFile(); if ( createParentFolder ) { final File directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { XSSFExcelExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportStructureValidator validator = new ReportStructureValidator(); ReportProcessor reportProcessor; if ( validator.isValidForFastProcessing( report ) == false ) { final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); target.setUseXlsxFormat( true ); reportProcessor = new FlowReportProcessor( report, target ); } else { reportProcessor = new FastExcelExportProcessor( report, out, true ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "ExcelExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { XSSFExcelExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { XSSFExcelExportTask.logger.error( "Excel export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { XSSFExcelExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } }
XSSFExcelExportTask implements Runnable { @Override public void run() { OutputStream out = null; File file = null; try { file = new File( fileName ).getCanonicalFile(); if ( createParentFolder ) { final File directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { XSSFExcelExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportStructureValidator validator = new ReportStructureValidator(); ReportProcessor reportProcessor; if ( validator.isValidForFastProcessing( report ) == false ) { final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); target.setUseXlsxFormat( true ); reportProcessor = new FlowReportProcessor( report, target ); } else { reportProcessor = new FastExcelExportProcessor( report, out, true ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "ExcelExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { XSSFExcelExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { XSSFExcelExportTask.logger.error( "Excel export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { XSSFExcelExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } }
XSSFExcelExportTask implements Runnable { @Override public void run() { OutputStream out = null; File file = null; try { file = new File( fileName ).getCanonicalFile(); if ( createParentFolder ) { final File directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { XSSFExcelExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportStructureValidator validator = new ReportStructureValidator(); ReportProcessor reportProcessor; if ( validator.isValidForFastProcessing( report ) == false ) { final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); target.setUseXlsxFormat( true ); reportProcessor = new FlowReportProcessor( report, target ); } else { reportProcessor = new FastExcelExportProcessor( report, out, true ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "ExcelExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { XSSFExcelExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { XSSFExcelExportTask.logger.error( "Excel export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { XSSFExcelExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } XSSFExcelExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); }
XSSFExcelExportTask implements Runnable { @Override public void run() { OutputStream out = null; File file = null; try { file = new File( fileName ).getCanonicalFile(); if ( createParentFolder ) { final File directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { XSSFExcelExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportStructureValidator validator = new ReportStructureValidator(); ReportProcessor reportProcessor; if ( validator.isValidForFastProcessing( report ) == false ) { final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); target.setUseXlsxFormat( true ); reportProcessor = new FlowReportProcessor( report, target ); } else { reportProcessor = new FastExcelExportProcessor( report, out, true ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "ExcelExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { XSSFExcelExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { XSSFExcelExportTask.logger.error( "Excel export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { XSSFExcelExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } XSSFExcelExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); @Override void run(); }
XSSFExcelExportTask implements Runnable { @Override public void run() { OutputStream out = null; File file = null; try { file = new File( fileName ).getCanonicalFile(); if ( createParentFolder ) { final File directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { XSSFExcelExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportStructureValidator validator = new ReportStructureValidator(); ReportProcessor reportProcessor; if ( validator.isValidForFastProcessing( report ) == false ) { final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); target.setUseXlsxFormat( true ); reportProcessor = new FlowReportProcessor( report, target ); } else { reportProcessor = new FastExcelExportProcessor( report, out, true ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "ExcelExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { XSSFExcelExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { XSSFExcelExportTask.logger.error( "Excel export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { XSSFExcelExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "ExcelExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } XSSFExcelExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); @Override void run();  }