Java Code Examples for org.pentaho.reporting.engine.classic.core.MasterReport#getConfiguration()

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractExportActionPlugin.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Exports a report.
 *
 * @param job
 *          the report.
 * @return A boolean.
 */
public boolean performShowExportDialog( final MasterReport job, final String configKey ) {
  try {
    final Configuration configuration = job.getConfiguration();
    final String dialogClassName = configuration.getConfigProperty( configKey );
    final ExportDialog dialog = createExportDialog( dialogClassName );

    return dialog.performQueryForExport( job, getContext() );
  } catch ( InstantiationException e ) {
    AbstractExportActionPlugin.logger.error( messages
        .getErrorString( "AbstractExportActionPlugin.ERROR_0005_UNABLE_TO_CONFIGURE" ) ); //$NON-NLS-1$
    getContext().getStatusListener().setStatus( StatusType.ERROR,
        messages.getString( "AbstractExportActionPlugin.ERROR_0005_UNABLE_TO_CONFIGURE" ), e ); //$NON-NLS-1$
    return false;
  }
}
 
Example 2
Source File: StateUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ReportParameterValues computeParameterValueSet( final MasterReport report,
    final ReportParameterValues parameterValues ) throws ReportProcessingException {
  final ReportParameterValues retval = new ReportParameterValues();
  retval.putAll( parameterValues );

  final Configuration config = report.getConfiguration();
  if ( "true".equals( config
      .getConfigProperty( "org.pentaho.reporting.engine.classic.core.legacy.ReportNameAsProperty" ) ) ) {
    retval.put( "report.name", report.getName() );
  }

  final ReportEnvironment reportEnvironment = report.getReportEnvironment();
  final Object property = reportEnvironment.getEnvironmentProperty( "::internal::report.date" );
  if ( property instanceof Date == false ) {
    retval.put( MasterReport.REPORT_DATE_PROPERTY, new Date() );
  } else {
    retval.put( MasterReport.REPORT_DATE_PROPERTY, property );
  }
  return retval;
}
 
Example 3
Source File: DebugReportRunner.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Configuration wrapForCompatibility( final MasterReport processingContext ) {
  final Integer compatibilityLevel = processingContext.getCompatibilityLevel();
  if ( compatibilityLevel == null || compatibilityLevel < 0 ) {
    return processingContext.getConfiguration();
  }

  if ( compatibilityLevel < ClassicEngineBoot.computeVersionId( 3, 999, 999 ) ) {
    // enable strict compatibility mode for reports older than 4.0.
    final HierarchicalConfiguration config = new HierarchicalConfiguration( processingContext.getConfiguration() );
    config.setConfigProperty( "org.pentaho.reporting.engine.classic.core.legacy.WrapProgressMarkerInSection", "true" );
    config.setConfigProperty( "org.pentaho.reporting.engine.classic.core.legacy.StrictCompatibility", "true" );
    return config;
  }

  // this is a trunk or 4.0 or newer report.
  return processingContext.getConfiguration();
}
 
Example 4
Source File: ExcelReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void createXLSX( final MasterReport report, final OutputStream outputStream,
                               final ReportProgressListener listener )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( outputStream == null ) {
    throw new NullPointerException();
  }

  final FlowExcelOutputProcessor target =
    new FlowExcelOutputProcessor( report.getConfiguration(), outputStream, report.getResourceManager() );
  target.setUseXlsxFormat( true );
  final FlowReportProcessor reportProcessor = new FlowReportProcessor( report, target );
  if ( listener != null ) {
    reportProcessor.addReportProgressListener( listener );
  }
  doProcess( listener, reportProcessor );
}
 
Example 5
Source File: HtmlReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void createStreamHTML( final MasterReport report, final OutputStream outputStream )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( outputStream == null ) {
    throw new NullPointerException();
  }
  final StreamRepository targetRepository = new StreamRepository( outputStream );
  final ContentLocation targetRoot = targetRepository.getRoot();

  final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor( report.getConfiguration() );
  final HtmlPrinter printer = new AllItemsHtmlPrinter( report.getResourceManager() );
  printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, "index", "html" ) );
  printer.setDataWriter( null, null );
  printer.setUrlRewriter( new FileSystemURLRewriter() );
  outputProcessor.setPrinter( printer );

  final StreamReportProcessor sp = new StreamReportProcessor( report, outputProcessor );
  sp.processReport();
  sp.close();
}
 
