/** Test passing reportContext */
 @SuppressWarnings("unchecked")
 @Test
 public void testExecute1() {
   try {
     final IReportEngine reportEngine = ReportEngine.getReportEngine();
     final InputStream is =
         this.getClass().getResourceAsStream("/reports/test_display_parameters.rptdesign");
     final IReportRunnable design = reportEngine.openReportDesign(is);
     final IGetParameterDefinitionTask paramTask =
         reportEngine.createGetParameterDefinitionTask(design);
     List<EngineException> errors = null;
     try {
       final IRunAndRenderTask rrTask = reportEngine.createRunAndRenderTask(design);
       final Map<String, Object> appContext = rrTask.getAppContext();
       final ClassLoader classLoader = getClass().getClassLoader();
       appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader);
       // rrTask.setAppContext(appContext);
       try {
         final ByteArrayOutputStream os = new ByteArrayOutputStream();
         final RenderOption options = new HTMLRenderOption();
         options.setOutputFormat("HTML");
         options.setOutputStream(os);
         rrTask.setRenderOption(options);
         rrTask.run();
         errors = rrTask.getErrors();
         String output = os.toString("utf-8");
         System.out.println(output);
         Assert.assertTrue(output.indexOf("Australian Collectors, Co.") >= 0);
         Assert.assertTrue(output.indexOf("NewParameter") >= 0);
         Assert.assertTrue(output.indexOf("abc") >= 0);
       } finally {
         rrTask.close();
       }
     } finally {
       paramTask.close();
     }
     if (errors != null) {
       Iterator<EngineException> iterator = errors.iterator();
       if (iterator.hasNext()) {
         EngineException error = iterator.next();
         Assert.fail("Engine exception: " + error.getMessage());
       }
     }
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     Assert.fail(e.toString());
   } catch (BirtException e) {
     e.printStackTrace();
     Assert.fail(e.toString());
   }
 }
Пример #2
0
    @Override
    public IRenderOption getPreferredRenderOption() {
      RenderOption renderOption = new RenderOption();

      renderOption.setEmitterID(getID());
      renderOption.setOutputFormat("odt"); // $NON-NLS-1$

      if (values != null && values.length > 0) {
        for (IOptionValue optionValue : values) {
          if (optionValue != null) {
            renderOption.setOption(
                getRenderOptionName(optionValue.getName()), optionValue.getValue());
          }
        }
      }

      return renderOption;
    }
Пример #3
0
  void doRun() throws EngineException {
    loadScripts();
    // register default parameters and validate
    doValidateParameters();

    setupRenderOption();
    initReportVariable();
    loadDesign();
    prepareDesign();
    startFactory();
    updateRtLFlag();
    startRender();
    try {
      IContentEmitter emitter = createContentEmitter();
      IReportExecutor executor = new ReportExecutor(executionContext);
      executor = new SuppressDuplciateReportExecutor(executor);
      executor = new LocalizedReportExecutor(executionContext, executor);
      executionContext.setExecutor(executor);
      if (ExtensionManager.PAPER_SIZE_PAGINATION.equals(pagination)) {
        LayoutEngine pdfLayoutEmitter =
            new LayoutEngine(emitter, renderOptions, executionContext, 0l);
        emitter = pdfLayoutEmitter;
      }
      initializeContentEmitter(emitter);

      // if we need do the paginate, do the paginate.
      String format = executionContext.getOutputFormat();

      boolean paginate = true;
      if (FORMAT_HTML.equalsIgnoreCase(format)
          || FORMAT_XHTML.equalsIgnoreCase(format)) // $NON-NLS-1$
      {
        HTMLRenderOption htmlOption = new HTMLRenderOption(executionContext.getRenderOption());
        paginate = htmlOption.getHtmlPagination();
      } else {
        RenderOption taskOption = new RenderOption(executionContext.getRenderOption());
        paginate = taskOption.getBooleanOption(IRenderOption.HTML_PAGINATION, true);
      }
      if (ExtensionManager.NO_PAGINATION.equals(pagination)) {
        paginate = false;
      }

      synchronized (this) {
        if (!executionContext.isCanceled()) {
          layoutEngine = createReportLayoutEngine(pagination, renderOptions);
        }
      }

      if (layoutEngine != null) {
        layoutEngine.setLocale(executionContext.getLocale());

        CompositeLayoutPageHandler layoutPageHandler = new CompositeLayoutPageHandler();
        OnPageBreakLayoutPageHandle handle = new OnPageBreakLayoutPageHandle(executionContext);
        layoutPageHandler.addPageHandler(handle);
        layoutPageHandler.addPageHandler(new ContextPageBreakHandler(executionContext));
        if (!ExtensionManager.PAPER_SIZE_PAGINATION.equals(pagination)) {
          layoutPageHandler.addPageHandler(new LayoutPageHandler());
          layoutEngine.setPageHandler(layoutPageHandler);
        } else {
          ((LayoutEngine) emitter).setPageHandler(layoutPageHandler);
        }

        CompositeContentEmitter outputEmitters = new CompositeContentEmitter(format);
        outputEmitters.addEmitter(emitter);
        outputEmitters.addEmitter(handle.getEmitter());

        IReportContent report = executor.execute();
        outputEmitters.start(report);
        layoutEngine.layout(executor, report, outputEmitters, paginate);
        layoutEngine.close();
        outputEmitters.end(report);
      }
      closeRender();
      executionContext.closeDataEngine();
      closeFactory();
    } catch (Throwable t) {
      handleFatalExceptions(t);
    }
  }