Chapter 21. Developing a Data Extraction Extension

This chapter describes how to develop a report data extraction extension using the Eclipse PDE. The data extraction example exports report data to XML format. The Eclipse PDE provides the basis for the extension.

Understanding a data extraction extension

BIRT Report Engine provides a data extraction extension point that supports developing a new plug-in for exporting report data to a custom format. The BIRT user interface also provides a built-in data extraction feature that can export data from a report document in CSV format. This functionality is available in the BIRT Web Viewer. The Data Export feature is available in the BIRT Web Viewer toolbar, as shown in Figure 21-1.

Figure 21-1 BIRT Web Viewer toolbar

image

The user can select the data columns for the export, the export format, the data encoding, and other properties using Export Data, as shown in Figure 21-2.

Figure 21-2 Export Data menu

image

A data extraction extension adds a plug-in to the BIRT Report Engine framework by implementing the extension point, org.eclipse.birt.report.engine.dataExtraction. The XML schema file, org.eclipse.birt.report.engine/schema/dataExtraction.exsd, describes this extension point.

The data extraction extension point enables support for new output formats in the presentation engine. The BIRT plug-in registry uses this extension point to discover all supported output formats specified for the report engine environment. The Export Data menu lists the available formats in the Export format list.

The XML data extraction extension in this chapter provides an example of how to create a data extraction extension.

You can download the source code for the XML data extraction extension example at http://www.actuate.com/birt/contributions. For reference documentation, see the BIRT Report Engine API Javadoc in Eclipse Help for the org.eclipse.birt.report.engine.dataextraction and org.eclipse.birt.report.engine.content packages.

Developing an XML data extraction extension

The sample XML data extraction extension is a plug-in that can export BIRT report data in XML format. Typically, report developers render BIRT report data to XML to enable sharing data with another application. The XML data extraction extension extends the functionality defined by the org.eclipse.birt.report.engine.dataExtraction package, which is part of the org.eclipse.birt.report.engine.dataextraction plug-in. In the course of developing the XML data extraction extension, you perform the following tasks:

• Create an XML data extraction extension project in the Eclipse PDE

• Define the dependencies

• Declare the plug-in extension point

• Implement the plug-in interfaces

• Test the extension

Creating an XML data extraction plug-in project

Create a new plug-in project for the XML data extraction extension using the Eclipse PDE.

How to create the XML data extraction plug-in project

1 From the Eclipse PDE menu, choose File→New→Project. New Project appears.

2 In New Project, select Plug-in Project. Choose Next. New Plug-in Project appears.

3 In Plug-in Project, modify the settings, as shown in Table 21-1.

Table 21-1 Settings for the XML Data Extraction Plug-in Project

image

Plug-in Project appears as shown in Figure 21-3. Choose Next. Plug-in Content appears.

Figure 21-3 Specifying Plug-in Project settings

image

4 In Plug-in Content, modify the settings, as shown in Table 21-2.

Table 21-2 Settings for the XML Data Extraction Plug-in Content

image

Plug-in Content appears as shown in Figure 21-4. Choose Finish.

Figure 21-4 Specifying Plug-in Content settings

image

The XML data extraction extension project appears in the Eclipse PDE workbench, as shown in Figure 21-5.

Figure 21-5 CSV report rendering extension project

image

Defining the dependencies for the XML data extraction extension

To compile and run the XML data extraction example, specify the list of plug-ins that must be available on the classpath of the extension.

How to specify the dependencies

1 On PDE Manifest Editor, choose Overview.

2 In Plug-in Content, choose Dependencies.

3 In Plug-in Dependences, choose Add. Plug-in Selection appears.

1 In Plug-in Selection, hold down CTRL and select the org.eclipse.birt.report.engine following plug-ins:

• org.eclipse.birt.report.engine.dataextraction

• org.eclipse.birt.report.engine

com.ibm.icu

2 Choose OK. Dependencies appear as shown in Figure 21-6.

Figure 21-6 The Dependencies page

image

Declaring the data extraction extension point

In this step, specify the extension point required to implement the XML data extraction extension and add the extension element details. The extension point, org.eclipse.birt.report.engine.dataExtraction, sets the following properties for the extension point:

• ID

Optional identifier of the extension instance

• Name

Optional name of the extension instance

The extension point defines how to create a new data extraction extension to extract data in a custom way. The extension point defines the following extension element properties:

• id

Optional identifier for the data extraction extension

• format

Supported format of this data extraction extension

• class

Java class, that implements the IDataExtractionExtension

• mimeType

MIME type of the supported file output format, such as xml

• name

Name of the extension

• isHidden

Used to determine whether format is shown in UI

Use the Eclipse PDE to specify the extension point and 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 extension point:

org.eclipse.birt.report.engine.dataExtraction

Extensions appears, as shown in Figure 21-7. Choose Finish.

Figure 21-7 Selecting the data extraction extension point

image

All Extensions lists the extension point, org.eclipse.birt.report.engine.dataExtraction. Extension Details contains the list of extension details specified in the XML schema file, dataExtraction.exsd.