Example 6
Source File: Prd4069IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testStreamTableExport() throws ReportProcessingException {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }
  final MasterReport report = createTestReport();
  final StreamRepository targetRepository = new StreamRepository( new NullOutputStream() );
  final ContentLocation targetRoot = targetRepository.getRoot();

  final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor( report.getConfiguration() );
  final HtmlPrinter printer = new ValidatingHtmlPrinter( report.getResourceManager() );
  printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, "index", "html" ) );
  printer.setDataWriter( null, null );
  printer.setUrlRewriter( new FileSystemURLRewriter() );
  outputProcessor.setPrinter( printer );

  final StreamReportProcessor sp = new StreamReportProcessor( report, outputProcessor );
  sp.processReport();
  sp.close();
}
 
Example 7
Source File: Pre34IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReportSizePRD4251() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }
  final URL url = getClass().getResource( "Pre-34.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();

  final PageableReportProcessor p =
      new PageableReportProcessor( resource, new GraphicsOutputProcessor( resource.getConfiguration() ) );
  p.paginate();

  // if you return 1, then your datasource is f'd up.
  assertTrue( p.getPhysicalPageCount() > 10 );
}
 
Example 8
Source File: StraightToPlainText.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Saves a report to PDF format.
 *
 * @param report   the report.
 * @param fileName target file name.
 * @return true or false.
 */
public boolean savePlainText(final MasterReport report, final String fileName)
{
  try
  {
    final BufferedOutputStream fout = new BufferedOutputStream
        (new FileOutputStream(fileName));

    // cpi = 15, lpi = 10
    final TextFilePrinterDriver pc = new TextFilePrinterDriver(fout, 15, 10);

    final PageableTextOutputProcessor outputProcessor = new PageableTextOutputProcessor(pc,
        report.getConfiguration());
    final PageableReportProcessor proc = new PageableReportProcessor(report, outputProcessor);
    proc.processReport();
    proc.close();
    fout.close();
    return true;
  }
  catch (Exception e)
  {
    logger.error("Writing PlainText failed.", e);
    return false;
  }
}
 
Example 9
Source File: BundleMetaFileWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeVersionMarker( final WriteableDocumentMetaData writeableMetaData, final MasterReport masterReport ) {
  final int releaseMajor = ParserUtil.parseInt( ClassicEngineInfo.getInstance().getReleaseMajor(), -1 );
  final int releaseMinor = ParserUtil.parseInt( ClassicEngineInfo.getInstance().getReleaseMinor(), -1 );
  final int releasePatch = ParserUtil.parseInt( ClassicEngineInfo.getInstance().getReleaseMilestone(), -1 );
  int versionId = ClassicEngineBoot.computeVersionId( releaseMajor, releaseMinor, releasePatch );
  if ( versionId > 0 && ClassicEngineBoot.VERSION_TRUNK != versionId ) {
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.major",
        releaseMajor );
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.minor",
        releaseMinor );
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.patch",
        releasePatch );
  } else {
    final Configuration configuration = masterReport.getConfiguration();
    if ( "true"
        .equals( configuration
            .getConfigProperty( "org.pentaho.reporting.engine.classic.core.designtime.PreserveOriginalCompatibilitySettingInTrunk" ) ) ) {
      final Integer reportCompatibility = masterReport.getCompatibilityLevel();
      if ( reportCompatibility != null && reportCompatibility > 0 ) {
        final int patch = reportCompatibility % 1000;
        final int minor = ( reportCompatibility / 1000 ) % 1000;
        final int major = ( reportCompatibility / 1000000 );
        writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.major", major );
        writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.minor", minor );
        writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.patch", patch );
        return;
      }
    }
    // trunk is just the strongest player in town
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.major", 999 );
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.minor", 999 );
    writeableMetaData.setBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "prpt-spec.version.patch", 999 );
  }
}
 
