@Override
  protected boolean performExport(final MasterReport report) {
    try {
      final File targetFile =
          getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_TARGETFILE);
      if (targetFile == null) {
        return false;
      }

      File dataDirectory =
          getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR);
      if (dataDirectory == null) {
        dataDirectory = new File(targetFile, "data/"); // $NON-NLS-1$
      }

      final File targetDirectory = targetFile.getParentFile();
      if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
        dataDirectory = dataDirectory.getParentFile();
        if (dataDirectory.isDirectory() == false) {
          String msg =
              Messages.getInstance()
                  .getErrorString(
                      "JFreeReportDirectoryComponent.ERROR_0001_INVALID_DIR", //$NON-NLS-1$
                      dataDirectory.getPath());
          throw new ReportProcessingException(msg);
        }
      } else if (dataDirectory.exists() == false) {
        dataDirectory.mkdirs();
      }

      final FileRepository targetRepository = new FileRepository(targetDirectory);
      final ContentLocation targetRoot = targetRepository.getRoot();

      final FileRepository dataRepository = new FileRepository(dataDirectory);
      final ContentLocation dataRoot = dataRepository.getRoot();

      final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();

      final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
      printer.setContentWriter(
          targetRoot, new DefaultNameGenerator(targetRoot, targetFile.getName()));
      printer.setDataWriter(
          dataRoot, new DefaultNameGenerator(targetRoot, "content")); // $NON-NLS-1$
      printer.setUrlRewriter(new FileSystemURLRewriter());
      outputProcessor.setPrinter(printer);

      final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
      final int yieldRate = getYieldRate();
      if (yieldRate > 0) {
        sp.addReportProgressListener(new YieldReportListener(yieldRate));
      }
      sp.processReport();
      sp.close();
      return true;
    } catch (ReportProcessingException e) {
      return false;
    } catch (ContentIOException e) {
      return false;
    }
  }
コード例 #2
0
  @Override
  protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
    try {
      String dataDirectory =
          getInputStringValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR);
      if (dataDirectory == null) {
        dataDirectory = "data"; // $NON-NLS-1$
      }

      final ZipRepository zipRepository = new ZipRepository();
      final ContentLocation root = zipRepository.getRoot();
      final ContentLocation data =
          RepositoryUtilities.createLocation(
              zipRepository, RepositoryUtilities.split(dataDirectory, "/")); // $NON-NLS-1$

      final FlowHtmlOutputProcessor outputProcessor =
          new FlowHtmlOutputProcessor(report.getConfiguration());

      final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
      printer.setContentWriter(root, new DefaultNameGenerator(root, "report.html")); // $NON-NLS-1$
      printer.setDataWriter(data, new DefaultNameGenerator(data, "content")); // $NON-NLS-1$
      printer.setUrlRewriter(new SingleRepositoryURLRewriter());
      outputProcessor.setPrinter(printer);

      final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
      final int yieldRate = getYieldRate();
      if (yieldRate > 0) {
        sp.addReportProgressListener(new YieldReportListener(yieldRate));
      }
      sp.processReport();
      zipRepository.write(outputStream);
      close();
      return true;
    } catch (ReportProcessingException e) {
      error(
          Messages.getInstance()
              .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"),
          e); //$NON-NLS-1$
      return false;
    } catch (IOException e) {
      error(
          Messages.getInstance()
              .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"),
          e); //$NON-NLS-1$
      return false;
    } catch (ContentIOException e) {
      error(
          Messages.getInstance()
              .getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"),
          e); //$NON-NLS-1$
      return false;
    }
  }