Developing an Eclipse BIRT XML Report Rendering Extension, Page 5
Understanding LoadExportSchema
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 8 shows the specification of the default substitution patterns for the XML tags and the constructor, which calls the readSchemaFile( ) method.
Listing 8: The LoadExportSchema class
package org.eclipse.birt.report.engine.emitter.xml;
...
public class LoadExportSchema{
protected String fileName = "";
protected String startTag = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>";
protected String textTag = "<text>??value</text>";
protected String imageTag = "<image>??value</image>";
protected String dataTag = "<data>??value</data>";
protected String labelTag = "<label>??value</label>";
protected String endTag = "</report>";
protected String reportTag = "<report:??name>";
public LoadExportSchema(String fileName)
{
if ( fileName.length() > 0 )
{
this.fileName = fileName;
readSchemaFile();
}
}
The readSchemaFile( ) method reads the XML Schema file, one line at a time, replacing the default values for the patterns of the XML version, text, image, data, label, and report tags with the values specified in the XML Schema file.
Listing 9 shows the code for the readSchemaFile( ) method.
Listing 9: The readSchemaFile( ) method
private void readSchemaFile()
{
BufferedReader input = null;
try
{
input = new BufferedReader(
new FileReader(fileName) );
String line = null; //not declared within while loop
while (( line = input.readLine()) != null){
int pos = line.indexOf("=");
if ( pos > 0 )
{
String index = line.substring(0, pos );
String indexTag = line.substring(pos + 1,
line.length());
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( );
}
}
}
0 Comments (click to add your comment)
Networking Solutions
