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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getReportConfiguration() . 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: ReportConverter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Writes a report in the new XML format.
 *
 * @param report
 *          the report.
 * @param w
 *          a character stream writer.
 * @param contentBase
 *          the content base for creating relative URLs.
 * @param encoding
 *          the encoding of the generated file.
 * @throws IOException
 *           if there is an I/O problem.
 * @throws ReportWriterException
 *           if there were problems while serializing the report definition.
 */
public void write( final MasterReport report, final Writer w, final URL contentBase, final String encoding )
  throws IOException, ReportWriterException {
  if ( contentBase == null ) {
    throw new NullPointerException( "ContentBase is null" );
  }
  final ModifiableConfiguration config = new HierarchicalConfiguration( report.getReportConfiguration() );
  config.setConfigProperty( AbstractXmlResourceFactory.CONTENTBASE_KEY, contentBase.toExternalForm() );

  final ReportWriter writer = new ReportWriter( report, encoding, config );
  writer.addClassFactoryFactory( new URLClassFactory() );
  writer.addClassFactoryFactory( new DefaultClassFactory() );
  writer.addClassFactoryFactory( new BandLayoutClassFactory() );
  writer.addClassFactoryFactory( new ArrayClassFactory() );
  writer.addClassFactoryFactory( new ExtraShapesClassFactory() );

  writer.addStyleKeyFactory( new DefaultStyleKeyFactory() );
  writer.addStyleKeyFactory( new PageableLayoutStyleKeyFactory() );
  writer.addTemplateCollection( new DefaultTemplateCollection() );
  writer.addElementFactory( new DefaultElementFactory() );
  writer.addDataSourceFactory( new DefaultDataSourceFactory() );
  writer.write( w );
}
 
Example 2
Source File: PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void printDirectly( final MasterReport report, final ReportProgressListener progressListener )
  throws PrinterException, ReportProcessingException {
  final ModifiableConfiguration reportConfiguration = report.getReportConfiguration();
  final String jobName = reportConfiguration.getConfigProperty( PRINTER_JOB_NAME_KEY, report.getTitle() );

  final PrinterJob printerJob = PrinterJob.getPrinterJob();
  if ( jobName != null ) {
    printerJob.setJobName( jobName );
  }

  final PrintReportProcessor reportPane = new PrintReportProcessor( report );
  if ( progressListener != null ) {
    reportPane.addReportProgressListener( progressListener );
  }
  printerJob.setPageable( reportPane );
  try {
    printerJob.setCopies( getNumberOfCopies( reportConfiguration ) );
    printerJob.print();
  } finally {
    reportPane.close();
    if ( progressListener != null ) {
      reportPane.removeReportProgressListener( progressListener );
    }
  }
}
 
Example 3
Source File: ReportWriterIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ReportWriter createWriter() {
  final MasterReport report = new MasterReport();
  final ModifiableConfiguration repConf = new HierarchicalConfiguration( report.getReportConfiguration() );
  repConf.setConfigProperty( AbstractXmlResourceFactory.CONTENTBASE_KEY, "file://tmp/" );

  final ReportWriter writer = new ReportWriter( report, "UTF-16", repConf );
  writer.addClassFactoryFactory( new URLClassFactory() );
  writer.addClassFactoryFactory( new DefaultClassFactory() );
  writer.addClassFactoryFactory( new BandLayoutClassFactory() );
  writer.addClassFactoryFactory( new ArrayClassFactory() );

  writer.addStyleKeyFactory( new DefaultStyleKeyFactory() );
  writer.addStyleKeyFactory( new PageableLayoutStyleKeyFactory() );
  writer.addTemplateCollection( new DefaultTemplateCollection() );
  writer.addElementFactory( new DefaultElementFactory() );
  writer.addDataSourceFactory( new DefaultDataSourceFactory() );
  return writer;
}
 
Example 4
Source File: SettingsFileWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void writeConfiguration( final BundleWriterState state, final XmlWriter writer ) throws IOException {
  if ( state == null ) {
    throw new NullPointerException();
  }
  if ( writer == null ) {
    throw new NullPointerException();
  }

  final MasterReport report = state.getMasterReport();
  final ModifiableConfiguration rawConfig = report.getReportConfiguration();
  if ( rawConfig instanceof HierarchicalConfiguration ) {
    writer.writeTag( BundleNamespaces.SETTINGS, "configuration", XmlWriterSupport.OPEN );
    final HierarchicalConfiguration configuration = (HierarchicalConfiguration) rawConfig;
    final Enumeration keys = configuration.getConfigProperties();
    while ( keys.hasMoreElements() ) {
      final String key = (String) keys.nextElement();
      final String value = configuration.getConfigProperty( key );
      if ( value != null && configuration.isLocallyDefined( key ) ) {
        writer.writeTag( BundleNamespaces.SETTINGS, "property", "name", key, XmlWriterSupport.OPEN );
        writer.writeTextNormalized( value, true );
        writer.writeCloseTag();
      }
    }

    writer.writeCloseTag();
  }
}
 
Example 5
Source File: ReportWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Builds a default configuration from a given report definition object.
 * <p/>
 * This will only create a valid definition, if the report has a valid content base object set.
 *
 * @param report
 *          the report for which to create the writer configuration.
 * @return the generated configuration.
 */
public static Configuration createDefaultConfiguration( final MasterReport report ) {
  final ModifiableConfiguration repConf = new HierarchicalConfiguration( report.getReportConfiguration() );
  final ResourceKey contentBase = report.getContentBase();
  if ( contentBase != null ) {
    final ResourceManager resourceManager = report.getResourceManager();
    final URL value = resourceManager.toURL( contentBase );
    if ( value != null ) {
      repConf.setConfigProperty( AbstractXmlResourceFactory.CONTENTBASE_KEY, value.toExternalForm() );
    }
  }

  return repConf;
}
 
