Package org.eclipse.birt.report.engine.api

Examples of org.eclipse.birt.report.engine.api.IRunAndRenderTask


        String helperName = delegator.getGroupHelperName(delegatorGroupHelperName);    // gets the helper (localderby, localmysql, localpostgres, etc.) for your entity group org.ofbiz
        Connection connection = ConnectionFactory.getConnection(helperName);
        engine.getConfig().getAppContext().put("OdaJDBCDriverPassInConnection", connection);
        */

        IRunAndRenderTask task = engine.createRunAndRenderTask(design);
        if (birtLocale != null) {
            Debug.logInfo("Set birt locale:" + birtLocale, module);
            task.setLocale(birtLocale);
        }

        // set parameters if exists
        Map<String, Object> parameters = UtilGenerics.cast(context.get(BirtWorker.BIRT_PARAMETERS));
        if (parameters != null) {
            Debug.logInfo("Set birt parameters:" + parameters, module);
            task.setParameterValues(parameters);
        }

        // set output options
        RenderOption options = new RenderOption();
        if ("text/html".equalsIgnoreCase(contentType)) {
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_HTML);
        } else if ("application/pdf".equalsIgnoreCase(contentType)) {
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_PDF);
        } else if ("application/vnd.ms-word".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("doc");
        else if ("application/vnd.ms-excel".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("xls");
        } else if ("application/vnd.ms-powerpoint".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("ppt");
        } else {
            throw new GeneralException("Unknown content type : " + contentType);
        }

        if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_HTML)) {
            // set html render options
            HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
            htmlOptions.setImageDirectory(birtImageDirectory);
            htmlOptions.setBaseImageURL(birtImageDirectory);
            options.setImageHandler(imageHandler);
        } else if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_PDF)) {
            // set pdf render options
            PDFRenderOption pdfOptions = new PDFRenderOption(options);
            pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, Boolean.TRUE );
        } else if (options.getOutputFormat().equalsIgnoreCase("xls")) {
            // set excel render options
            new EXCELRenderOption(options);
        }
        options.setOutputStream(output);
        task.setRenderOption(options);

        // run report
        Debug.logInfo("Birt's locale is: " + task.getLocale(), module);
        Debug.logInfo("Run report's task", module);
        task.run();
        task.close();
    }
View Full Code Here


             birtImageDirectory = "/";
        }
        Debug.logInfo("Get report engine", module);
        IReportEngine engine = BirtFactory.getReportEngine();

        IRunAndRenderTask task = engine.createRunAndRenderTask(design);
        if (birtLocale != null) {
            Debug.logInfo("Set BIRT locale:" + birtLocale, module);
            task.setLocale(birtLocale);
        }

        // set parameters if exists
        Map<String, Object> parameters = UtilGenerics.cast(context.get(BirtWorker.BIRT_PARAMETERS));
        if (parameters != null) {
            Debug.logInfo("Set BIRT parameters:" + parameters, module);
            task.setParameterValues(parameters);
        }

        // set output options
        RenderOption options = new RenderOption();
        if ("text/html".equalsIgnoreCase(contentType)) { // HTML
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_HTML);
            HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
            htmlOptions.setImageDirectory(birtImageDirectory);
            htmlOptions.setBaseImageURL(birtImageDirectory);
            options.setImageHandler(imageHandler);
        } else if ("application/postscript".equalsIgnoreCase(contentType)) { // Post Script
            options.setOutputFormat("postscript");
        } else if ("application/pdf".equalsIgnoreCase(contentType)) { // PDF
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_PDF);
            PDFRenderOption pdfOptions = new PDFRenderOption(options);
            pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, Boolean.TRUE );
        } else if ("application/vnd.ms-word".equalsIgnoreCase(contentType)) { // MS Word
            options.setOutputFormat("doc");
        else if ("application/vnd.ms-excel".equalsIgnoreCase(contentType)) { // MS Excel
            options.setOutputFormat("xls");
            new EXCELRenderOption(options);
        } else if ("application/vnd.ms-powerpoint".equalsIgnoreCase(contentType)) { // MS Power Point
            options.setOutputFormat("ppt");
        } else if ("application/vnd.oasis.opendocument.text".equalsIgnoreCase(contentType)) { // Open Document Text
            options.setOutputFormat("odt");
        } else if ("application/vnd.oasis.opendocument.spreadsheet".equalsIgnoreCase(contentType)) { // Open Document Spreadsheet
            options.setOutputFormat("ods");
        } else if ("application/vnd.oasis.opendocument.presentation".equalsIgnoreCase(contentType)) { // Open Document Presentation
            options.setOutputFormat("odp");
        } else {
            throw new GeneralException("Unknown content type : " + contentType);
        }

        options.setOutputStream(output);
        task.setRenderOption(options);

        // run report
        Debug.logInfo("BIRT's locale is: " + task.getLocale(), module);
        Debug.logInfo("Run report's task", module);
        task.run();
        task.close();
    }