Example 10
Source File: StreamHtmlReportProcessTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @noinspection ThrowableInstanceNeverThrown
 */
public void run() {
  if ( isValid() == false ) {
    setError( new ReportProcessingException( "Error: The task is not configured properly." ) );
    return;
  }

  setError( null );
  try {
    final MasterReport masterReport = getReport();
    final Configuration configuration = masterReport.getConfiguration();

    final HtmlPrinter printer = new AllItemsHtmlPrinter( masterReport.getResourceManager() );
    printer.setContentWriter( getBodyContentLocation(), getBodyNameGenerator() );
    printer.setDataWriter( getBulkLocation(), getBulkNameGenerator() );
    printer.setUrlRewriter( computeUrlRewriter() );

    final StreamHtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor( configuration );
    final StreamReportProcessor streamReportProcessor = new StreamReportProcessor( masterReport, outputProcessor );
    try {
      final ReportProgressListener[] progressListeners = getReportProgressListeners();
      for ( int i = 0; i < progressListeners.length; i++ ) {
        final ReportProgressListener listener = progressListeners[i];
        streamReportProcessor.addReportProgressListener( listener );
      }
      streamReportProcessor.processReport();
    } finally {
      streamReportProcessor.close();
    }
  } catch ( Throwable e ) {
    setError( e );
  }
}
 
Example 11
Source File: StraightToEverything.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Saves a report to plain text format.
 *
 * @param report   the report.
 * @param filename target file name.
 * @throws Exception if an error occurs.
 */
public static void createPlainText(final MasterReport report, final String filename)
    throws Exception
{
  final OutputStream fout = new BufferedOutputStream(new FileOutputStream(filename));
  // cpi = 15, lpi = 10
  final TextFilePrinterDriver pc = new TextFilePrinterDriver(fout, 15, 10);

  final PageableTextOutputProcessor outputProcessor = new PageableTextOutputProcessor(pc, report.getConfiguration());
  final PageableReportProcessor proc = new PageableReportProcessor(report, outputProcessor);
  proc.processReport();
  proc.close();
  fout.close();
}
 
Example 12
Source File: Prd4069IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFlowTableExport() throws ReportProcessingException {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }
  final MasterReport report = createTestReport();
  final FlowExcelOutputProcessor target =
      new ValidatingFlowExcelOutputProcessor( report.getConfiguration(), new NullOutputStream(), report
          .getResourceManager() );
  target.setUseXlsxFormat( true );
  final FlowReportProcessor reportProcessor = new FlowReportProcessor( report, target );
  reportProcessor.processReport();
  reportProcessor.close();

}
 
Example 13
Source File: StreamCSVReportProcessTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @noinspection ThrowableInstanceNeverThrown
 */
public void run() {
  if ( isValid() == false ) {
    setError( new ReportProcessingException( "Error: The task is not configured properly." ) );
    return;
  }

  setError( null );
  try {
    final MasterReport masterReport = getReport();
    final Configuration configuration = masterReport.getConfiguration();

    final ContentLocation contentLocation = getBodyContentLocation();
    final NameGenerator nameGenerator = getBodyNameGenerator();
    final ContentItem contentItem = contentLocation.createItem( nameGenerator.generateName( null, "text/csv" ) );
    final OutputStream outputStream = contentItem.getOutputStream();

    try {
      final StreamCSVOutputProcessor outputProcessor = new StreamCSVOutputProcessor( outputStream );
      final StreamReportProcessor streamReportProcessor = new StreamReportProcessor( masterReport, outputProcessor );
      try {
        final ReportProgressListener[] progressListeners = getReportProgressListeners();
        for ( int i = 0; i < progressListeners.length; i++ ) {
          final ReportProgressListener listener = progressListeners[i];
          streamReportProcessor.addReportProgressListener( listener );
        }
        streamReportProcessor.processReport();
      } finally {
        streamReportProcessor.close();
      }
    } finally {
      outputStream.close();
    }
  } catch ( Throwable e ) {
    setError( e );
  }
}
 