4 In All Extensions, choose the extension point, org.eclipse.birt.report.engine.dataExtraction. The Extension Element Details appear.

5 In Extension Element Details, specify the properties for the data extraction extension element, as shown in Table 21-3.

Table 21-3 Property values for the data extraction extension element

image

Extension Element Details appears as shown in Figure 21-8. The PDE Manifest Editor automatically updates plugin.xml.

Figure 21-8 Property values for the emitter extension

image

Understanding the XML data extraction extension

The XML data extraction extension example described in this chapter illustrates how to create a plug-in extension that converts all or part of report data to XML format. The XML data extraction extension example exports only the data selected in the export data menu to an output file. The export data feature is available in the BIRT Web Viewer.

This extension example creates the XML output stream and sends the stream to the browser. Typically the browser shows a download message that prompts the user to select to view or save the XML output.

This behavior depends on the browser and how it is configured to work with XML MIME type files. If the user changes the MIME type in the plug-in’s extension properties to text/plain, the browser displays the xml file instead of displaying a download message.

The following section provides a general description of the code a developer must write to complete the development of an XML data extraction extension.

Implementing the data extraction interfaces

The org.eclipse.birt.report.engine.api and org.eclipse.birt.report.engine.dataextraction plug-ins define the data extraction interfaces used to extract and format data to a specified format. The XML data extraction extension implements the following interfaces and classes:

• org.eclipse.birt.report.engine.extension.IDataExtractionExtension Defines three methods to initialize the resources, output extracted data, and release allocated resources during the data extraction process. The purpose of the output method is to process the metadata in the result set and format the output in the desired format. Extending the implementation class of the interface DataExtractionExtensionBase instead of the interface itself is a recommended best practice.

• org.eclipse.birt.report.engine.api.IExtractionResults Provides the API for retrieving metadata for the result set.

• org.eclipse.birt.report.engine.api.IDataExtractionOption Defines the basic properties of the data extraction and related get and set methods. Basic properties include elements such as output format, output file, and output stream.

• org.eclipse.birt.report.engine.dataextraction.ICommonDataExtractionOption

Extends the IDataExtractionOption interface to define the basic properties and related get and set methods for a common data extraction plug-in. The XML data extraction extension uses this interface, since most of the properties defined for the common data extraction apply to the XML extraction as well.

The implementation class for this interface is org.eclipse.birt.report.engine.dataextraction.impl.CommonDataExtractionImpl. The class provides utility methods that are initialized according to the data extraction options. The basic properties for the data extraction option are:

• Output locale

• Output timezone

• Output encoding, such as UTF-8, UTF-16LE, or ISO-8859-1

• Output date format

• Selected columns for export

• Indicator of whether to export the columns data type

• Indicator of whether to export the locale neutral format value

• User-defined parameters

Understanding the XML document format

The implementation package for the XML data extraction extension, org.eclipse.birt.report.engine.dataextraction.xml, contains only the class XMLDataExtractionImpl.java.

The XMLDataExtractionImpl extends org.eclipse.birt.report.engine.dataextraction.impl.CommonDataExtractionImpl class and implements private methods that create an XML document.

The XML document schema contains the following elements:

• <Report>

<Report> encloses the other elements of the XML document

• <Properties>

Contents include information about the following report properties:

• <ReportName>

Full path and the report name

• <Locale>

Report locale for display. If the locale is null, the default is locale en_US, displaying American English.

• <Encoding>

Specifies an option in the Export Data user interface allowing users to select the encoding for exported report data. By default, the encoding is set to UTF-8. The text content of <Encoding> displays the selected encoding.

• <Parameters>

This tag includes all parameters passed in the URL used to run the report in the Web Viewer. These parameters are referred as user parameters, which are different from report parameters. These items appear in separate <Parameter> tags. The parameter name is shown in a name attribute and the value is displayed as text in the <Parameter> node.

The exact number and values of the parameters depend on the report design and the environments in which the report runs. The user parameter names are self-documenting.

The following list displays the most common user parameters:

• __asattachment

• __cubememsize

• __dpi

• __exportdatatype

• __exportencoding

• __extractextension

• __format

• __locale

• __localeneutral

• __masterpage

• __report

• __resourceFolder

• __resultsetname

• __rtl

• __selectedcolumn0

• __selectedcolumn1

• __selectedcolumn2

• __selectedcolumnnumber

• __sep=0

• __sessionId

• __svg

• __timezone

• <isLocaleNeutral>

Users have the option to export data in a locale neutral format. Numbers are exported as neutral string values. Date format columns are exported in ISO8601 format, such as YYYY-MM-DD or YYYYMMDD for example.

• <Columns>

Lists the columns in the data row. Column type is an attribute of <Column>. The type attribute is optional and appears in an XML document only if the user selects to export the data types in the Data Export dialog.

• <Row>

Contains the data for a single data row. <Data> displays the column values.

Listing 21-1 shows an example of an exported XML document.