View Full Code Here

      else
      {
        log.error("Export type not yet implemented: " + input.getExportType());
      }
     
      IRunAndRenderTask task = engine.createRunAndRenderTask(design);         
      task.setRenderOption(renderOption);
      task.setParameterValues(parameters);     
      task.validateParameters();
     
      if (input.getLocale() != null)
      {
        task.setLocale(input.getLocale());
      }
     
      if (input.getXmlInput() != null)
      {
        ByteArrayInputStream stream = new ByteArrayInputStream(input.getXmlInput().getBytes());         
        task.getAppContext().put("org.eclipse.datatools.enablement.oda.xml.inputStream", stream);       
            }
     
      log.info("Generating BIRT report: " + report.getName());
     
      task.run();           
      task.close();
     
      log.info("Finished Generating BIRT report: " + report.getName());
     
      output.setContent(out.toByteArray());
    }
View Full Code Here

        String helperName = delegator.getGroupHelperName(delegatorGroupHelperName);    // gets the helper (localderby, localmysql, localpostgres, etc.) for your entity group org.ofbiz
        Connection connection = ConnectionFactory.getConnection(helperName);
        engine.getConfig().getAppContext().put("OdaJDBCDriverPassInConnection", connection);
        */

        IRunAndRenderTask task = engine.createRunAndRenderTask(design);
        if (birtLocale != null) {
            Debug.logInfo("Set birt locale:" + birtLocale, module);
            task.setLocale(birtLocale);
        }

        // set parameters if exists
        Map<String, Object> parameters = UtilGenerics.cast(context.get(BirtWorker.BIRT_PARAMETERS));
        if (parameters != null) {
            Debug.logInfo("Set birt parameters:" + parameters, module);
            task.setParameterValues(parameters);
        }

        // set output options
        RenderOption options = new RenderOption();
        if ("text/html".equalsIgnoreCase(contentType)) {
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_HTML);
        } else if ("application/pdf".equalsIgnoreCase(contentType)) {
            options.setOutputFormat(RenderOption.OUTPUT_FORMAT_PDF);
        } else if ("application/vnd.ms-word".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("doc");
        else if ("application/vnd.ms-excel".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("xls");
        } else if ("application/vnd.ms-powerpoint".equalsIgnoreCase(contentType)) {
            options.setOutputFormat("ppt");
        } else {
            throw new GeneralException("Unknown content type : " + contentType);
        }

        if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_HTML)) {
            // set html render options
            HTMLRenderOption htmlOptions = new HTMLRenderOption(options);
            htmlOptions.setImageDirectory(birtImageDirectory);
            htmlOptions.setBaseImageURL(birtImageDirectory);
            options.setImageHandler(imageHandler);
        } else if (options.getOutputFormat().equalsIgnoreCase(RenderOption.OUTPUT_FORMAT_PDF)) {
            // set pdf render options
            PDFRenderOption pdfOptions = new PDFRenderOption(options);
            pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW, Boolean.TRUE );
        } else if (options.getOutputFormat().equalsIgnoreCase("xls")) {
            // set excel render options
            EXCELRenderOption excelOptions = new EXCELRenderOption(options);
        }
        options.setOutputStream(output);
        task.setRenderOption(options);

        // run report
        Debug.logInfo("Birt's locale is: " + task.getLocale(), module);
        Debug.logInfo("Run report's task", module);
        task.run();
        task.close();
    }
View Full Code Here

            InputStream reportInputStream = ChartOfAccountReport.class
                    .getClassLoader().getResourceAsStream(REPORT_NAME);
            IReportRunnable report = reportEngine
                    .openReportDesign(reportInputStream);

            IRunAndRenderTask task = reportEngine
                    .createRunAndRenderTask(report);
            task.getAppContext().put(
                    "org.eclipse.birt.report.data.oda.xml.inputStream",
                    xmlStream);

            HTMLRenderOption options = new HTMLRenderOption();
            options.setOutputStream((OutputStream) context.get("outputStream"));
            options.setOutputFormat("html");
            options.setEmbeddable(false);

            task.setRenderOption(options);
            task.run();
            task.close();

            result = ServiceUtil.returnSuccess("Render Report Complete");
        } catch (EngineException e) {
            e.printStackTrace();
        }
