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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#derive() . 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: BundleWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void writeReport( final WriteableDocumentBundle bundle, final MasterReport report,
    final DocumentBundle globalBundle ) throws IOException, BundleWriterException {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( globalBundle == null ) {
    throw new NullPointerException();
  }

  final WriteableDocumentMetaData data = bundle.getWriteableDocumentMetaData();
  data.setBundleType( ClassicEngineBoot.BUNDLE_TYPE );

  final MasterReport clone = (MasterReport) report.derive();
  final BundleWriterState state = new BundleWriterState( clone, globalBundle, this );
  for ( int i = 0; i < masterWriter.length; i++ ) {
    final BundleWriterHandler handler = masterWriter[i];
    handler.writeReport( bundle, state );
  }
}
 
Example 2
Source File: LookAndFeelStep.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private AbstractReportDefinition loadDefinitionFromFile( final File filename ) {
  try {
    final ResourceKey selectedFile = resourceManager.createKey( filename );
    final Resource directly = resourceManager.create( selectedFile, null, new Class[] { MasterReport.class } );
    final MasterReport resource = (MasterReport) directly.getResource();
    final DocumentBundle bundle = resource.getBundle();
    if ( bundle == null ) {
      // Ok, that should not happen if we work with the engine's parsers, but better safe than sorry.
      final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle( resource.getContentBase() );
      documentBundle.getWriteableDocumentMetaData().setBundleType( ClassicEngineBoot.BUNDLE_TYPE );
      resource.setBundle( documentBundle );
      resource.setContentBase( documentBundle.getBundleMainKey() );
    } else {
      final MemoryDocumentBundle mem = new MemoryDocumentBundle( resource.getContentBase() );
      BundleUtilities.copyStickyInto( mem, bundle );
      BundleUtilities.copyMetaData( mem, bundle );
      resource.setBundle( mem );
      resource.setContentBase( mem.getBundleMainKey() );
    }

    return (AbstractReportDefinition) resource.derive();
  } catch ( Exception ex ) {
    getDesignTimeContext().error( ex );
    return null;
  }
}
 
Example 3
Source File: CrosstabRenderIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testClone() throws ResourceException {
  CrosstabElement element = new CrosstabElement();

  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( element );

  CrosstabElement ct0 = (CrosstabElement) report.getReportHeader().getElement( 0 );
  NoDataBand noDataBand0 = ct0.getNoDataBand();
  MasterReport derive = (MasterReport) report.derive();
  CrosstabElement ct1 = (CrosstabElement) derive.getReportHeader().getElement( 0 );
  NoDataBand noDataBand1 = ct1.getNoDataBand();
  Assert.assertNotSame( noDataBand0, noDataBand1 );
}
 
Example 4
Source File: DebugReportRunner.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static LogicalPageBox layoutSingleBand( final MasterReport originalReport, final Band reportHeader,
    final FontStorage fontRegistry, final boolean expectPageBreak, final boolean designTime )
  throws ReportProcessingException, ContentProcessingException {
  final ReportStateKey stateKey = new ReportStateKey();

  final DebugOutputProcessorMetaData metaData = new DebugOutputProcessorMetaData( fontRegistry );
  metaData.setDesignTime( designTime );

  final MasterReport report = originalReport.derive( true );
  resolveStyle( report );
  resolveStyle( reportHeader );

  metaData.initialize( wrapForCompatibility( report ) );

  final ProcessingContext processingContext = new DefaultProcessingContext( report, metaData );
  final DebugExpressionRuntime runtime = new DebugExpressionRuntime( new DefaultTableModel(), 0, processingContext );

  final DebugRenderer debugLayoutSystem = new DebugRenderer( metaData );
  debugLayoutSystem.setStateKey( stateKey );
  debugLayoutSystem.startReport( report, processingContext, new DefaultPerformanceMonitorContext() );
  debugLayoutSystem.startSection( Renderer.SectionType.NORMALFLOW );
  debugLayoutSystem.add( reportHeader, runtime );
  debugLayoutSystem.endSection();
  if ( expectPageBreak ) {
    debugLayoutSystem.endReport();
    final Renderer.LayoutResult result = debugLayoutSystem.validatePages();
    Assert.assertEquals( Renderer.LayoutResult.LAYOUT_PAGEBREAK, result );
  } else {
    debugLayoutSystem.validatePages();
  }
  return debugLayoutSystem.getPageBox();
}
 