Listing 21-1 An exported XML document


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Report>
   <!--Extract report data in XML format-->
   <!--Lists the report properties, such as name, locale,
   encoding, user parameters-->
   <Properties>
      <ReportName>C:TESTXMLDataExtraction
   XMLDataExtraction.rptdesign</ReportName>
      <Locale>English</Locale>
      <isLocaleNeutral>true</isLocaleNeutral>
      <Encoding>UTF-8</Encoding>
      <Parameters>
         <Parameter name="__exportencoding">UTF-8</Parameter>
         <Parameter name="__svg">false</Parameter>
         <Parameter name=
            "__selectedcolumn1">COUNTRY</Parameter>
         <Parameter name=
            "__selectedcolumn2">CREDITLIMIT</Parameter>
         <Parameter name="__rtl">false</Parameter>
         <Parameter name=
            "__extractextension">com.eclipse.birt.report
            .engine.dataextraction.xml</Parameter>
         <Parameter name=
            "__report">C:TESTXMLDataExtraction
            XMLDataExtraction.rptdesign</Parameter>
         <Parameter name="__masterpage">true</Parameter>
         <Parameter name=
            "__sessionId">20090923_110444_204</Parameter>
         <Parameter name="__format">html</Parameter>
         <Parameter name="__asattachment">true</Parameter>
         <Parameter name="__selectedcolumnnumber">3</Parameter>
         <Parameter name="__localeneutral">true</Parameter>
         <Parameter name="__sep">0</Parameter>
         <Parameter name=
            "__timezone">America/Los_Angeles</Parameter>
         <Parameter name="1069371071"/>
         <Parameter name="__locale">en_US</Parameter>
         <Parameter name="__cubememsize">10</Parameter>
         <Parameter name="__exportdatatype">true</Parameter>
         <Parameter name="__resultsetname">ELEMENT_9</Parameter>
         <Parameter name=
            "__selectedcolumn0">CUSTOMERNAME</Parameter>
         <Parameter name=
            "__resourceFolder">C:TESTXMLDataExtraction
         </Parameter>
         <Parameter name="__dpi">100</Parameter>
      </Parameters>
   </Properties>
   <Columns>
      <Column type="String">CUSTOMERNAME</Column>
      <Column type="String">COUNTRY</Column>
      <Column type="Float">CREDITLIMIT</Column>
   </Columns>
   <Row>
      <Data>Signal Gift Stores</Data>
      <Data>USA</Data>
      <Data>71800.0</Data>
   </Row>
   <Row>
      <Data>Mini Gifts Distributors Ltd.</Data>
      <Data>USA</Data>
      <Data>210500.0</Data>
   </Row>
   <Row>
      <Data>Mini Wheels Co.</Data>
      <Data>USA</Data>
      <Data>64600.0</Data>
   </Row>
</Report>

Understanding XMLDataExtractionImpl methods

XMLDataExtractionImpl extends CommonDataExtractionImpl.

The class creates private variables to store the output XML document, the output stream where the document streams as a string, and the properties of the report. These properties are exported in the <properties> tag of the output XML file.

The variable declarations are shown in Listing 21-2.

Listing 21-2 XML data extraction option variables