View Full Code Here

            InputStream reportInputStream = ChartOfAccountReport.class
                    .getClassLoader().getResourceAsStream(REPORT_NAME);
            IReportRunnable report = reportEngine
                    .openReportDesign(reportInputStream);

            IRunAndRenderTask task = reportEngine
                    .createRunAndRenderTask(report);
            task.getAppContext().put(
                    "org.eclipse.birt.report.data.oda.xml.inputStream",
                    xmlStream);

            HTMLRenderOption options = new HTMLRenderOption();
            options.setOutputStream((OutputStream) context.get("outputStream"));
            options.setOutputFormat("html");
            options.setEmbeddable(false);

            task.setRenderOption(options);
            task.run();
            task.close();

            result = ServiceUtil.returnSuccess("Render Report Complete");
        } catch (EngineException e) {
            e.printStackTrace();
        }
View Full Code Here

            InputStream reportInputStream = ChartOfAccountReport.class
                    .getClassLoader().getResourceAsStream(REPORT_NAME);
            IReportRunnable report = reportEngine
                    .openReportDesign(reportInputStream);

            IRunAndRenderTask task = reportEngine
                    .createRunAndRenderTask(report);
            task.getAppContext().put(
                    "org.eclipse.birt.report.data.oda.xml.inputStream",
                    xmlStream);

            HTMLRenderOption options = new HTMLRenderOption();
            options.setOutputStream((OutputStream) context.get("outputStream"));
            options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
            options.setEmbeddable(false);

            task.setRenderOption(options);
            task.run();
            task.close();

            result = ServiceUtil.returnSuccess("Render Report Complete");
        } catch (EngineException e) {
            e.printStackTrace();
        }
