Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Retrieving Images of all types in Report
Retrieving Images of all types in Report [message #1412534] Tue, 26 August 2014 11:52 Go to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Hello,

We are integrating Birt for a Project. I need to retrieve all Images existing in rptdesign. Actually I have found and implemented a Solution for finding all Images in Report. But I think it can not ensure to retrieve all Images in Report. Because i'm iterating over grids rows and then cells and Listing recursively. the Problem is that a Image does not have to exist in a Grid. so what happens if a Image is added in a Table or Data. or am I wrong? is there any simple solution for finding all Images in a Report File? Thanks in advance


        SlotHandle shBody = reportHandle.getBody();

        Iterator allImagesList = shBody.iterator();

        while (allImagesList.hasNext()) {
            Object obj = allImagesList.next();
            if (obj instanceof ImageHandle) {
                ImageHandle imgHandle = (ImageHandle) obj;

            } else if (obj instanceof GridHandle) {
                GridHandle gridHandle = (GridHandle) obj;
                parseGrid(gridHandle);
            } else if (obj instanceof ListingHandle) {
                ListingHandle list = (ListingHandle) obj;
                parseList(list);
            }

        }

  private void parseGrid(GridHandle grid) {
        SlotHandle grRows = grid.getRows();
        Iterator rowIterator = grRows.iterator();
        parseRow(rowIterator);
    }

private void parseRow(Iterator rowIterator) {

        while (rowIterator.hasNext()) {
// Get RowHandle objects.
            Object rowSlotContents = rowIterator.next();
            System.out.println("Row ID: " + ((RowHandle) rowSlotContents).getID());
// 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();
                System.out.println("Cell ID: " + ((CellHandle) cellSlotContents).getID());
                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 imageSource = ((ImageHandle) cellContents).getSource();
                        ImageHandle ih = (ImageHandle) cellContents;
                        //  System.out.println(ih.getImageName());
                        // Check that the image has a URI.

                        //System.out.println("Type Expression: " + ih.getExpressionProperty("uri").getStringValue());
                        if (ih.getSource() != null) {
                            HashMap<String, Serializable> imageMap = new HashMap<String, Serializable>();
                            imageMap.put(BirtProperties.IMAGE_ID, ih.getID());
                            imageMap.put(BirtProperties.IMAGE_HEIGHT, ih.getHeight().getStringValue());
                            imageMap.put(BirtProperties.IMAGE_WIDTH, ih.getWidth().getStringValue());
                            imageMap.put(BirtProperties.IMAGE_SOURCE, ih.getSource());

                            if (ih.getSource().equals("embed") && ih.getImageName() != null) {
                                imageMap.put(BirtProperties.IMAGE_NAME, ih.getImageName());
                                imageMap.put(BirtProperties.IMAGE_IDENTIFIER, ih.getImageName());

                                List allEmbeddedImages = reportHandle.getAllImages();

                                for (Object embedImageHandle : allEmbeddedImages) {
                                    EmbeddedImageHandle img = (EmbeddedImageHandle) embedImageHandle;

                                    if (img.getName().equals(imageMap.get(BirtProperties.IMAGE_NAME))) {
                                        imageMap.put(BirtProperties.IMAGE_BASE64, img.getData());
                                        imageMap.put(BirtProperties.IMAGE_TYPE, img.getType());

                                    }

                                }

                            } else {
                                imageMap.put(BirtProperties.IMAGE_NAME, ih.getExpressionProperty("uri").getStringValue());
                                imageMap.put(BirtProperties.IMAGE_IDENTIFIER, ih.getExpressionProperty("uri").getStringValue());
                                imageMap.put(BirtProperties.IMAGE_BASE64, ih.getExpressionProperty("uri").getStringValue());

                            }

                            parameters.put(String.valueOf(ih.getID()), imageMap);
                        }

                    } else if (cellContents instanceof GridHandle) {
                        parseGrid((GridHandle) cellContents);

                    } else if (cellContents instanceof ListingHandle) {
                        parseList((ListingHandle) cellContents);

                    }

                }
            }

        }

    }

 private void parseList(ListingHandle list) {
        SlotHandle grRows = list.getHeader();
        Iterator rowIterator = grRows.iterator();
        parseRow(rowIterator);
        grRows = list.getDetail();
        rowIterator = grRows.iterator();
        parseRow(rowIterator);
        grRows = list.getFooter();
        rowIterator = grRows.iterator();
        parseRow(rowIterator);
        grRows = list.getGroups();
        rowIterator = grRows.iterator();
        parseRow(rowIterator);
    }

[Updated on: Tue, 26 August 2014 11:53]

Report message to a moderator

Re: Retrieving Images of all types in Report [message #1413873 is a reply to message #1412534] Fri, 29 August 2014 16:33 Go to previous message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Finally I found a simple Solution for getting all images in report. I add solution here for other people need in future

reportHandle = (ReportDesignHandle) design.getDesignHandle();
SlotHandle shBody = reportHandle.getBody();

findAllImages(shBody);

private static void findAllImages(SlotHandle slot) {

        for (DesignElementHandle element : (List<DesignElementHandle>) slot
                .getContents()) {

            if (element instanceof ImageHandle) {
                ids.add(((ImageHandle) element).getID());

            } else {
                
                int slotCount = element.getDefn().getSlotCount();
                for (int i = 0; i < slotCount; i++) {
                    findAllImages(element.getSlot(i));
                }
            }
        }

    }

Previous Topic:Creating report using EMF model
Next Topic:Get padding property from ItextArea
Goto Forum:
  


Current Time: Sat Apr 27 05:22:11 GMT 2024

Powered by FUDForum. Page generated in 0.02773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top