/**
   * @param model
   * @param output
   * @return
   * @throws IOException
   * @throws BundleWriterException
   * @throws ContentIOException
   */
  private ByteArrayOutputStream generatePrptOutput(
      SaikuMasterModel model, final MasterReport output)
      throws IOException, BundleWriterException, ContentIOException {

    final ByteArrayOutputStream prptContent = new ByteArrayOutputStream();
    ensureSaikuPreProcessorIsRemoved(output);
    BundleWriter.writeReportToZipStream(output, prptContent);

    return prptContent;
  }
  /**
   * This method does what the report designer does on save.
   *
   * @param report
   * @param file
   * @throws Exception
   */
  private void saveReport(final MasterReport report, final File file) throws Exception {
    BundleWriter.writeReportToZipFile(report, file);
    final ResourceManager resourceManager = report.getResourceManager();
    final Resource bundleResource = resourceManager.createDirectly(file, DocumentBundle.class);
    final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
    final ResourceKey bundleKey = bundle.getBundleKey();

    final MemoryDocumentBundle mem = new MemoryDocumentBundle();
    BundleUtilities.copyStickyInto(mem, bundle);
    BundleUtilities.copyMetaData(mem, bundle);
    report.setBundle(mem);
    report.setContentBase(mem.getBundleMainKey());
    report.setDefinitionSource(bundleKey);
  }