Example 6
Source File: ReportConfigReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the handler for a child element.
 *
 * @param tagName
 *          the tag name.
 * @param atts
 *          the attributes.
 * @return the handler or null, if the tagname is invalid.
 * @throws org.xml.sax.SAXException
 *           if there is a parsing error.
 */
protected XmlReadHandler getHandlerForChild( final String uri, final String tagName, final PropertyAttributes atts )
  throws SAXException {
  final DataFactoryReadHandlerFactory factory = DataFactoryReadHandlerFactory.getInstance();
  final DataFactoryReadHandler handler = (DataFactoryReadHandler) factory.getHandler( uri, tagName );
  if ( handler != null ) {
    dataFactoryReadHandler = handler;
    return handler;
  }

  if ( isSameNamespace( uri ) == false ) {
    return null;
  }

  final AbstractReportDefinition report =
      (AbstractReportDefinition) getRootHandler().getHelperObject( ReportParserUtil.HELPER_OBJ_REPORT_NAME );
  if ( report instanceof MasterReport ) {
    final MasterReport masterReport = (MasterReport) report;
    if ( "page-definition".equals( tagName ) ) {
      return new PageDefinitionReadHandler();
    } else if ( "simple-page-definition".equals( tagName ) ) {
      return new SimplePageDefinitionReadHandler();
    } else if ( "configuration".equals( tagName ) ) {
      return new ConfigurationReadHandler( masterReport.getReportConfiguration() );
    }
  }

  return null;
}
 
Example 7
Source File: PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean print( final MasterReport report, final ReportProgressListener progressListener )
  throws PrinterException, ReportProcessingException {
  final ModifiableConfiguration reportConfiguration = report.getReportConfiguration();
  final String jobName = reportConfiguration.getConfigProperty( PRINTER_JOB_NAME_KEY, report.getTitle() );

  final PrinterJob printerJob = PrinterJob.getPrinterJob();
  if ( jobName != null ) {
    printerJob.setJobName( jobName );
  }

  final PrintReportProcessor reportPane = new PrintReportProcessor( report );
  if ( progressListener != null ) {
    reportPane.addReportProgressListener( progressListener );
  }

  try {
    reportPane.fireProcessingStarted();
    printerJob.setPageable( reportPane );
    printerJob.setCopies( getNumberOfCopies( reportConfiguration ) );
    if ( printerJob.printDialog() ) {
      printerJob.print();
      return true;
    }
    return false;
  } finally {
    reportPane.fireProcessingFinished();
    reportPane.close();
    if ( progressListener != null ) {
      reportPane.removeReportProgressListener( progressListener );
    }
  }
}
 
Example 8
Source File: GoldTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected MasterReport tuneForTesting( final MasterReport report ) throws Exception {
  final ModifiableConfiguration configuration = report.getReportConfiguration();
  configuration.setConfigProperty( DefaultReportEnvironment.ENVIRONMENT_KEY + "::internal::report.date",
      "2011-04-07T15:00:00.000+0000" );
  configuration.setConfigProperty( DefaultReportEnvironment.ENVIRONMENT_TYPE + "::internal::report.date",
      "java.util.Date" );
  return report;
}
 
Example 9
Source File: AbstractExportDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Opens the dialog to query all necessary input from the user. This will not start the processing, as this is done
 * elsewhere.
 *
 * @param reportJob
 *          the report that should be processed.
 * @return true, if the processing should continue, false otherwise.
 */
public boolean performQueryForExport( final MasterReport reportJob, final SwingGuiContext guiContext ) {
  if ( reportJob == null ) {
    throw new NullPointerException();
  }
  if ( guiContext == null ) {
    throw new NullPointerException();
  }

  this.reportJob = reportJob;
  this.guiContext = guiContext;

  final Locale locale = guiContext.getLocale();
  setLocale( locale );
  pack();
  clear();
  initializeFromJob( reportJob, guiContext );
  createParametersPanelContent();

  final FormValidator formValidator = getFormValidator();
  formValidator.setEnabled( false );
  final ModifiableConfiguration repConf = reportJob.getReportConfiguration();
  final boolean inputStorageEnabled = isInputStorageEnabled( repConf );

  final Configuration loadedConfiguration;
  if ( inputStorageEnabled ) {
    loadedConfiguration = loadFromConfigStore( reportJob, repConf );
  } else {
    loadedConfiguration = repConf;
  }

  setDialogContents( loadedConfiguration );

  formValidator.setEnabled( true );
  formValidator.handleValidate();
  setModal( true );
  LibSwingUtil.centerDialogInParent( this );
  setVisible( true );
  if ( isConfirmed() == false ) {
    this.guiContext = defaultContext;
    return false;
  }

  formValidator.setEnabled( false );

  final Configuration fullDialogContents = grabDialogContents( true );
  final Enumeration configProperties = fullDialogContents.getConfigProperties();
  while ( configProperties.hasMoreElements() ) {
    final String key = (String) configProperties.nextElement();
    repConf.setConfigProperty( key, fullDialogContents.getConfigProperty( key ) );
  }

  if ( inputStorageEnabled ) {
    saveToConfigStore( reportJob, repConf );
  }

  formValidator.setEnabled( true );
  this.reportJob = null;
  this.guiContext = defaultContext;
  return true;
}
 
Example 10
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 );
}