Example 14
Source File: PlainTextReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void createPlainText( final MasterReport report, final String filename ) throws IOException,
  ReportProcessingException {
  final Configuration configuration = report.getConfiguration();
  final String cpiText =
      configuration
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.plaintext.CharsPerInch" );
  final String lpiText =
      configuration
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.plaintext.LinesPerInch" );

  createPlainText( report, filename, ParserUtil.parseInt( cpiText, 10 ), ParserUtil.parseInt( lpiText, 6 ) );
}
 
Example 15
Source File: StreamRTFReportProcessTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @noinspection ThrowableInstanceNeverThrown
 */
public void run() {
  if ( isValid() == false ) {
    setError( new ReportProcessingException( "Error: The task is not configured properly." ) );
    return;
  }

  setError( null );
  try {
    final MasterReport masterReport = getReport();
    final Configuration configuration = masterReport.getConfiguration();

    final ContentLocation contentLocation = getBodyContentLocation();
    final NameGenerator nameGenerator = getBodyNameGenerator();
    final ContentItem contentItem =
        contentLocation.createItem( nameGenerator.generateName( null, "application/rtf" ) );
    final OutputStream outputStream = contentItem.getOutputStream();

    try {
      final StreamRTFOutputProcessor outputProcessor =
          new StreamRTFOutputProcessor( configuration, outputStream, masterReport.getResourceManager() );
      final StreamReportProcessor streamReportProcessor = new StreamReportProcessor( masterReport, outputProcessor );
      try {
        final ReportProgressListener[] progressListeners = getReportProgressListeners();
        for ( int i = 0; i < progressListeners.length; i++ ) {
          final ReportProgressListener listener = progressListeners[i];
          streamReportProcessor.addReportProgressListener( listener );
        }
        streamReportProcessor.processReport();
      } finally {
        streamReportProcessor.close();
      }
    } finally {
      outputStream.close();
    }
  } catch ( Throwable e ) {
    setError( e );
  }
}
 
Example 16
Source File: PdfReportProcessTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @noinspection ThrowableInstanceNeverThrown
 */
public void run() {
  if ( isValid() == false ) {
    setError( new ReportProcessingException( "Error: The task is not configured properly." ) );
    return;
  }

  setError( null );
  try {
    final MasterReport masterReport = getReport();
    final Configuration configuration = masterReport.getConfiguration();

    final ContentLocation contentLocation = getBodyContentLocation();
    final NameGenerator nameGenerator = getBodyNameGenerator();
    final ContentItem contentItem =
        contentLocation.createItem( nameGenerator.generateName( null, "application/pdf" ) );
    final OutputStream outputStream = contentItem.getOutputStream();

    try {
      final PdfOutputProcessor outputProcessor = new PdfOutputProcessor( configuration, outputStream );
      final PageableReportProcessor streamReportProcessor =
          new PageableReportProcessor( masterReport, outputProcessor );
      try {
        final ReportProgressListener[] progressListeners = getReportProgressListeners();
        for ( int i = 0; i < progressListeners.length; i++ ) {
          final ReportProgressListener listener = progressListeners[i];
          streamReportProcessor.addReportProgressListener( listener );
        }
        streamReportProcessor.processReport();
      } finally {
        streamReportProcessor.close();
      }
    } finally {
      outputStream.close();
    }
  } catch ( Throwable e ) {
    setError( e );
  }
}
 
Example 17
Source File: RTFReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void createRTF( final MasterReport report, final OutputStream outputStream )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( outputStream == null ) {
    throw new NullPointerException();
  }

  final StreamRTFOutputProcessor target =
      new StreamRTFOutputProcessor( report.getConfiguration(), outputStream, report.getResourceManager() );
  final StreamReportProcessor proc = new StreamReportProcessor( report, target );
  proc.processReport();
  proc.close();
}
 
Example 18
Source File: PageableXExcelReportProcessTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @noinspection ThrowableInstanceNeverThrown
 */
