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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getBundle() . 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 ) throws IOException,
  BundleWriterException {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( report == null ) {
    throw new NullPointerException();
  }

  if ( bundle == report.getBundle() ) {
    throw new IllegalArgumentException( "Cannot write to the originating bundle." );
  }

  final DocumentBundle reportBundle = report.getBundle();
  if ( reportBundle == null ) {
    this.writeReport( bundle, report, new MemoryDocumentBundle() );
  } else {
    this.writeReport( bundle, report, reportBundle );
  }

}
 
Example 2
Source File: AbstractReportProcessor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected DefaultProcessingContext createProcessingContext() throws ReportProcessingException {
  final OutputProcessorMetaData metaData = getOutputProcessorMetaData();
  final MasterReport report = getReport();
  final DocumentMetaData documentMetaData;
  final DocumentBundle bundle = report.getBundle();
  if ( bundle != null ) {
    documentMetaData = bundle.getMetaData();
  } else {
    documentMetaData = new MemoryDocumentMetaData();
  }
  final Integer compatibilityLevel = report.getCompatibilityLevel();
  final int cLevel;
  if ( compatibilityLevel == null ) {
    cLevel = -1;
  } else {
    cLevel = compatibilityLevel;
  }
  return new DefaultProcessingContext( metaData, report.getResourceBundleFactory(), report.getConfiguration(), report
      .getResourceManager(), report.getContentBase(), documentMetaData, report.getReportEnvironment(), cLevel );
}
 
Example 3
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 4
Source File: EditReportPropertiesAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void undo( final ReportDocumentContext renderContext ) {
  final MasterReport report = renderContext.getContextRoot();
  final WriteableDocumentBundle bundle = (WriteableDocumentBundle) report.getBundle();
  final WriteableDocumentMetaData metaData = bundle.getWriteableDocumentMetaData();
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS,
      oldMetaData.getBundleAttribute( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.CREATOR,
      oldMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.CREATOR ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.DESCRIPTION,
      oldMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.DESCRIPTION ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.SUBJECT,
      oldMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.SUBJECT ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE,
      oldMetaData
        .getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE ) );
  report.notifyNodePropertiesChanged();
}
 
Example 5
Source File: EditReportPropertiesAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void redo( final ReportDocumentContext renderContext ) {
  final MasterReport report = renderContext.getContextRoot();
  final WriteableDocumentBundle bundle = (WriteableDocumentBundle) report.getBundle();
  final WriteableDocumentMetaData metaData = bundle.getWriteableDocumentMetaData();
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS,
      newMetaData.getBundleAttribute( ODFMetaAttributeNames.Meta.NAMESPACE, ODFMetaAttributeNames.Meta.KEYWORDS ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.CREATOR,
      newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.CREATOR ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.DESCRIPTION,
      newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.DESCRIPTION ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.SUBJECT,
      newMetaData.getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE,
        ODFMetaAttributeNames.DublinCore.SUBJECT ) );
  metaData.setBundleAttribute
    ( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE,
      newMetaData
        .getBundleAttribute( ODFMetaAttributeNames.DublinCore.NAMESPACE, ODFMetaAttributeNames.DublinCore.TITLE ) );
  report.notifyNodePropertiesChanged();
}
 
Example 6
Source File: Prd4542Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final Object selectedFile, final ResourceManager resourceManager )
  throws ResourceException, IOException {
  final Resource directly = resourceManager.createDirectly( selectedFile, 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() );
  }

  final Object visible =
    resource.getBundle().getMetaData().getBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "visible" );//NON-NLS
  if ( "true".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.TRUE );//NON-NLS
  } else if ( "false".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.FALSE );//NON-NLS
  }
  return resource;
}
 
Example 7
Source File: DefaultParameterContext.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public DefaultParameterContext( final MasterReport report, final ReportParameterValues parameterValues )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException( "Report parameter must not be null" );
  }
  if ( parameterValues == null ) {
    throw new NullPointerException( "ParameterValues parameter must not be null" );
  }
  this.configuration = report.getConfiguration();
  this.resourceBundleFactory =
      MasterReport.computeAndInitResourceBundleFactory( report.getResourceBundleFactory(), report
          .getReportEnvironment() );
  this.contentBase = report.getContentBase();
  this.resourceManager = report.getResourceManager();
  this.reportEnvironment = report.getReportEnvironment();
  final Object dataCacheEnabledRaw =
      report.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.DATA_CACHE );
  final boolean dataCacheEnabled = Boolean.FALSE.equals( dataCacheEnabledRaw ) == false;
  this.dataFactory = new CachingDataFactory( report.getDataFactory(), dataCacheEnabled );

  final DocumentBundle bundle = report.getBundle();
  if ( bundle != null ) {
    this.documentMetaData = bundle.getMetaData();
  }
  this.dataFactory.initialize( new DesignTimeDataFactoryContext( configuration, resourceManager, contentBase,
      resourceBundleFactory, dataFactory ) );

  final ReportEnvironmentDataRow envDataRow = new ReportEnvironmentDataRow( reportEnvironment );
  this.parameterValues = new CompoundDataRow( envDataRow, parameterValues );

}
 
