@Test public void testExportToRTFFile() throws Exception { String filename = "./testfile.rtf"; MasterReport report = Mockito.mock( MasterReport.class ); ModifiableConfiguration conf = Mockito.spy( new DefaultConfiguration() ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.rtf.FileName", filename ); Mockito.doReturn( conf ).when( report ).getConfiguration(); File file = new File( filename ).getCanonicalFile(); Assert.assertFalse( file.exists() ); RTFExportTask task = new RTFExportTask( report, null, null ); task.run(); Assert.assertTrue( file != null ); Assert.assertTrue( file.exists() ); file.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 ) { RTFExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); final StreamReportProcessor proc = new StreamReportProcessor( report, target ); if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); proc.addReportProgressListener( progressDialog ); } proc.processReport(); out.close(); if ( progressDialog != null ) { proc.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "RTFExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { RTFExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { RTFExportTask.logger.error( "RTF export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { RTFExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } }
RTFExportTask 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 ) { RTFExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); final StreamReportProcessor proc = new StreamReportProcessor( report, target ); if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); proc.addReportProgressListener( progressDialog ); } proc.processReport(); out.close(); if ( progressDialog != null ) { proc.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "RTFExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { RTFExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { RTFExportTask.logger.error( "RTF export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { RTFExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } }
RTFExportTask 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 ) { RTFExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); final StreamReportProcessor proc = new StreamReportProcessor( report, target ); if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); proc.addReportProgressListener( progressDialog ); } proc.processReport(); out.close(); if ( progressDialog != null ) { proc.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "RTFExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { RTFExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { RTFExportTask.logger.error( "RTF export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { RTFExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } RTFExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); }
RTFExportTask 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 ) { RTFExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); final StreamReportProcessor proc = new StreamReportProcessor( report, target ); if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); proc.addReportProgressListener( progressDialog ); } proc.processReport(); out.close(); if ( progressDialog != null ) { proc.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "RTFExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { RTFExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { RTFExportTask.logger.error( "RTF export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { RTFExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } RTFExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); @Override void run(); }
RTFExportTask 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 ) { RTFExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); final StreamRTFOutputProcessor target = new StreamRTFOutputProcessor( report.getConfiguration(), out, report.getResourceManager() ); final StreamReportProcessor proc = new StreamReportProcessor( report, target ); if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); proc.addReportProgressListener( progressDialog ); } proc.processReport(); out.close(); if ( progressDialog != null ) { proc.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "RTFExportTask.USER_TASK_FINISHED" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { RTFExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { RTFExportTask.logger.error( "RTF export failed", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { RTFExportTask.logger.error( "Unable to close the output stream.", e ); if ( statusListener != null ) { statusListener.setStatus( StatusType.WARNING, messages.getString( "RTFExportTask.USER_TASK_FAILED" ), e ); } } } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } RTFExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); @Override void run();  }