October 27, 2016
Hot Topics:

Developing an Eclipse BIRT XML Report Rendering Extension

  • March 6, 2008
  • By Jason Weathersby, Iana Chatalbasheva, and Tom Bondur
  • Send Email »
  • More Articles »

Defining the dependencies for the XML report rendering extension

To compile and run the XML report rendering example, you specify the org.eclipse.birt.report.engine plug-in, which must be available on the classpath for the XML rendering extension.

Declaring the emitters extension point

To implement the XML report rendering extension, specify the org.eclipse.birt.report.engine.emitters extension point and add the extension element details.

How to specify the extension point
  1. On PDE Manifest Editor, choose Extensions.
  2. In All Extensions, choose Add. New Extension—Extension Point Selection appears.
  3. In Available extension points, select the following plug-in:
  4. org.eclipse.birt.report.engine.emitters
  5. Choose Finish.
  6. In All Extensions, right-click the extension point, org.eclipse.birt.report.engine.emitters, and choose the extension element, emitter.
  7. In Extension Element Details, specify the properties for the emitter extension element, emitter, as shown in Table 3.
  8. Table 3: Property values for the emitter extension element

    Property Value
    class org.eclipse.birt.report.engine.emitter.xml. XMLReportEmitter
    format xml
    mimeType xml
    id org.eclipse.birt.report.engine.emitter.xml

Understanding the sample XML report rendering extension

The XML report rendering extension extends the report emitter interfaces and XML writer in org.eclipse.birt.report.engine.emitter. The extension example creates the XML output file in the same folder as the exported report. The output file name is the name of the report with an .XML extension. The extension example provides only limited error checking.

The following section provides a general description of the code-based extensions a developer must make to develop an XML report rendering extension after defining the plug-in framework in the Eclipse PDE.

Understanding the XML report rendering extension package

The implementation package for the XML report rendering extension example, org.eclipse.birt.report.engine.emitter.xml, contains the following classes:

  • XMLPlugin: The plug-in run-time class for the report item extension example.
  • XMLReportEmitter: Handles the start and end processing that renders the report container.
  • XMLRenderOption: Integrates the plug-in with BIRT Report Engine, specifying configuration information, including the output format as XML.
  • XMLTags.java: Defines the controls and associated property lists used when writing to the XML file.
  • XMLFileWriter: XMLWriter writes the XML version, text, image, data, label, and report tag content of the report to the XML output file.
  • LoadExportSchema: Loads the XML Schema file, if one exists, to replace the default values specified for the XML version, text, image, data, label, and report tags. An accessor method for each tag returns the value to XMLReportEmitter for output to the export file.

The following section contains more specific information about the implementation details for the classes in the XML report rendering extension package.

Understanding XMLReportEmitter

XMLReportEmitter writes the contents of the report to an XML file. XMLReportEmitter instantiates the writer and emitter objects and handles the start and end processing that renders the report container. XMLReportEmitter exports the XML version, text, image, data, label, and report tag content of the report to the XML output file.

XMLReportEmitter implements the following methods:

  • XMLReportEmitter( ) instantiates the XML report emitter class as an org.eclipse.birt.report.engine.presentation. ContentEmitterVisitor object to perform emitter operations.
  • initialize( ) performs the following operations required to create an output stream that writes the report contents to the XML file:
    • Obtains a reference to the IEmitterServices interface
    • Instantiates the file and output stream objects, using the specified settings
    • Instantiates the XML writer object
  • start( ) performs the following operations:
    • Obtains a reference to the IReportContent interface, containing accessor methods that get the interfaces to the report content emitters
    • Sets the start emitter logging level and writes to the log file
    • If an optional XML Schema file exists:
      • Locates the XML Schema file for the report
      • Instantiates a LoadExportSchema object to read the XML Schema file
    • Opens the output file, specifying the encoding scheme as UTF-8
    • Starts the XML writer
    • Writes the start tag, which specifies the <xml> tag, including the version and encoding schema, to the output file
    • Writes the <report> tag, which specifies the report name and other properties in the report property list to the output file

    Listing 1 shows the start( ) method.

    Listing 1: The start( ) method

    public void start( IReportContent report )
       logger.log( Level.FINE,
          "[XMLReportEmitter] Start emitter." );
       String fileName =
          report.getDesign( ).getReportDesign( )
          .getFileName( );
       int pos = fileName.indexOf("/");
       String fn =
          fileName.substring(pos+1,fileName.length( ));
       fileName = fn;
       if (fileName.length( ) > 0) {
          pos =  fileName.lastIndexOf(".");
       if ( pos > 0 )
          fileName = fileName.substring(0, pos);
          fileName = fileName + ".xmlemitter";
          pos = fileName.lastIndexOf("/");
          String propFileName =
             fileName.substring( pos+1 ,
                fileName.length( ) );
          String resourceFolder =
             report.getDesign().getReportDesign( )
                .getResourceFolder( );
          if ( fileExists(resourceFolder + "/"
                + propFileName))
             exportSchema = new LoadExportSchema(
                resourceFolder + "/" + propFileName );
             if ( fileExists(fileName))
             exportSchema =
                new LoadExportSchema( fileName );
          else exportSchema =
             new LoadExportSchema( "" );
       this.report = report;
       writer.open( out, "UTF-8" );
       writer.startWriter( );
       writer.closeTag( exportSchema.getExportStartTag( ));
       writer.closeTag( XMLTags.TAG_CR );
       String rp = exportSchema.getExportReportTag( );
       for (int i = 0;i < XMLTags.rPropList.length;i++)
          if (exportSchema.isPropertyRequired(
             XMLTags.rPropList[i], rp))
             String propValue = getReportPropValue(i,report);
             rp = replaceTag( rp, "??"
                +XMLTags.rPropList[i], propValue );
       writer.writeCode( rp );
       writer.closeTag( XMLTags.TAG_CR );

    end( ) performs the following operations, similar to the CSV rendering extension:

    • Sets the end report logging level and writes to the log file
    • Ends the write process and closes the XML writer
    • Closes the output file

Page 2 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel