public static JRPrintImage getImage(
      List<JasperPrint> jasperPrintList, JRPrintElementIndex imageIndex) {
    JasperPrint report = jasperPrintList.get(imageIndex.getReportIndex());
    JRPrintPage page = report.getPages().get(imageIndex.getPageIndex());

    Integer[] elementIndexes = imageIndex.getAddressArray();
    Object element = page.getElements().get(elementIndexes[0].intValue());

    for (int i = 1; i < elementIndexes.length; ++i) {
      JRPrintFrame frame = (JRPrintFrame) element;
      element = frame.getElements().get(elementIndexes[i].intValue());
    }

    return (JRPrintImage) element;
  }
  public static JRPrintElementIndex getPrintElementIndex(String imageName) {
    if (!imageName.startsWith(IMAGE_NAME_PREFIX)) {
      throw new JRRuntimeException("Invalid image name: " + imageName);
    }

    return JRPrintElementIndex.parsePrintElementIndex(imageName.substring(IMAGE_NAME_PREFIX_LEGTH));
  }
 /**
  * protected void writeImageMap(String imageMapName, JRPrintHyperlink mainHyperlink, List
  * imageMapAreas) throws IOException { writer.write("<map name=\"" + imageMapName + "\">\n");
  *
  * <p>for (Iterator it = imageMapAreas.iterator(); it.hasNext();) { JRPrintImageAreaHyperlink
  * areaHyperlink = (JRPrintImageAreaHyperlink) it.next(); JRPrintImageArea area =
  * areaHyperlink.getArea();
  *
  * <p>writer.write(" <area shape=\"" + JRPrintImageArea.getHtmlShape(area.getShape()) + "\"");
  * writeImageAreaCoordinates(area); writeImageAreaHyperlink(areaHyperlink.getHyperlink());
  * writer.write("/>\n"); }
  *
  * <p>if (mainHyperlink.getHyperlinkTypeValue() != NONE) { writer.write(" <area
  * shape=\"default\""); writeImageAreaHyperlink(mainHyperlink); writer.write("/>\n"); }
  *
  * <p>writer.write("</map>\n"); }
  *
  * <p>protected void writeImageAreaCoordinates(JRPrintImageArea area) throws IOException { int[]
  * coords = area.getCoordinates(); if (coords != null && coords.length > 0) { StringBuffer
  * coordsEnum = new StringBuffer(coords.length * 4); coordsEnum.append(coords[0]); for (int i = 1;
  * i < coords.length; i++) { coordsEnum.append(','); coordsEnum.append(coords[i]); }
  *
  * <p>writer.write(" coords=\"" + coordsEnum + "\""); } }
  *
  * <p>protected void writeImageAreaHyperlink(JRPrintHyperlink hyperlink) throws IOException {
  * String href = getHyperlinkURL(hyperlink); if (href == null) { writer.write("
  * nohref=\"nohref\""); } else { writer.write(" href=\"" + href + "\"");
  *
  * <p>String target = getHyperlinkTarget(hyperlink); if (target != null) { writer.write("
  * target=\""); writer.write(target); writer.write("\""); } }
  *
  * <p>if (hyperlink.getHyperlinkTooltip() != null) { writer.write(" title=\"");
  * writer.write(JRStringUtil.xmlEncode(hyperlink.getHyperlinkTooltip())); writer.write("\""); } }
  *
  * <p>/**
  */
 public static String getImageName(JRPrintElementIndex printElementIndex) {
   return IMAGE_NAME_PREFIX + printElementIndex.toString();
 }
  protected void exportGrid(JRGridLayout gridLayout, JRPrintElementIndex frameIndex)
      throws IOException, JRException {
    CutsInfo xCuts = gridLayout.getXCuts();
    JRExporterGridCell[][] grid = gridLayout.getGrid();

    TableBuilder tableBuilder =
        frameIndex == null
            ? new TableBuilder(reportIndex, pageIndex, tempBodyWriter, tempStyleWriter)
            : new TableBuilder(frameIndex.toString(), tempBodyWriter, tempStyleWriter);

    tableBuilder.buildTableStyle(gridLayout.getWidth());
    tableBuilder.buildTableHeader();

    for (int col = 1; col < xCuts.size(); col++) {
      tableBuilder.buildColumnStyle(col - 1, xCuts.getCutOffset(col) - xCuts.getCutOffset(col - 1));
      tableBuilder.buildColumnHeader(col - 1);
      tableBuilder.buildColumnFooter();
    }

    JRPrintElement element = null;
    for (int row = 0; row < grid.length; row++) {
      int emptyCellColSpan = 0;
      int emptyCellWidth = 0;
      int rowHeight = gridLayout.getRowHeight(row);

      tableBuilder.buildRowStyle(row, rowHeight);
      tableBuilder.buildRowHeader(row);

      for (int col = 0; col < grid[0].length; col++) {
        JRExporterGridCell gridCell = grid[row][col];
        if (gridCell.getType() == JRExporterGridCell.TYPE_OCCUPIED_CELL) {
          if (emptyCellColSpan > 0) {
            // writeEmptyCell(gridCell, emptyCellColSpan, emptyCellWidth, rowHeight);
            emptyCellColSpan = 0;
            emptyCellWidth = 0;
          }

          // writeOccupiedCells(1);
          exportOccupiedCells(1);
          //					OccupiedGridCell occupiedGridCell = (OccupiedGridCell)gridCell;
          //					ElementGridCell elementGridCell =
          // (ElementGridCell)grid[occupiedGridCell.getRow()][occupiedGridCell.getCol()];
          //					exportOccupiedCells(elementGridCell);
          //					col += elementGridCell.getColSpan() - 1;
        } else if (gridCell.getWrapper() != null) {
          if (emptyCellColSpan > 0) {
            // writeEmptyCell(gridCell, emptyCellColSpan, emptyCellWidth, rowHeight);
            emptyCellColSpan = 0;
            emptyCellWidth = 0;
          }

          element = gridCell.getWrapper().getElement();

          if (element instanceof JRPrintLine) {
            exportLine(tableBuilder, (JRPrintLine) element, gridCell);
          } else if (element instanceof JRPrintRectangle) {
            exportRectangle(tableBuilder, (JRPrintRectangle) element, gridCell);
          } else if (element instanceof JRPrintEllipse) {
            exportEllipse(tableBuilder, (JRPrintEllipse) element, gridCell);
          } else if (element instanceof JRPrintImage) {
            exportImage(tableBuilder, (JRPrintImage) element, gridCell);
          } else if (element instanceof JRPrintText) {
            exportText(tableBuilder, (JRPrintText) element, gridCell);
          } else if (element instanceof JRPrintFrame) {
            exportFrame(tableBuilder, (JRPrintFrame) element, gridCell);
          } else if (element instanceof JRGenericPrintElement) {
            exportGenericElement(tableBuilder, (JRGenericPrintElement) element, gridCell);
          }

          // //x += gridCell.colSpan - 1;
          // col += gridCell.getColSpan() - 1;
        } else {
          emptyCellColSpan++;
          emptyCellWidth += gridCell.getWidth();
          exportEmptyCell(gridCell, 1);
        }
      }

      //			if (emptyCellColSpan > 0)
      //			{
      //				//writeEmptyCell(null, emptyCellColSpan, emptyCellWidth, rowHeight);
      //			}

      tableBuilder.buildRowFooter();
    }

    tableBuilder.buildTableFooter();
  }