Programming using the BIRT Reporting APIs : Programming the structure of a report design : Using a report item in a report design : How to use the report structure to access a report item
 
How to use the report structure to access a report item
The code sample in Listing 12‑18 finds an image item in a grid, checks its type, and examines its URI. Use this technique for generic code to navigate a report design structure or if to find an item that does not have a name. The variable, design, is a ReportDesignHandle object.
Listing 12‑18 Navigating the report structure to access a report item
// Instantiate a slot handle and iterator for the body slot.
SlotHandle shBody = design.getBody( );
Iterator slotIterator = shBody.iterator( );
 
// To retrieve top-level report items, iterate over the body.
while (slotIterator.hasNext( )) {
Object shContents = slotIterator.next( );
// To get the contents of the top-level report items,
// instantiate slot handles.
if ( shContents instanceof GridHandle ) {
GridHandle grid = ( GridHandle ) shContents;
SlotHandle grRows = grid.getRows( );
Iterator rowIterator = grRows.iterator( );
while ( rowIterator.hasNext( )) {
// Get RowHandle objects.
Object rowSlotContents = rowIterator.next( );
// To find the image element, iterate over the grid.
SlotHandle cellSlot = ( ( RowHandle ) rowSlotContents ).getCells( );
Iterator cellIterator = cellSlot.iterator( );
 
while ( cellIterator.hasNext( )) {
// Get a CellHandle object.
Object cellSlotContents = cellIterator.next( );
SlotHandle cellContentSlot = ( ( CellHandle) cellSlotContents ).getContent( );
Iterator cellContentIterator = cellContentSlot.iterator( );
 
while ( cellContentIterator.hasNext( )) {
// Get a DesignElementHandle object.
Object cellContents = cellContentIterator.next( );
// Check that the element is an image.
if (cellContents instanceof ImageHandle) {
String is = ( ( ImageHandle ) cellContents ).getSource( );
// Check that the image has a URI.
if ( ( is.equals( DesignChoiceConstants.IMAGE_REF_TYPE_URL ))
|| ( is.equals( DesignChoiceConstants.IMAGE_REF_TYPE_FILE ))) {
// Retrieve the URI of the image.
String imageURI = ( ( ImageHandle ) cellContents ).getURI( );
}
}
}
}
}
}
}