View Full Code Here

    String outputFormat = request.getParameter("outputType");   
    logger.debug("outputType -- [" + outputFormat + "]");
   
    logger.debug( "runReport(): report design opened successfully.");
    // Create task to run and render the report,
    IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design);
    task.setLocale(locale);
    logger.debug( "runReport(): RunAndRenderTask created successfully.");
    // Set parameters for the report
    Map reportParams = findReportParams(request, design);

    String requestConnectionName = (String) request.getParameter(CONNECTION_NAME);
    logger.debug("requestConnectionName:" + requestConnectionName);
    IDataSource ds = findDataSource(request.getSession(), userId, documentId,requestConnectionName);
    if (ds != null) {
      logger.debug("DataSource founded.");
   
      if (ds.checkIsJndi() ) {
       
        if (ds.checkIsMultiSchema()){
          String schema=null;
          try {
              String attrname=ds.getSchemaAttribute();
              if (attrname!=null) schema = (String)profile.getUserAttribute(attrname);           
          } catch (EMFInternalError e) {
            logger.error("Cannot retrive ENTE", e);
          }
          reportParams.put("connectionName", ds.getJndi()+schema);
        }else{
          reportParams.put("connectionName", ds.getJndi());
        }

       
      } else {
        reportParams.put("driver", ds.getDriver());
        reportParams.put("url", ds.getUrlConnection());
        reportParams.put("user", ds.getUser());
        reportParams.put("pwd", (ds.getPwd().equals("")) ? " " : ds.getPwd());

      }
    }

    reportParams.put("KpiDSXmlUrl", kpiUrl);
   
    //gets static resources with SBI_RESOURCE_PATH system's parameter
    String resPathJNDI = EnginConf.getInstance().getResourcePath();
    String resourcePath = resPathJNDI+"/img/";
    String entity=(String)reportParams.get(SpagoBIConstants.SBI_ENTITY);
    // IF exist an ENTITY  parameter concat to resourcePath
    if (entity!=null && entity.length()>0){
      resourcePath=resourcePath.concat(entity+"/");
    }
    logger.debug("SetUp resourcePath:"+resourcePath);
    reportParams.put("SBI_RESOURCE_PATH", resourcePath);

    task.setParameterValues(reportParams);
    task.validateParameters();

    String templateFileName = request.getParameter("template_file_name");
    logger.debug("templateFileName -- [" + templateFileName + "]");
    if (templateFileName == null || templateFileName.trim().equals(""))
      templateFileName = "report";
    IRenderOption renderOption = null;

    if (outputFormat != null && outputFormat.equalsIgnoreCase(IBirtConstants.PDF_RENDER_FORMAT)) {
      renderOption = new PDFRenderOption();
      renderOption.setOutputFormat(IBirtConstants.PDF_RENDER_FORMAT);
      //renderOption.setSupportedImageFormats("JPG;jpg;PNG;png;BMP;bmp;SVG;svg;GIF;gif");
      response.setContentType("application/pdf");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".pdf");     
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase(IBirtConstants.HTML_RENDER_FORMAT)) {
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat(IBirtConstants.HTML_RENDER_FORMAT);
      response.setHeader("Content-Type", "text/html");
      response.setContentType("text/html");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase(IBirtConstants.DOC_RENDER_FORMAT)) {
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat(IBirtConstants.DOC_RENDER_FORMAT);
      // renderOption.setOutputFileName(templateFileName + ".doc");
      response.setContentType("application/msword");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".doc");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase(RTF_FORMAT)) {
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat(RTF_FORMAT);
      response.setContentType("application/rtf");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".rtf");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase("xls")) {
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat("xls");
      // renderOption.setOutputFileName(templateFileName + ".xls");
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".xls");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase("ppt")) {
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat("ppt");
      // renderOption.setOutputFileName(templateFileName + ".ppt");
      response.setContentType("application/vnd.ms-powerpoint");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".ppt");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase(IBirtConstants.POSTSCRIPT_RENDER_FORMAT)) {
      renderOption = new PDFRenderOption();
      renderOption.setOutputFormat(IBirtConstants.POSTSCRIPT_RENDER_FORMAT);
      // renderOption.setOutputFileName(templateFileName + ".ps");
      response.setHeader("Content-disposition", "inline; filename=" + templateFileName + ".ps");
    } else if (outputFormat != null && outputFormat.equalsIgnoreCase(DataExtractionParameterUtil.EXTRACTION_FORMAT_CSV)) {
      logger.debug(" Output format parameter is CSV. Create document obj .");
      prepareCSVRender(reportParams, request, design, userId, documentId, profile, kpiUrl, response);
      return;
     
    }else {
      logger.debug(" Output format parameter not set or not valid. Using default output format: HTML.");
      outputFormat = IBirtConstants.HTML_RENDER_FORMAT;
      renderOption = prepareHtmlRenderOption(servletContext, request);
      renderOption.setOutputFormat(IBirtConstants.HTML_RENDER_FORMAT);
      response.setContentType("text/html");
      response.setHeader("Content-Type", "text/html");
    }

    Map userProfileAttrs = UserProfileUtils.getProfileAttributes( profile );
    Map context = getTaskContext(userId, params, request, resPathJNDI, userProfileAttrs);
    //Map context = BirtUtility.getAppContext(request);
    task.setAppContext(context);
    renderOption.setOutputStream((OutputStream) response.getOutputStream());
    task.setRenderOption(renderOption);
   
    // setting HTML header if output format is HTML: this is necessary in order to inject the document.domain directive
    // commented by Davide Zerbetto on 12/10/2009: there are problems with MIF (Ext ManagedIFrame library) library
    /*
    if (outputFormat.equalsIgnoreCase(IBirtConstants.HTML_RENDER_FORMAT)) {
      ((HTMLRenderOption) renderOption).setEmbeddable(true);
      injectHTMLHeader(response);
    }
    */
   
    try {
      task.run();
    } catch(Exception e) {
      logger.error("Error while running the report: " + e);
    }
    task.close();
   
    // commented by Davide Zerbetto on 12/10/2009: there are problems with MIF (Ext ManagedIFrame library) library
    /*
    if (outputFormat.equalsIgnoreCase(IBirtConstants.HTML_RENDER_FORMAT)) {
      injectHTMLFooter(response);
View Full Code Here

        try {
            LOG.info("report path:"+reportPath);
            reportPath=FileUtils.getAbsolutePath(reportPath);
            LOG.info("report path:"+reportPath);
            design = birtReportEngine.openReportDesign(reportPath);
            IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design);

            task.getAppContext().put("BIRT_VIEWER_HTTPSERVLET_REQUEST", req );
            task.setParameterValue("title", "用户图形报表");
            task.setParameterValue("tip", "测试用户报表");
           
            HTMLRenderOption options = new HTMLRenderOption();
            options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            options.setOutputStream(out);
            options.setImageHandler(new HTMLServerImageHandler());
            options.setBaseImageURL(SystemListener.getContextPath() + "/platform/reports/images");
            options.setImageDirectory(FileUtils.getAbsolutePath("/platform/reports/images"));
            task.setRenderOption(options);

            task.run();
            task.close();
            total=(float)Runtime.getRuntime().totalMemory()/1000000 - total;
            LOG.info("完成渲染报表,耗时:"+ConvertUtils.getTimeDes(System.currentTimeMillis()-start)+" ,耗费内存:"+total+"M");
            return out.toByteArray();
        } catch (EngineException | NumberFormatException e) {
            LOG.error("输出报表出错",e);
View Full Code Here

TOP

Related Classes of org.eclipse.birt.report.engine.api.IRunAndRenderTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.