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
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, data, image, label, report tags, and text. 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.
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, data, image, label, report tag content, and text 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, similar to the CSV report rendering extension:
Obtains a reference to the IEmitterServices interface
Instantiates the file and output stream objects, using the specified settings
Instantiates the XML file 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, start( )
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
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
Understanding the other XMLReportEmitter methods
The XMLReportEmitter class defines the following additional methods, called at different phases of the report generation process, that provide access to the report container, pages, tables, rows, cells text, labels, data, images, hyperlinks, and other contents. The following examples show the processing for a label:
startLabel( ) performs the following operations:
Calls LoadExportSchema.getExportLabelTag( ) to get the pattern for the <label> tag specified in the <report_name>.xmlemitter property file. If the property file does not exist, the plug-in uses the following default pattern specified in the LoadExportSchema class:
<label>??value</label>
Iterates through the following label properties list defined in XMLTags to determine the properties required by the report:
The XMLFileWriter class writes the closing tag similar to the CSVWriter class in the CSV report rendering extension.
XMLRenderOption class
The org.eclipse.birt.report.engine.emitter.xml.XMLRenderOption class adds the XML rendering option to the BIRT report engine run time, as shown in Listing 24‑21.
The org.eclipse.birt.report.engine.emitter.xml.LoadExportSchema class optionally loads an XML schema by performing the following operations:
Specifies the default substitution patterns for the XML tags
Calls the readSchemaFile( ) method
Specifies an accessor method for each tag that returns a value to XMLReportEmitter for output to the export file
Listing 24‑22 shows the specification of the default substitution patterns for the XML tags and the constructor, which calls the readSchemaFile( ) method.
The readSchemaFile( ) method reads the XML schema file, one line at a time, replacing the default values for the patterns of the XML version, data, image, label, report tags, and text with the values specified in the XML schema file.
Listing 24‑23 shows the code for the readSchemaFile( ) method.
Listing 24‑23 The readSchemaFile( ) method
private void readSchemaFile( )
{
BufferedReader input = null;
try {
input = new BufferedReader( new FileReader( fileName ) );
String line = null; //not declared within while loop
if ( index.equalsIgnoreCase( XMLTags.labelControl ) )
{
labelTag = indexTag;
}
if ( index.equalsIgnoreCase( XMLTags.imageControl ) )
{
imageTag = indexTag;
}
if ( index.equalsIgnoreCase( XMLTags.dataControl ) )
{
dataTag = indexTag;
}
if ( index.equalsIgnoreCase( XMLTags.startControl ) )
{
startTag = indexTag;
}
if ( index.equalsIgnoreCase( XMLTags.endControl ) )
{
endTag = indexTag;
}
if ( index.equalsIgnoreCase( XMLTags.reportControl ) )
{
reportTag = indexTag;
}
}
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace( );
}
catch (IOException ex) {
ex.printStackTrace( );
}
finally {
try {
if (input!= null)
{
input.close( );
}
}
catch (IOException ex) {
ex.printStackTrace( );
}
}
}
Listing 24‑24 shows the values of the patterns for the XML version, data tags, image, label, report, and text specified in the XML schema file, xmlReport.xmlemitter.