public class XMLDataExtractionImpl extends
   CommonDataExtractionImpl {
   public static final String PLUGIN_ID =
   "org.eclipse.birt.report.engine.dataextraction.xml";
   public static final String DEFAULT_ENCODING =
      Charset.defaultCharset( ).name( );
   private Document outDocument;
   private OutputStream outputStream;
   private String encoding;
   private String selectedColumnNames;
   private boolean isExportDataType;
   private boolean isLocaleNeutral;
   private Locale locale;
   private String reportName;
   private Map pUserParameters;

The XMLDataExtractionImpl class uses Java API defined in org.w3c.dom package for the XML processing. Table 21-4 describes the exported properties variables.

Table 21-4 Report properties variables

image

The following XMLDataExtractionImpl methods set up and implement the data extraction:

• initialize( )

Defined by the org.eclipse.birt.report.engine.extension.IDataExtractionExtension interface class. Initializes context and options objects and calls the private initXMLOptions( ) method to initialize local variables.

Listing 21-3 initialize( )


public void initialize( IReportContext context,
   IDataExtractionOption options )
   throws BirtException
{
   super.initialize( context, options );
   initXMLOptions( options );
}

• initXMLOptions( )

Called at the beginning of each data extraction to perform the following operations:

• Creates the output stream that writes the text contents of the report to the XML file.

• Obtains a reference to the CommonDataExtractionOption object xmlOption, containing accessor methods that get the IDataExtractionOption interface options for the plug-in.

• Uses the data extraction API methods to initialize report property values, such as encoding, locale, iLocaleNeutral, selected columns, isExportDataType, user parameters, and report name.

Listing 21-4 initXMLOptions( )


private void initXMLOptions( IDataExtractionOption options ){
   outputStream = options.getOutputStream( );

   CommonDataExtractionOption xmlOption;
   if ( options instanceof CommonDataExtractionOption ){
      xmlOption = (CommonDataExtractionOption)options;
      }
      else {
         xmlOption =
            (CommonDataExtractionOption)
            new CommonDataExtractionOption(
               options.getOptions( ));
      }
      encoding = xmlOption.getEncoding( );
      if ( encoding == null || "".equals(encoding.trim( ))){
         encoding = null;
      }
      else {
         encoding = encoding.trim( );
      }
      if ( encoding == null ){
         encoding = DEFAULT_ENCODING;
      }
      isLocaleNeutral = xmlOption.isLocaleNeutralFormat( );
      locale = (Locale) xmlOption.getLocale( );
      if ( locale == null ){
         locale = Locale.getDefault( );
      }
      selectedColumnNames = xmlOption.getSelectedColumns( );
      isExportDataType = xmlOption.isExportDataType( );
      pUserParameters = xmlOption.getUserParameters( );
      getReportName( pUserParameters );
   }

• getReportName( )

Called by the initXMLOptions( ) method to extract the report name and path from the user parameters.

Listing 21-5 getReportName( )


private void getReportName( Map pUserParameters ){
   Map uParameters = pUserParameters;
   \Iterate over the keys, values in the map
   if ( uParameters != null ){
      java.util.Iterator it = null;
      for ( it =(java.util.Iterator)
           uParameters.keySet( ).iterator( );
           ((java.util.Iterator) it).hasNext( ); ) {
        Object key = it.next( );
        Object value = uParameters.get(key);
        if (key.toString( )
              .equalsIgnoreCase("__report")){
           reportName = value.toString( );
        }
      }
   }
}

• output( )

Interface method called to format the output stream for the data extraction. Uses the Document Object Model (DOM) component API to create the output XML document.

The data set result set is passed to the output( ) method through the IExtractionResults results input parameter. The code iterates through the result set to extract the data for only the selected columns. At the end the code converts the XML document to a string and writes the string to the output stream.

Listing 21-6 output( )


public void output( IExtractionResults results )
   throws BirtException{
   String[ ] columnNames = (String[ ]) selectedColumnNames;
   try {
      outDocument = createNewDocument ( );
   } catch (Exception e) {
      e.printStackTrace();
}
//create root element of output XML document
   Element rootElement =
      outDocument.createElement( "Report" );
   rootElement.appendChild( outDocument.createComment(
         "Extract report data in XML format" ));
   outDocument.appendChild( rootElement );

   Element pRow =
      outDocument.createElement( "Properties" );
   rootElement.appendChild( outDocument.createComment(
      "Lists the report properties, such as name, locale,
         encoding, user parameters" ));
   rootElement.appendChild( pRow );

   Element nodeReportName =
      outDocument.createElement( "ReportName" );
   nodeReportName.appendChild(
      outDocument.createTextNode( reportName ));
   pRow.appendChild( nodeReportName );

   Element nodeLocale =
      outDocument.createElement( "Locale" );
   nodeLocale.appendChild(outDocument.createTextNode(
   locale.getDisplayLanguage( ) ));
   pRow.appendChild( nodeLocale );

   Element nodeEncoding =
      outDocument.createElement( "Encoding" );
   nodeEncoding.appendChild( outDocument
      .createTextNode( encoding ));
   pRow.appendChild( nodeEncoding );

   Element nodeParameters =
      outDocument.createElement( "Parameters" );
   nodeParameters.appendChild(
      outDocument.createTextNode( userParameters ));
   pRow.appendChild(nodeParameters);

   try {
    // if selected columns are null or empty,
      returns all columns
         if ( columnNames == null || columnNames.length <= 0 ){
              int count =
              results.getResultMetaData( ).getColumnCount( );
              columnNames = new String[ count ];
              for ( int i = 0; i < count; i++ ){
                 String colName =
                 results.getResultMetaData( ).getColumnName(i);
                    columnNames[i] = colName;
              }
      }
      IDataIterator iData = null;
         if ( results != null ){
            iData = results.nextResultIterator( );
            if ( iData != null && columnNames.length > 0 ){
               String[ ] values =
                     new String[ columnNames.length ];
                  while ( iData.next( ) ){
                          Element row =
                     outDocument.createElement( "Row" );
                     rootElement.appendChild( row );
                     for (int i = 0; i < columnNames.length;
                             i++){
                        String columnName =
                           results.getResultMetaData( )
                              .getColumnName( i );
                        values[i] = getStringValue(iData
                           .getValue( columnNames[i] ),
                           isLocaleNeutral, locale );
                        Element node =
                           outDocument.createElement(
                              columnName);
                       node.appendChild(
                       outDocument.createTextNode(
                          values[ i ] ));
                       row.appendChild( node );
                    }
               }
            }
         }
      if ( encoding != null &&
         encoding.trim( ).length( ) > 0 ){
         outputStream.write(
            serialize( outDocument ).getBytes(
               encoding.trim( )));
         }
      else{
         outputStream.write( serialize( outDocument )
            .getBytes( ));
      }
   }
   catch ( Exception e ){ }
   }
}

• getColumnTypes( )

Extracts the data types from the result set metadata. The column data types export to the XML document only when the user selects this option in the Export Data dialog.

Listing 21-7 getColumnTypes( )


private String[ ] getColumnTypes( String[ ] columnNames,
   IExtractionResults results ) throws BirtException {
      Map<String,Integer> typesMap =
         new HashMap<String,Integer>( );
      int count =
         results.getResultMetaData( ).getColumnCount( );
      for ( int i = 0; i < count; i++ ){
         String colName = results.getResultMetaData( )
            .getColumnName( i );
         int colType = results.getResultMetaData( )
            .getColumnType( i );
         typesMap.put( colName, colType );
      }
      int[ ] types = new int[ columnNames.length ];
      String[ ] typeNames = new String[ columnNames.length ];
      for ( int i = 0; i < columnNames.length; i++ ){
         types[i] = typesMap.get( columnNames[i] ).intValue( );
         typeNames[i] = DataType.getName( types[i] );
      }
   return typeNames;
}

• exportIntoString( )

Converts XML document to a string in order to write to the output stream and send to the browser. The exportIntoString( ) method uses the javax.xml.transform package API to convert the XML document to a string.

Listing 21-8 exportIntoString( )


public String exportIntoString( ) throws Exception {
   try {
      ByteArrayOutputStream byteArrayOutputStream =
         new ByteArrayOutputStream( );
      TransformerFactory transformerFactory =
         TransformerFactory.newInstance( );
      Transformer transformer =
         transformerFactory.newTransformer( );
      Properties props = new Properties( );
      props.setProperty( OutputKeys.INDENT, "yes" );
      transformer.setOutputProperties( props );
      Source source = new DOMSource( outDocument );
      StreamResult streamResult =
         new StreamResult( byteArrayOutputStream );
      transformer.transform( source, streamResult );
      return byteArrayOutputStream.toString( encoding );
      //output is always in UTF-8
   } catch ( Exception e ) {
      System.out.println( "error in doExportIntoString" );
      throw e;
   }
}

Testing the XML data extraction plug-in

You can run the new XML data extraction plug-in directly in BIRT Report Designer or programmatically when you run and render a report using the Web Viewer. This section describes how to test the XML data extraction plug-in in BIRT Report Designer.

How to launch the XML data extraction plug-in

1 From the Eclipse SDK menu, choose Run—Run Configurations. In Run Configurations, right-click Eclipse Application. Choose New.

2 Create a configuration to launch an Eclipse application by performing the following tasks:

1 In Name, type:

XMLDataExtraction

2 On Main, in Location, type:

C:Test

3 Run Configurations appears as shown in Figure 21-9.

Figure 21-9 Creating the XMLDataExtraction run configuration

image

4 Choose the Plug-ins tab to select the list of plug-ins to launch with the Run configuration.

5 In Launch with, choose:

plug-ins selected below only

from the drop-down list, as shown in Figure 21-10.

Figure 21-10 Selecting the XMLDataExtraction plug-in

image

In some configurations, you can get an error message related to insufficient memory. The error is:

java.lang.OutOfMemoryError: PermGen space

To fix the error, add the following VM argument in the run configuration:

-XX:MaxPermSize=256M

In Run Configuration, choose Arguments and enter the MaxPermSize setting in VM arguments to avoid this problem, as shown in Figure 21-11.

Figure 21-11 Setting the VM argument

image

6 Choose Run to launch the run-time Eclipse workbench. A new instance of Eclipse opens up.

How to extract data from a BIRT report to XML format

The BIRT Report Designer discovers the new XML data extraction plug-in and displays the new XML format in the Export Data menu.

1 In the new Eclipse workbench, open the BIRT Report Design perspective.

2 In BIRT Report Designer perspective, open a BIRT report.

3 Choose Run→View Report→In Web Viewer from the main menu, as shown in Figure 21-12.

Figure 21-12 Previewing a report in CSV format

image

4 In the Web Viewer, select Export Data from the viewer toolbar, as shown in Figure 21-13.

Figure 21-13 Selecting the Export Data feature

image

5 In Export Data, choose the following options:

1 In Available Columns, press <CTRL> and select the columns to export.

2 Choose the arrow to move the columns to the Selected Columns list.

Use the double arrow to select and move all the columns in the dataset.

Use the up and down arrows to change the order in which the columns appear in the output file.

3 In the Export format, select XML(*.xml) from the list.

4 Select the Export column data type and Export column as locale neutral, as shown in Figure 21-14.

Figure 21-14 Setting the Export Data properties

image

5 Choose OK to start the export.

6 File Downloads opens with the message, Do you want to open or save this file?, as shown in Figure 21-15.

Figure 21-15 Saving the exported XML data

image

7 Choose Save and select the location to save the XML report or Open to view the report in the browser.

8 Open a saved report using any editor. Listing 21-9 shows a partial listing of exported data from an example report.

Listing 21-9 Partial listing of exported report data


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Report>
<!--Extract report data in XML format-->
<!--Lists the report properties, such as name, locale,
   encoding, user parameters-->
<Properties>
<ReportName>C:TESTXMLDataExtraction
   XMLDataExtraction.rptdesign</ReportName>
<Locale>English</Locale>
<isLocaleNeutral>true</isLocaleNeutral>
<Encoding>UTF-8</Encoding>
<Parameters>
<Parameter name="__exportencoding">UTF-8</Parameter>
<Parameter name="__svg">false</Parameter>
<Parameter name="__selectedcolumn1">COUNTRY</Parameter>
<Parameter name="__selectedcolumn2">CREDITLIMIT</Parameter>
<Parameter name="__rtl">false</Parameter>
<Parameter
   name="__extractextension">com.eclipse.birt.report.engine
   .dataextraction.xml</Parameter>
<Parameter name="__report">C:TESTXMLDataExtraction
   XMLDataExtraction.rptdesign</Parameter>
<Parameter name="__masterpage">true</Parameter>
<Parameter name="__sessionId">20090923_110444_204</Parameter>
<Parameter name="__format">html</Parameter>
<Parameter name="__asattachment">true</Parameter>
<Parameter name="__selectedcolumnnumber">3</Parameter>
<Parameter name="__localeneutral">true</Parameter>
<Parameter name="__sep">0</Parameter>
<Parameter name="__timezone">America/Los_Angeles</Parameter>
<Parameter name="1069371071"/>
<Parameter name="__locale">en_US</Parameter>
<Parameter name="__cubememsize">10</Parameter>
<Parameter name="__exportdatatype">true</Parameter>
<Parameter name="__resultsetname">ELEMENT_9</Parameter>
<Parameter name="__selectedcolumn0">CUSTOMERNAME</Parameter>
<Parameter name="__resourceFolder">C:TESTXMLDataExtraction
   </Parameter>
<Parameter name="__dpi">100</Parameter>
</Parameters>
</Properties>
<Columns>
<Column type="String">CUSTOMERNAME</Column>
<Column type="String">COUNTRY</Column>
<Column type="Float">CREDITLIMIT</Column>
</Columns>
<Row>
<Data>Signal Gift Stores</Data>
<Data>USA</Data>
<Data>71800.0</Data>
</Row>
<Row>
<Data>Mini Gifts Distributors Ltd.</Data>
<Data>USA</Data>
<Data>210500.0</Data>
</Row>
<Row>
<Data>Mini Wheels Co.</Data>
<Data>USA</Data>
<Data>64600.0</Data>
</Row>
...
</Report>

About the report design XML code

The XML file for the report design, new_report.rpdesign, contains the following source code settings, as specified in the report design:

• Data sources, including the ODA plug-in extension ID, driver class, URL, and user

• Data sets, including the ODA JDBC plug-in extension ID, result set properties, and query text

• Page setup, including the page footer

• Body, containing the table structure and properties for the bound data columns, including the header, footer, and detail rows

The report design example specifies a data source that connects to org.eclipse.birt.report.data.oda.sampledb, the BIRT Classic Models sample database. Listing 21-10 shows the XML source code for the report design used to test the XML data extraction example.

Listing 21-10 The report design XML code


<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design"
   version="3.2.21" id="1">
   <property name="createdBy">Eclipse BIRT Designer Version
      2.6.0.v20100531 Build &lt;2.6.0.v20100609-0613>
   </property>
   <property name="units">in</property>
   <property name=
      "iconFile">/templates/blank_report.gif</property>
   <property name="bidiLayoutOrientation">ltr</property>
   <parameters>
      scalar-parameter name="country" id="31">
         <property name="valueType">dynamic</property>
         <property name="dataSetName">Data Set</property>
         <expression name=
            "valueExpr">dataSetRow["COUNTRY"]</expression>
         <expression name=
            "labelExpr">dataSetRow["COUNTRY"]</expression>
         <expression name=
            "sortByColumn">dataSetRow["COUNTRY"]</expression>
         <property name="sortDirection">asc</property>
         <property name="dataType">string</property>
         <simple-property-list name="defaultValue">
            <value type="constant">USA</value>
         </simple-property-list>
         <property name="paramType">simple</property>
         <property name="controlType">list-box</property>
         <property name="mustMatch">true</property>
         <property name="fixedOrder">false</property>
         <property name="distinct">true</property>
            <structure name="format">
               <property name="category">Unformatted</property>
            </structure>
      </scalar-parameter>
   </parameters>
   <data-sources>
      <oda-data-source extensionID=
         "org.eclipse.birt.report.data.oda.jdbc"
            name="Data Source" id="7">
         <property name="odaDriverClass">
            org.eclipse.birt.report.data.oda.sampledb.Driver
         </property>
         <property name="odaURL">jdbc:classicmodels:sampledb
         </property>
         <property name="odaUser">ClassicModels</property>
      </oda-data-source>
   </data-sources>
   <data-sets>
      <oda-data-set
         extensionID=
            "org.eclipse.birt.report.data.oda.jdbc
               .JdbcSelectDataSet" name="Data Set" id="8">
         <list-property name="columnHints">
            <structure>
               <property name="columnName">CUSTOMERNAME
               </property>
               <property name="displayName">CUSTOMERNAME
               </property>
               </structure>
               <structure>
               <property name="columnName">COUNTRY</property>
               <property name="displayName">COUNTRY</property>
            </structure>
            <structure>
               <property name="columnName">CREDITLIMIT
               </property>
               <property name="displayName">CREDITLIMIT
               </property>
            </structure>
         </list-property>
         <list-property name="parameters">
            <structure>
               <property name="name">param_1</property>
               <property name="paramName">country</property>
               <property name="nativeName"></property>
               <property name="dataType">string</property>
               <property name="nativeDataType">12</property>
               <property name="position">1</property>
               <property name="isOptional">true</property>
               <property name="allowNull">true</property>
               <property name="isInput">true</property>
               <property name="isOutput">false</property>
            </structure>
         </list-property>
         <structure name="cachedMetaData">
            <list-property name="resultSet">
               <structure>
                  <property name="position">1</property>
                  <property name="dataType">string</property>
               </structure>
               <structure>
                  <property name="position">2</property>
                  <property name="name">COUNTRY</property>
                  <property name="dataType">string</property>
               </structure>
               <structure>
                  <property name="position">3</property>
                  <property name="name">CREDITLIMIT</property>
                  <property name="dataType">float</property>
               </structure>
            </list-property>
         </structure>
            <property name="dataSource">Data Source</property>
               <list-property name="resultSet">
                  <structure>
                     <property name="position">1</property>
                     <property name="name">CUSTOMERNAME
                        </property>
                     <property name="nativeName">CUSTOMERNAME
                        </property>
                     <property name="dataType">string</property>
                     <property name="nativeDataType">12</property>
                  </structure>
                  <structure>
                     <property name="position">2</property>
                     <property name="name">COUNTRY</property>
                     <property name="nativeName">COUNTRY</property>
                     <property name="dataType">string</property>
                     <property name="nativeDataType">12</property>
                  </structure>
                  <structure>
                     <property name="position">3</property>
                     <property name="name">CREDITLIMIT</property>
                     <property name="nativeName">CREDITLIMIT
                        </property>
                     <property name="dataType">float</property>
                     <property name="nativeDataType">8</property>
                  </structure>
               </list-property>
            <xml-property name="queryText">
               <![CDATA[select CLASSICMODELS.CUSTOMERS
                          .CUSTOMERNAME,
                          CLASSICMODELS.CUSTOMERS.COUNTRY,
                          CLASSICMODELS.CUSTOMERS.CREDITLIMIT
                       from CLASSICMODELS.CUSTOMERS
                       where country=?]]>
            </xml-property>
            <xml-property name="designerValues">
               <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
               <model:DesignValues xmlns:design=
                     "http://www.eclipse.org/datatools/
                     connectivity/oda/design" xmlns:model=
                     "http://www.eclipse.org/birt/report/model/
                     adapter/odaModel">
                  <Version>1.0</Version>
               <design:DataSetParameters>
                  <design:parameterDefinitions>
                     <design:inOutMode>In</design:inOutMode>
                     <design:attributes>
                        <design:name></design:name>
                        <design:position>1</design:position>
                        <design:nativeDataTypeCode>12
                           </design:nativeDataTypeCode>
                        <design:precision>50</design:precision>
                        <design:scale>0</design:scale>
                        <design:nullability>Nullable
                           </design:nullability>
                     </design:attributes>
                     <design:inputAttributes>
                        <design:elementAttributes>
                        <design:optional>true</design:optional>
                        </design:elementAttributes>
                     </design:inputAttributes>
                  </design:parameterDefinitions>
               </design:DataSetParameters>
               <design:ResultSets derivedMetaData="true">
                  <design:resultSetDefinitions>
                  <design:resultSetColumns>
                     <design:resultColumnDefinitions>
                        <design:attributes>
                           <design:name>CUSTOMERNAME</design:name>
                           <design:position>1</design:position>
                           <design:nativeDataTypeCode>12
                              </design:nativeDataTypeCode>
                           <design:precision>50</design:precision>
                           <design:scale>0</design:scale>
                           <design:nullability>Nullable
                              </design:nullability>
                           <design:uiHints>
                              <design:displayName>CUSTOMERNAME
                                    </design:displayName>
                           </design:uiHints>
                        </design:attributes>
                        <design:usageHints>
                           <design:label>CUSTOMERNAME</design:label>
                           <design:formattingHints>
                              <design:displaySize>50
                                 </design:displaySize>
                           </design:formattingHints>
                        </design:usageHints>
                     </design:resultColumnDefinitions>
                     <design:resultColumnDefinitions>
                        <design:attributes>
                           <design:name>COUNTRY</design:name>
                           <design:position>2</design:position>
                           <design:nativeDataTypeCode>12
                              </design:nativeDataTypeCode>
                           <design:precision>50</design:precision>
                           <design:scale>0</design:scale>
                           <design:nullability>Nullable
                              </design:nullability>
                           <design:uiHints>
                              <design:displayName>COUNTRY
                                 </design:displayName>
                           </design:uiHints>
                        </design:attributes>
                        <design:usageHints>
                           <design:label>COUNTRY</design:label>
                           <design:formattingHints>
                              <design:displaySize>50
                                 </design:displaySize>
                              </design:formattingHints>
                        </design:usageHints>
                     </design:resultColumnDefinitions>
                     <design:resultColumnDefinitions>
                        <design:attributes>
                           <design:name>CREDITLIMIT</design:name>
                           <design:position>3</design:position>
                           <design:nativeDataTypeCode>8
                              </design:nativeDataTypeCode>
                            <design:precision>15</design:precision>
                           <design:scale>0</design:scale>
                           <design:nullability>Nullable
                              </design:nullability>
                           <design:uiHints>
                                 <design:displayName>CREDITLIMIT
                                    </design:displayName>
                           </design:uiHints>
                        </design:attributes>
                        <design:usageHints>
                           <design:label>CREDITLIMIT</design:label>
                           <design:formattingHints>
                              <design:displaySize>22
                                 </design:displaySize>
                           </design:formattingHints>
                        </design:usageHints>
                     </design:resultColumnDefinitions>
                  </design:resultSetColumns>
               </design:resultSetDefinitions>
            </design:ResultSets>
         </model:DesignValues>]]></xml-property>
      </oda-data-set>
   </data-sets>
   <styles>
      <style name="report" id="4">
         <property name="fontFamily">"Verdana"</property>
         <property name="fontSize">10pt</property>
      </style>
      <style name="crosstab-cell" id="5">
         <property name="borderBottomColor">#CCCCCC</property>
         <property name="borderBottomStyle">solid</property>
         <property name="borderBottomWidth">1pt</property>
         <property name="borderLeftColor">#CCCCCC</property>
         <property name="borderLeftStyle">solid</property>
         <property name="borderLeftWidth">1pt</property>
         <property name="borderRightColor">#CCCCCC</property>
         <property name="borderRightStyle">solid</property>
         <property name="borderRightWidth">1pt</property>
         <property name="borderTopColor">#CCCCCC</property>
         <property name="borderTopStyle">solid</property>
         <property name="borderTopWidth">1pt</property>
      </style>
      <style name="crosstab" id="6">
         <property name="borderBottomColor">#CCCCCC</property>
         <property name="borderBottomStyle">solid</property>
         <property name="borderBottomWidth">1pt</property>
         <property name="borderLeftColor">#CCCCCC</property>
         <property name="borderLeftStyle">solid</property>
         <property name="borderLeftWidth">1pt</property>
         <property name="borderRightColor">#CCCCCC</property>
         <property name="borderRightStyle">solid</property>
         <property name="borderRightWidth">1pt</property>
         <property name="borderTopColor">#CCCCCC</property>
         <property name="borderTopStyle">solid</property>
         <property name="borderTopWidth">1pt</property>
      </style>
   </styles>
   <page-setup>
      <simple-master-page name="Simple MasterPage" id="2">
         <page-footer>
            <text id="3">
            <property name="contentType">html</property>
               <text-property name="content">
                  <![CDATA[<value-of>new Date()</value-of>]]>
               </text-property>
            </text>
         </page-footer>
      </simple-master-page>
   </page-setup>
   <body>
      <table id="9">
         <property name="dataSet">Data Set</property>
         <list-property name="boundDataColumns">
            <structure>
               <property name="name">CUSTOMERNAME</property>
               <property name="displayName">CUSTOMERNAME
                  </property>
               <expression
                  name="expression">dataSetRow["CUSTOMERNAME"]
                     </expression>
               <property name="dataType">string</property>
            </structure>
            <structure>
               <property name="name">COUNTRY</property>
               <property name="displayName">COUNTRY</property>
               <expression
                  name="expression">dataSetRow["COUNTRY"]
                  </expression>
               <property name="dataType">string</property>
            </structure>
            <structure>
               <property name="name">CREDITLIMIT</property>
               <property name="displayName">CREDITLIMIT
                  </property>
               <expression name="expression">
                  dataSetRow["CREDITLIMIT"]</expression>
               <property name="dataType">float</property>
            </structure>
         </list-property>
         <column id="28"/>
         <column id="29"/>
         <column id="30"/>
            <header>
               <row id="10">
                  <cell id="11">
                     <label id="12">
                        <text-property name="text">CUSTOMERNAME
                           </text-property>
                     </label>
                  </cell>
                  <cell id="13">
                     <label id="14">
                        <text-property name="text">COUNTRY
                           </text-property>
                     </label>
                  </cell>
                  <cell id="15">
                     <label id="16">
                        <text-property name="text">CREDITLIMIT
                           </text-property>
                     </label>
                  </cell>
               </row>
            </header>
            <detail>
               <row id="17">
                  <cell id="18">
                     <data id="19">
                        <property
                              name="resultSetColumn">CUSTOMERNAME
                        </property>
                     </data>
                  </cell>
                  <cell id="20">
                     <data id="21">
                        <property name="resultSetColumn">COUNTRY
                           </property>
                     </data>
                  </cell>
                  <cell id="22">
                     <data id="23">
                        <property
                           name="resultSetColumn">CREDITLIMIT
                        </property>
                     </data>
                  </cell>
               </row>
            </detail>
            <footer>
               <row id="24">
                  <cell id="25"/>
                  <cell id="26"/>
                  <cell id="27"/>
               </row>
            </footer>
      </table>
   </body>
</report>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset