private void createInfomation(Composite parent) {

    Font font = parent.getFont();
    Composite continer = createComposite(parent, font, 2, 2, GridData.FILL_BOTH, 0, 0);
    continer.setBackground(fBackgroundColor);
    IReportDocument document = null;
    try {
      document = engine.openReportDocument(getFileName());
      createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.3")); // $NON-NLS-1$
      createScriptgLabel(continer, document.getName());

      createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.4")); // $NON-NLS-1$
      createScriptgLabel(continer, document.getVersion());

      createScriptgLabel(continer, Messages.getString("ReportDocumentEditor.5")); // $NON-NLS-1$
      createScriptgLabel(continer, "" + document.getPageCount()); // $NON-NLS-1$

    } catch (EngineException e) {
      this.e = e;
      createErrorControl(continer);
    } finally {
      if (document != null) {
        document.close();
      }
    }
  }
Esempio n. 2
0
  public void testRunWithArchiveView() throws Exception {
    // 1. create document from ORIGINAL_REPORT_DESIGN_RESOURCE first
    copyResource(ORIGINAL_REPORT_DESIGN_RESOURCE, ORIGINAL_REPORT_DESIGN);
    IReportRunnable report = engine.openReportDesign(ORIGINAL_REPORT_DESIGN);
    IRunTask task = engine.createRunTask(report);
    try {
      task.run(ORIGINAL_REPORT_DOCUMENT);
    } finally {
      task.close();
    }

    // 2. create document from CHANGED_REPORT_DESIGN_RESOURCE
    copyResource(CHANGED_REPORT_DESIGN_RESOURCE, CHANGED_REPORT_DESIGN);

    ArchiveView view = new ArchiveView(ARCHIVE_VIEW_DOCUMENT, ORIGINAL_REPORT_DOCUMENT, "rw");

    try {
      report = engine.openReportDesign(CHANGED_REPORT_DESIGN);
      task = engine.createRunTask(report);
      try {
        // 3. new view archive and render
        ArchiveWriter writer = new ArchiveWriter(view);
        task.setDataSource(new ArchiveReader(view));
        task.run(writer);
      } finally {
        task.close();
      }

      // 3. create golden report document
      report = engine.openReportDesign(CHANGED_REPORT_DESIGN);
      task = engine.createRunTask(report);
      try {
        task.run(CHANGED_REPORT_DOCUMENT);
      } finally {
        task.close();
      }
      IReportDocument goldenDocument = engine.openReportDocument(CHANGED_REPORT_DOCUMENT);
      try {
        IReportDocument ivDocument =
            engine.openReportDocument(null, new ArchiveReader(view), new HashMap());

        try {
          // 5. compare two report document
          compare(goldenDocument, ivDocument);
        } finally {
          ivDocument.close();
        }
      } finally {
        goldenDocument.close();
      }
    } finally {
      view.close();
    }
  }
Esempio n. 3
0
 protected void compare(IReportDocument src, IReportDocument tgt) throws Exception {
   assertTrue(src.getPageCount() == tgt.getPageCount());
   long pageCount = src.getPageCount();
   for (long index = 1; index <= pageCount; index++) {
     String golden = renderPage(src, index);
     String target = renderPage(tgt, index);
     /* remove auto-generated bookmark */
     Pattern p = Pattern.compile("\"AUTOGENBOOKMARK.*\"");
     Matcher m = p.matcher(golden);
     while (m.find()) {
       golden = golden.substring(0, m.start() + 1) + golden.substring(m.end() - 1);
       m = p.matcher(golden);
     }
     m = p.matcher(target);
     while (m.find()) {
       target = target.substring(0, m.start() + 1) + target.substring(m.end() - 1);
       m = p.matcher(target);
     }
     assertEquals(golden, target);
   }
 }
Esempio n. 4
0
  /** Заполнение отчёта */
  private void fillReport(RptMain report, RptProperties properties) {
    String reportDoc = generateReportFileName(report, properties);

    IReportDocument rd = null;
    byte[] reportResult = null;

    try {
      IRunTask runTask = engine.createRunTask(design);
      setupEngineTask(runTask, properties);
      try {
        runTask.run(reportDoc);
      } finally {
        runTask.close();
      }

      rd = engine.openReportDocument(reportDoc);

      IRenderTask rendTask = engine.createRenderTask(rd);
      setupRenderTask(rendTask, properties);

      try {
        rendTask.render();

        reportResult =
            ((ByteArrayOutputStream) rendTask.getRenderOption().getOutputStream()).toByteArray();
      } finally {
        rendTask.close();
      }
    } catch (EngineException e) {
      if (e.getCause() instanceof ApplicationException) throw (ApplicationException) e.getCause();
      else throw new ReportException(Messages.getInstance().getMessage(Messages.BIRT_ERROR), e);
    } finally {
      if (rd != null) rd.close();
      File f = new File(reportDoc);
      f.delete();
      f = null;
    }

    showReport(report, reportResult, properties);
  }