public void run() {
  if ( isValid() == false ) {
    setError( new ReportProcessingException( "Error: The task is not configured properly." ) );
    return;
  }

  setError( null );
  try {
    final MasterReport masterReport = getReport();
    final Configuration configuration = masterReport.getConfiguration();

    final ContentLocation contentLocation = getBodyContentLocation();
    final NameGenerator nameGenerator = getBodyNameGenerator();
    final ContentItem contentItem =
        contentLocation.createItem( nameGenerator.generateName( null,
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) );
    final OutputStream outputStream = contentItem.getOutputStream();

    try {
      final PageableExcelOutputProcessor outputProcessor =
          new PageableExcelOutputProcessor( configuration, outputStream, masterReport.getResourceManager() );
      outputProcessor.setUseXlsxFormat( true );
      final PageableReportProcessor streamReportProcessor =
          new PageableReportProcessor( masterReport, outputProcessor );
      try {
        final ReportProgressListener[] progressListeners = getReportProgressListeners();
        for ( int i = 0; i < progressListeners.length; i++ ) {
          final ReportProgressListener listener = progressListeners[i];
          streamReportProcessor.addReportProgressListener( listener );
        }
        streamReportProcessor.processReport();
      } finally {
        streamReportProcessor.close();
      }
    } finally {
      outputStream.close();
    }
  } catch ( Throwable e ) {
    setError( e );
  }
}
 
Example 19
Source File: HtmlStreamExportTask.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates a new html export task.
 *
 * @param dialog
 *          the progress monitor component.
 * @param report
 *          the report that should be exported.
 */
public HtmlStreamExportTask( final MasterReport report, final ReportProgressDialog dialog,
    final SwingGuiContext swingGuiContext ) throws ReportProcessingException {
  if ( report == null ) {
    throw new ReportProcessingException( "HtmlStreamExportTask(..): Report-Parameter cannot be null" ); //$NON-NLS-1$
  }
  try {
    this.progressDialog = dialog;
    this.report = report;
    if ( swingGuiContext != null ) {
      this.statusListener = swingGuiContext.getStatusListener();
      this.messages =
          new Messages( swingGuiContext.getLocale(), HtmlExportGUIModule.BASE_RESOURCE_CLASS, ObjectUtilities
              .getClassLoader( HtmlExportGUIModule.class ) );
    } else {
      this.messages =
          new Messages( Locale.getDefault(), HtmlExportGUIModule.BASE_RESOURCE_CLASS, ObjectUtilities
              .getClassLoader( HtmlExportGUIModule.class ) );
    }

    final Configuration config = report.getConfiguration();
    final String targetFileName =
        config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.html.stream.TargetFileName" ); //$NON-NLS-1$
    if ( targetFileName == null ) {
      throw new ReportProcessingException( messages.getErrorString( "HtmlStreamExportTask.ERROR_0002_TARGET_NOT_SET" ) ); //$NON-NLS-1$
    }
    final String createParentFolder =
      config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.html.stream.CreateParentFolder" ); //$NON-NLS-1$
    if ( createParentFolder == null ) {
      this.createParentFolder = false;
    } else {
      this.createParentFolder = Boolean.parseBoolean( createParentFolder );
    }
    final File targetFile = new File( targetFileName ).getCanonicalFile();
    targetDirectory = targetFile.getParentFile();

    suffix = getSuffix( targetFileName );
    filename = IOUtils.getInstance().stripFileExtension( targetFile.getName() );

    if ( targetFile.exists() ) {
      // lets try to delete it ..
      if ( targetFile.delete() == false ) {
        throw new ReportProcessingException( messages.getErrorString(
            "HtmlStreamExportTask.ERROR_0003_TARGET_FILE_EXISTS", targetFile.getAbsolutePath() ) ); //$NON-NLS-1$
      }
    }
  } catch ( IOException ioe ) {
    throw new ReportProcessingException( "Failed to normalize directories.", ioe );
  }
}
 
Example 20
Source File: XMLProcessor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Creates a new XMLProcessor. The processor will output the report as simple xml stream.
 *
 * @param report
 *          the report that should be processed
 * @throws ReportProcessingException
 *           if the report could not be initialized
 */
public XMLProcessor( final MasterReport report ) throws ReportProcessingException {
  super( report, new XMLDataOutputProcessor( report.getConfiguration() ) );
}