protected String getImagePath(
      JRRenderable renderer, boolean isLazy, JRExporterGridCell gridCell) {
    String imagePath = null;

    if (renderer != null) {
      if (renderer.getType() == JRRenderable.TYPE_IMAGE
          && rendererToImagePathMap.containsKey(renderer.getId())) {
        imagePath = rendererToImagePathMap.get(renderer.getId());
      } else {
        if (isLazy) {
          imagePath = ((JRImageRenderer) renderer).getImageLocation();
        } else {
          JRPrintElementIndex imageIndex = getElementIndex(gridCell);
          imagesToProcess.add(imageIndex);

          String imageName = getImageName(imageIndex);
          imagePath = "Pictures/" + imageName;
        }

        rendererToImagePathMap.put(renderer.getId(), imagePath);
      }
    }

    return imagePath;
  }
  protected void exportReportToOasisZip(OutputStream os) throws JRException, IOException {
    OasisZip oasisZip =
        new FileBufferedOasisZip(((JROpenDocumentExporterNature) nature).getOpenDocumentNature());

    ExportZipEntry tempBodyEntry = new FileBufferedZipEntry(null);
    ExportZipEntry tempStyleEntry = new FileBufferedZipEntry(null);

    tempBodyWriter = tempBodyEntry.getWriter();
    tempStyleWriter = tempStyleEntry.getWriter();

    styleCache = new StyleCache(tempStyleWriter, fontMap, getExporterKey());

    Writer stylesWriter = oasisZip.getStylesEntry().getWriter();

    StyleBuilder styleBuilder = new StyleBuilder(jasperPrintList, stylesWriter);
    styleBuilder.build();

    stylesWriter.close();

    for (reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++) {
      setJasperPrint(jasperPrintList.get(reportIndex));

      List<JRPrintPage> pages = jasperPrint.getPages();
      if (pages != null && pages.size() > 0) {
        if (isModeBatch) {
          startPageIndex = 0;
          endPageIndex = pages.size() - 1;
        }

        JRPrintPage page = null;
        for (pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++) {
          if (Thread.interrupted()) {
            throw new JRException("Current thread interrupted.");
          }

          page = pages.get(pageIndex);

          exportPage(page);
        }
      }
    }

    tempBodyWriter.flush();
    tempStyleWriter.flush();

    tempBodyWriter.close();
    tempStyleWriter.close();

    /*   */
    ContentBuilder contentBuilder =
        new ContentBuilder(
            oasisZip.getContentEntry(),
            tempStyleEntry,
            tempBodyEntry,
            styleCache.getFontFaces(),
            ((JROpenDocumentExporterNature) nature).getOpenDocumentNature());
    contentBuilder.build();

    tempStyleEntry.dispose();
    tempBodyEntry.dispose();

    if ((imagesToProcess != null && imagesToProcess.size() > 0)) {
      for (Iterator<JRPrintElementIndex> it = imagesToProcess.iterator(); it.hasNext(); ) {
        JRPrintElementIndex imageIndex = it.next();

        JRPrintImage image = getImage(jasperPrintList, imageIndex);
        JRRenderable renderer = image.getRenderer();
        if (renderer.getType() == JRRenderable.TYPE_SVG) {
          renderer =
              new JRWrappingSvgRenderer(
                  renderer,
                  new Dimension(image.getWidth(), image.getHeight()),
                  ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null);
        }

        oasisZip.addEntry( // FIXMEODT optimize with a different implementation of entry
            new FileBufferedZipEntry(
                "Pictures/" + getImageName(imageIndex), renderer.getImageData()));
      }
    }

    oasisZip.zipEntries(os);

    oasisZip.dispose();
  }
  /**
   * @throws JRException
   * @throws IOException
   */
  public void exportImage(JRPrintImage image) throws JRException, IOException {
    xmlWriter.startElement(JRXmlConstants.ELEMENT_image);
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_scaleImage, image.getOwnScaleImageValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hAlign, image.getOwnHorizontalAlignmentValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_vAlign, image.getOwnVerticalAlignmentValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_isLazy, image.isLazy(), false);
    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_onErrorType, image.getOnErrorTypeValue(), OnErrorTypeEnum.ERROR);

    if (hyperlinkProducerFactory == null) {
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkType,
          image.getLinkType(),
          HyperlinkTypeEnum.NONE.getName());
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkReference, image.getHyperlinkReference());
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkAnchor, image.getHyperlinkAnchor());
      xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkPage, image.getHyperlinkPage());
    } else {
      String reference = hyperlinkProducerFactory.produceHyperlink(image);
      if (reference != null) {
        xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkType, HyperlinkTypeEnum.REFERENCE);
        xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkReference, reference);
      }
    }

    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_hyperlinkTarget,
        image.getLinkTarget(),
        HyperlinkTargetEnum.SELF
            .getName()); // FIXMETARGET this exporter is used in the Flash viewer
    xmlWriter.addEncodedAttribute(
        JRXmlConstants.ATTRIBUTE_hyperlinkTooltip, image.getHyperlinkTooltip());
    xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_anchorName, image.getAnchorName());
    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_bookmarkLevel, image.getBookmarkLevel(), JRAnchor.NO_BOOKMARK);

    exportReportElement(image);
    exportBox(image.getLineBox());
    exportGraphicElement(image);

    JRRenderable renderer = image.getRenderer();
    if (renderer != null) {
      xmlWriter.startElement(JRXmlConstants.ELEMENT_imageSource);
      xmlWriter.addAttribute(
          JRXmlConstants.ATTRIBUTE_isEmbedded, isEmbeddingImages && !image.isLazy(), false);

      String imageSource = "";

      if (renderer.getType() == JRRenderable.TYPE_SVG) {
        renderer =
            new JRWrappingSvgRenderer(
                renderer,
                new Dimension(image.getWidth(), image.getHeight()),
                ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null);
      }

      if (image.isLazy()) {
        imageSource = ((JRImageRenderer) renderer).getImageLocation();
      } else if (isEmbeddingImages) {
        try {
          ByteArrayInputStream bais = new ByteArrayInputStream(renderer.getImageData());
          ByteArrayOutputStream baos = new ByteArrayOutputStream();

          Base64Encoder encoder = new Base64Encoder(bais, baos);
          encoder.process();

          imageSource = new String(baos.toByteArray(), DEFAULT_XML_ENCODING);
        } catch (IOException e) {
          throw new JRException("Error embedding image into XML.", e);
        }
      } else {
        if (renderer.getType() == JRRenderable.TYPE_IMAGE
            && rendererToImagePathMap.containsKey(renderer)) {
          imageSource = rendererToImagePathMap.get(renderer);
        } else {
          imageSource = IMAGE_PREFIX + getNextImageId();
          imageNameToImageDataMap.put(imageSource, renderer.getImageData());

          imageSource = new File(imagesDir, imageSource).getPath();
          rendererToImagePathMap.put(renderer, imageSource);
        }
      }

      xmlWriter.writeCDATA(imageSource);
      xmlWriter.closeElement();
    }

    if (hyperlinkProducerFactory == null) {
      exportHyperlinkParameters(image);
    }

    xmlWriter.closeElement();
  }