Esempio n. 5
0
 protected String renderPage(IReportDocument doc, long pageNo) throws Exception {
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   assertTrue(pageNo <= doc.getPageCount());
   IRenderTask renderTask = engine.createRenderTask(doc);
   try {
     HTMLRenderOption options = new HTMLRenderOption();
     options.setOutputFormat("html");
     options.setOutputStream(buffer);
     renderTask.setRenderOption(options);
     renderTask.setPageNumber((long) pageNo);
     renderTask.render();
     List errors = renderTask.getErrors();
     assertEquals(0, errors.size());
   } finally {
     renderTask.close();
   }
   return new String(buffer.toString("UTF-8"));
 }
  @SuppressWarnings("unchecked")
  protected void renderMergedOutputModel(
      Map<String, Object> modelData, HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    FileInputStream fis = null;
    IReportRunnable runnable = null;
    IReportDocument document = null;
    try {

      if (this.reportParameters == null) this.reportParameters = new HashMap<String, Object>();

      for (String k : modelData.keySet()) this.reportParameters.put(k, modelData.get(k));

      // 2) reportName property
      // 1) report name parameter is available, use that

      String reportName;
      reportName =
          StringUtils.hasText(this.reportName)
              ? this.reportName
              : request.getParameter(this.reportNameRequestParameter); // 'cat'
      String fullReportName = canonicalizeName(reportName);

      String documentName;
      documentName =
          StringUtils.hasText(this.documentName)
              ? this.documentName
              : request.getParameter(this.documentNameRequestParameter); // 'cat'
      String fullDocumentName = canonicalizeDocName(documentName);
      if (documentName == null) {
        fullDocumentName = reportName.replaceAll(".rptdesign", ".rptdocument");
      }

      String format;
      if (this.reportOutputFormat != null) {
        format = this.reportOutputFormat;
      } else {
        format = request.getParameter(this.reportFormatRequestParameter);
      }
      ServletContext sc =
          request.getServletContext(); // / avoid creating an HTTP session if possible.

      if (format == null) {
        format = "html";
      }

      Map<String, Object> mapOfOptions = new HashMap<String, Object>();
      mapOfOptions.put(
          IModuleOption.RESOURCE_FOLDER_KEY,
          birtViewResourcePathCallback.resourceDirectory(sc, request, reportName));
      mapOfOptions.put(IModuleOption.PARSER_SEMANTIC_CHECK_KEY, Boolean.FALSE);

      // set content type
      String contentType = birtEngine.getMIMEType(format);
      response.setContentType(contentType);
      setContentType(contentType);

      Map<String, Object> appContextMap = new HashMap<String, Object>();
      appContextMap.put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request);

      if (this.dataSource != null) {
        appContextMap.put(IConnectionFactory.PASS_IN_CONNECTION, this.dataSource.getConnection());

        if (this.closeDataSourceConnection)
          appContextMap.put(IConnectionFactory.CLOSE_PASS_IN_CONNECTION, Boolean.TRUE);
      }

      IEngineTask task = null;
      String pathForReport =
          birtViewResourcePathCallback.pathForReport(sc, request, fullReportName);
      fis = new FileInputStream(pathForReport);
      runnable = birtEngine.openReportDesign(fullReportName, fis, mapOfOptions);

      if (runnable != null && this.taskType == AbstractSingleFormatBirtView.RUNRENDERTASK) {
        task = birtEngine.createRunAndRenderTask(runnable);
        task.setParameterValues(discoverAndSetParameters(runnable, request));
        IRunAndRenderTask runAndRenderTask = (IRunAndRenderTask) task;
        IRenderOption options = null == this.renderOption ? new RenderOption() : this.renderOption;
        options.setActionHandler(actionHandler);
        IRenderOption returnedRenderOptions =
            renderReport(
                modelData,
                request,
                response,
                this.birtViewResourcePathCallback,
                appContextMap,
                reportName,
                format,
                options);
        for (String k : appContextMap.keySet())
          runAndRenderTask.getAppContext().put(k, appContextMap.get(k));
        runAndRenderTask.setRenderOption(returnedRenderOptions);
        runAndRenderTask.run();
        runAndRenderTask.close();
      } else {

        // Run then Render
        if (runnable != null) {
          task = birtEngine.createRunTask(runnable);
          task.setParameterValues(discoverAndSetParameters(runnable, request));
          IRunTask runTask = (IRunTask) task;
          for (String k : appContextMap.keySet())
            runTask.getAppContext().put(k, appContextMap.get(k));
          String pathForDocument =
              birtViewResourcePathCallback.pathForDocument(sc, request, fullDocumentName);
          runTask.run(pathForDocument);
          runTask.close();
          document = birtEngine.openReportDocument(fullDocumentName, pathForDocument, mapOfOptions);
          task = birtEngine.createRenderTask(document);
          IRenderTask renderTask = (IRenderTask) task;
          IRenderOption options =
              null == this.renderOption ? new RenderOption() : this.renderOption;
          options.setActionHandler(actionHandler);
          IRenderOption returnedRenderOptions =
              renderReport(
                  modelData,
                  request,
                  response,
                  this.birtViewResourcePathCallback,
                  appContextMap,
                  reportName,
                  format,
                  options);
          for (String k : appContextMap.keySet())
            renderTask.getAppContext().put(k, appContextMap.get(k));
          if (renderRange != null) {

            renderTask.setPageRange(renderRange);
          }
          renderTask.setRenderOption(returnedRenderOptions);
          renderTask.render();
          renderTask.close();
          document.close();
        }
      }

    } catch (Throwable th) {
      throw new RuntimeException(th); // nothing useful to do here
    } finally {
      if (null != fis) IOUtils.closeQuietly(fis);
      if (null != document) document.close();
    }
  }