Example 8
Source File: OpenReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final Object selectedFile, final ResourceManager resourceManager )
  throws ResourceException, IOException {
  final Resource directly = resourceManager.createDirectly( selectedFile, 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() );
  }

  final Object visible =
    resource.getBundle().getMetaData().getBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "visible" );//NON-NLS
  if ( "true".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.TRUE );//NON-NLS
  } else if ( "false".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.FALSE );//NON-NLS
  }
  return resource;
}
 
Example 9
Source File: EditReportPropertiesAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
public void actionPerformed( final ActionEvent e ) {
  final ReportDocumentContext activeContext = getActiveContext();
  if ( activeContext == null ) {
    return;
  }
  final ReportDesignerContext context = getReportDesignerContext();
  final Component parent = context.getView().getParent();
  final Window window = LibSwingUtil.getWindowAncestor( parent );
  final DocumentMetaDataDialog dialog;
  if ( window instanceof JDialog ) {
    dialog = new DocumentMetaDataDialog( (JDialog) window );
  } else if ( window instanceof JFrame ) {
    dialog = new DocumentMetaDataDialog( (JFrame) window );
  } else {
    dialog = new DocumentMetaDataDialog();
  }

  try {
    final MasterReport report = activeContext.getContextRoot();
    final DocumentBundle bundle = report.getBundle();
    final DocumentMetaData oldMetaData = (DocumentMetaData) bundle.getMetaData().clone();
    final DocumentMetaData result = dialog.performEdit( oldMetaData,
      report.getResourceManager(),
      report.getDefinitionSource() );

    if ( result == null ) {
      return;
    }

    final MetaDataEditUndoEntry undoEntry = new MetaDataEditUndoEntry( oldMetaData, result );
    undoEntry.redo( activeContext );
    activeContext.getUndo().addChange( ActionMessages.getString( "EditReportPropertiesAction.Text" ), undoEntry );
  } catch ( CloneNotSupportedException cne ) {
    // should not happen
    UncaughtExceptionsModel.getInstance().addException( cne );
  }
}
 
Example 10
Source File: NewWizardReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void actionPerformed( final ActionEvent e ) {
  final ReportDesignerContext designerContext = getReportDesignerContext();
  if ( designerContext == null ) {
    return;
  }
  final Component parent = designerContext.getView().getParent();
  final Window window = getWindowAncestor( parent );
  final EmbeddedWizard dialog = getEmbeddedWizard( window );

  try {
    final MasterReport def = runDialog( dialog );
    if ( def == null ) {
      return;
    }

    try {
      final MemoryDocumentBundle bundle = (MemoryDocumentBundle) def.getBundle();
      if ( bundle.isEntryExists( TRANSLATIONS_PROPERTIES ) == false ) {
        final String defaultMessage = ActionMessages.getString( "Translations.DefaultContent" );
        final OutputStream outputStream = bundle.createEntry( TRANSLATIONS_PROPERTIES, "text/plain" );
        outputStream.write( defaultMessage.getBytes( "ISO-8859-1" ) );
        outputStream.close();
        bundle.getWriteableDocumentMetaData().setEntryAttribute( TRANSLATIONS_PROPERTIES,
            BundleUtilities.STICKY_FLAG, "true" );
      }
    } catch ( Exception ex ) {
      // ignore, its not that important ..
      DebugLog.log( "Failed to created default translation entry", ex );
    }

    designerContext.addMasterReport( def );
  } catch ( ReportProcessingException e1 ) {
    UncaughtExceptionsModel.getInstance().addException( e1 );
  }
}
 
Example 11
Source File: NewReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static MasterReport prepareMasterReport() {
  final MasterReport report = new MasterReport();
  report.setAutoSort( Boolean.TRUE );
  report.setDataFactory( new CompoundDataFactory() );
  report.setQuery( null );
  report.setQueryLimitInheritance( Boolean.TRUE );
  report.getRelationalGroup( 0 ).getHeader()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getRelationalGroup( 0 ).getFooter()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getDetailsFooter()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getDetailsHeader()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getNoDataBand()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getWatermark()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );

  try {
    final MemoryDocumentBundle bundle = (MemoryDocumentBundle) report.getBundle();
    if ( bundle.isEntryExists( TRANSLATIONS_PROPERTIES ) == false ) {
      final String defaultMessage = ActionMessages.getString( "Translations.DefaultContent" );
      final OutputStream outputStream = bundle.createEntry( TRANSLATIONS_PROPERTIES, "text/plain" ); // NON-NLS
      outputStream.write( defaultMessage.getBytes( "ISO-8859-1" ) ); // NON-NLS
      outputStream.close();
      bundle.getWriteableDocumentMetaData()
        .setEntryAttribute( TRANSLATIONS_PROPERTIES, BundleUtilities.STICKY_FLAG, "true" ); // NON-NLS
    }
  } catch ( Exception ex ) {
    // ignore, its not that important ..
    DebugLog.log( "Failed to created default translation entry", ex ); // NON-NLS
  }
  return report;
}