Example 5
Source File: AbstractReportProcessor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected AbstractReportProcessor( final MasterReport report, final OutputProcessor outputProcessor )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException( "Report cannot be null." );
  }

  if ( outputProcessor == null ) {
    throw new NullPointerException( "OutputProcessor cannot be null" );
  }

  // first cloning ... protect the page layouter function ...
  // and any changes we may do to the report instance.

  // a second cloning is done in the start state, to protect the
  // processed data.
  this.fullStreamingProcessor = true;
  this.handleInterruptedState = true;
  this.outputProcessor = outputProcessor;

  final Configuration configuration = report.getReportConfiguration();
  this.paranoidChecks =
      "true".equals( configuration
          .getConfigProperty( "org.pentaho.reporting.engine.classic.core.layout.ParanoidChecks" ) );
  final String yieldRateText =
      configuration.getConfigProperty( "org.pentaho.reporting.engine.classic.core.YieldRate" );
  final int yieldRate = ParserUtil.parseInt( yieldRateText, 0 );
  if ( yieldRate > 0 ) {
    addReportProgressListener( new YieldReportListener( yieldRate ) );
  }
  final String profile =
      configuration.getConfigProperty( "org.pentaho.reporting.engine.classic.core.ProfileReportProcessing" );
  if ( "true".equals( profile ) ) {
    final boolean logLevelProgress =
        "true".equals( configuration
            .getConfigProperty( "org.pentaho.reporting.engine.classic.core.performance.LogLevelProgress" ) );
    final boolean logPageProgress =
        "true".equals( configuration
            .getConfigProperty( "org.pentaho.reporting.engine.classic.core.performance.LogPageProgress" ) );
    final boolean logRowProgress =
        "true".equals( configuration
            .getConfigProperty( "org.pentaho.reporting.engine.classic.core.performance.LogRowProgress" ) );
    addReportProgressListener( new PerformanceProgressLogger( logLevelProgress, logPageProgress, logRowProgress ) );
  }

  final boolean designtime = outputProcessor.getMetaData().isFeatureSupported( OutputProcessorFeature.DESIGNTIME );
  this.report = report.derive( designtime );
  ReportProcessorThreadHolder.setProcessor( this );
}
 
Example 6
Source File: PasteAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Object normalizeElements( final Object element ) {
  if ( element instanceof MasterReport ) {
    final MasterReport rawMasterReport = (MasterReport) element;
    final MasterReport masterReport = (MasterReport) rawMasterReport.derive();

    final int result = JOptionPane.showOptionDialog( getReportDesignerContext().getView().getParent(),
      Messages.getString( "SubreportReportElementDragHandler.BandedOrInlineSubreportQuestion" ),
      Messages.getString( "SubreportReportElementDragHandler.InsertSubreport" ),
      JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null,
      new String[] { Messages.getString( "SubreportReportElementDragHandler.Inline" ),
        Messages.getString( "SubreportReportElementDragHandler.Banded" ),
        Messages.getString( "SubreportReportElementDragHandler.Cancel" ) },
      Messages.getString( "SubreportReportElementDragHandler.Inline" )
    );
    if ( result == JOptionPane.CLOSED_OPTION || result == 2 ) {
      return null;
    }

    final SubReport subReport = new SubReport();
    subReport.setRootGroup( (Group) masterReport.getRootGroup().derive() );
    subReport.setReportFooter( (ReportFooter) masterReport.getReportFooter().derive() );
    subReport.setReportHeader( (ReportHeader) masterReport.getReportHeader().derive() );
    subReport.setPageFooter( (PageFooter) masterReport.getPageFooter().derive() );
    subReport.setPageHeader( (PageHeader) masterReport.getPageHeader().derive() );
    subReport.setWatermark( (Watermark) masterReport.getWatermark().derive() );
    subReport.setDataFactory( masterReport.getDataFactory().derive() );
    masterReport.copyInto( subReport );

    final ReportParameterDefinition parameterDefinition = masterReport.getParameterDefinition();
    for ( final ParameterDefinitionEntry entry : parameterDefinition.getParameterDefinitions() ) {
      subReport.addInputParameter( entry.getName(), entry.getName() );
    }
    if ( subReport.getInputMappings().length == 0 ) {
      subReport.addInputParameter( "*", "*" );
    }

    subReport.setElementType( SubReportType.INSTANCE );
    if ( result == 0 ) {
      // inline
      subReport.setAttribute
        ( ReportDesignerBoot.DESIGNER_NAMESPACE, InsertationUtil.SUBREPORT_BANDED_HINT, Boolean.FALSE );
    } else if ( result == 1 ) {
      // banded
      subReport.setAttribute
        ( ReportDesignerBoot.DESIGNER_NAMESPACE, InsertationUtil.SUBREPORT_BANDED_HINT, Boolean.TRUE );
    }
    return subReport;
  }

  return element;
}