@Test public void testCreateParentFolder() { String filename = getTestDirectory() + "/" +"testfile.pdf"; MasterReport report = Mockito.mock( MasterReport.class ); ModifiableConfiguration conf = Mockito.spy( new DefaultConfiguration() ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.pdf.TargetFileName", filename ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.pdf.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() ); PdfExportTask task = new PdfExportTask( 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(); }
public void run() { PageableReportProcessor proc = null; OutputStream fout = null; try { if ( createParentFolder ) { final File directory = targetFile.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { PdfExportTask.logger.warn( "Can't create directories." ); } } } } fout = new BufferedOutputStream( new FileOutputStream( targetFile ) ); final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() ); proc = new PageableReportProcessor( report, outputProcessor ); if ( progressListener != null ) { proc.addReportProgressListener( progressListener ); progressListener.setVisible( true ); } proc.processReport(); if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "PdfExportTask.USER_EXPORT_COMPLETE" ), null ); } } catch ( Exception e ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "PdfExportTask.USER_EXPORT_FAILED" ), e ); } PdfExportTask.logger.error( "Failed" ); } finally { if ( proc != null ) { if ( progressListener != null ) { proc.removeReportProgressListener( progressListener ); } proc.close(); } if ( fout != null ) { try { fout.close(); } catch ( IOException e ) { } } if ( progressListener != null ) { progressListener.setVisible( false ); } } }
PdfExportTask implements Runnable { public void run() { PageableReportProcessor proc = null; OutputStream fout = null; try { if ( createParentFolder ) { final File directory = targetFile.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { PdfExportTask.logger.warn( "Can't create directories." ); } } } } fout = new BufferedOutputStream( new FileOutputStream( targetFile ) ); final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() ); proc = new PageableReportProcessor( report, outputProcessor ); if ( progressListener != null ) { proc.addReportProgressListener( progressListener ); progressListener.setVisible( true ); } proc.processReport(); if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "PdfExportTask.USER_EXPORT_COMPLETE" ), null ); } } catch ( Exception e ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "PdfExportTask.USER_EXPORT_FAILED" ), e ); } PdfExportTask.logger.error( "Failed" ); } finally { if ( proc != null ) { if ( progressListener != null ) { proc.removeReportProgressListener( progressListener ); } proc.close(); } if ( fout != null ) { try { fout.close(); } catch ( IOException e ) { } } if ( progressListener != null ) { progressListener.setVisible( false ); } } } }
PdfExportTask implements Runnable { public void run() { PageableReportProcessor proc = null; OutputStream fout = null; try { if ( createParentFolder ) { final File directory = targetFile.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { PdfExportTask.logger.warn( "Can't create directories." ); } } } } fout = new BufferedOutputStream( new FileOutputStream( targetFile ) ); final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() ); proc = new PageableReportProcessor( report, outputProcessor ); if ( progressListener != null ) { proc.addReportProgressListener( progressListener ); progressListener.setVisible( true ); } proc.processReport(); if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "PdfExportTask.USER_EXPORT_COMPLETE" ), null ); } } catch ( Exception e ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "PdfExportTask.USER_EXPORT_FAILED" ), e ); } PdfExportTask.logger.error( "Failed" ); } finally { if ( proc != null ) { if ( progressListener != null ) { proc.removeReportProgressListener( progressListener ); } proc.close(); } if ( fout != null ) { try { fout.close(); } catch ( IOException e ) { } } if ( progressListener != null ) { progressListener.setVisible( false ); } } } PdfExportTask( final MasterReport report, final ReportProgressDialog progressListener,
      final SwingGuiContext swingGuiContext ); }
PdfExportTask implements Runnable { public void run() { PageableReportProcessor proc = null; OutputStream fout = null; try { if ( createParentFolder ) { final File directory = targetFile.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { PdfExportTask.logger.warn( "Can't create directories." ); } } } } fout = new BufferedOutputStream( new FileOutputStream( targetFile ) ); final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() ); proc = new PageableReportProcessor( report, outputProcessor ); if ( progressListener != null ) { proc.addReportProgressListener( progressListener ); progressListener.setVisible( true ); } proc.processReport(); if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "PdfExportTask.USER_EXPORT_COMPLETE" ), null ); } } catch ( Exception e ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "PdfExportTask.USER_EXPORT_FAILED" ), e ); } PdfExportTask.logger.error( "Failed" ); } finally { if ( proc != null ) { if ( progressListener != null ) { proc.removeReportProgressListener( progressListener ); } proc.close(); } if ( fout != null ) { try { fout.close(); } catch ( IOException e ) { } } if ( progressListener != null ) { progressListener.setVisible( false ); } } } PdfExportTask( final MasterReport report, final ReportProgressDialog progressListener,
      final SwingGuiContext swingGuiContext ); void run(); }
PdfExportTask implements Runnable { public void run() { PageableReportProcessor proc = null; OutputStream fout = null; try { if ( createParentFolder ) { final File directory = targetFile.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { PdfExportTask.logger.warn( "Can't create directories." ); } } } } fout = new BufferedOutputStream( new FileOutputStream( targetFile ) ); final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() ); proc = new PageableReportProcessor( report, outputProcessor ); if ( progressListener != null ) { proc.addReportProgressListener( progressListener ); progressListener.setVisible( true ); } proc.processReport(); if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "PdfExportTask.USER_EXPORT_COMPLETE" ), null ); } } catch ( Exception e ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "PdfExportTask.USER_EXPORT_FAILED" ), e ); } PdfExportTask.logger.error( "Failed" ); } finally { if ( proc != null ) { if ( progressListener != null ) { proc.removeReportProgressListener( progressListener ); } proc.close(); } if ( fout != null ) { try { fout.close(); } catch ( IOException e ) { } } if ( progressListener != null ) { progressListener.setVisible( false ); } } } PdfExportTask( final MasterReport report, final ReportProgressDialog progressListener,
      final SwingGuiContext swingGuiContext ); void run();  }