public Map<String, String> getJasperExportParameters() {
    try {
      String format = getFormat();
      if (JasperReportConstants.FORMAT_XLS.equals(format)) {
        HttpServletRequest request = ServletActionContext.getRequest();
        String reportId = request.getParameter("report");
        File targetJasperFile = getTargetJasperFile(reportId);
        JasperReport jasperReport = (JasperReport) JRLoader.loadObject(targetJasperFile);

        // 为了方便模板设计和生产环境部署,扩展提供一个PROPERTY_WORKBOOK_TEMPLATE_FILENAME参数
        // 如果在模板文件中定义此参数值,框架会用此文件名转换为对应和jasper文件所在同路径的绝对路径去覆盖模板中PROPERTY_WORKBOOK_TEMPLATE参数值
        JRPropertiesMap properties = jasperReport.getPropertiesMap();
        String xlsWorkbookTemplateFilename =
            properties.getProperty(PROPERTY_WORKBOOK_TEMPLATE_FILENAME);
        if (StringUtils.isNotBlank(xlsWorkbookTemplateFilename)) {
          String xlsWorkbookTemplateFilepath =
              getWebRootDir()
                  + getRelativeJasperFilePath()
                  + File.separator
                  + xlsWorkbookTemplateFilename;
          logger.debug(
              "Overwrite jasper property: {}={}",
              JRXlsAbstractExporter.PROPERTY_WORKBOOK_TEMPLATE,
              xlsWorkbookTemplateFilepath);
          exportParameters.put(
              JRXlsAbstractExporter.PROPERTY_WORKBOOK_TEMPLATE, xlsWorkbookTemplateFilepath);
        }
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new WebException(e.getMessage(), e);
    }
    return exportParameters;
  }
  protected void initSubreportFiller(DatasetExpressionEvaluator evaluator) throws JRException {
    if (log.isDebugEnabled()) {
      log.debug("Fill " + filler.fillerId + ": creating subreport filler");
    }

    switch (jasperReport.getPrintOrderValue()) {
      case HORIZONTAL:
        {
          subreportFiller = new JRHorizontalFiller(jasperReport, evaluator, this);
          break;
        }
      case VERTICAL:
        {
          subreportFiller = new JRVerticalFiller(jasperReport, evaluator, this);
          break;
        }
      default:
        {
          throw new JRRuntimeException(
              "Unkown print order " + jasperReport.getPrintOrderValue().getValue() + ".");
        }
    }

    runner = getRunnerFactory().createSubreportRunner(this, subreportFiller);
    subreportFiller.setSubreportRunner(runner);
  }
 protected Map<String, Object> evaluateParameterValues(byte evaluation) throws JRException {
   return getParameterValues(
       filler,
       getParametersMapExpression(),
       getParameters(),
       evaluation,
       false,
       jasperReport.getResourceBundle() != null, // hasResourceBundle
       jasperReport.getFormatFactoryClass() != null // hasFormatFactory
       );
 }
  protected void verifyBandHeights() throws JRException {
    if (!filler.fillContext.isIgnorePagination()) {
      int pageHeight;
      int topMargin = jasperReport.getTopMargin();
      int bottomMargin = jasperReport.getBottomMargin();

      JRBaseFiller parentFiller = filler;
      do {
        // set every time, so at the end it will be the master page height
        pageHeight = parentFiller.jasperReport.getPageHeight();

        // sum parent page margins
        topMargin += parentFiller.jasperReport.getTopMargin();
        bottomMargin += parentFiller.jasperReport.getBottomMargin();

        parentFiller = parentFiller.parentFiller;
      } while (parentFiller != null);

      List<JRValidationFault> brokenRules = new ArrayList<JRValidationFault>();
      JRVerifier.verifyBandHeights(brokenRules, jasperReport, pageHeight, topMargin, bottomMargin);

      if (!brokenRules.isEmpty()) {
        throw new JRValidationException(
            "Band height validation for subreport \""
                + jasperReport.getName()
                + "\" failed in the current page context "
                + "(height = "
                + pageHeight
                + ", top margin = "
                + topMargin
                + ", bottom margin = "
                + bottomMargin
                + ") : ",
            brokenRules);
      } else if (log.isDebugEnabled()) {
        log.debug(
            "Band height validation for subreport \""
                + jasperReport.getName()
                + "\" succeeded in the current page context "
                + "(height = "
                + pageHeight
                + ", top margin = "
                + topMargin
                + ", bottom margin = "
                + bottomMargin
                + ")");
      }
    }
  }
  public Map<String, Object> getJasperReportParameters() {
    Map<String, Object> jasperReportParameters = Maps.newHashMap();
    try {
      HttpServletRequest request = ServletActionContext.getRequest();
      String reportId = request.getParameter("report");
      File targetJasperFile = getTargetJasperFile(reportId);
      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(targetJasperFile);

      // 根据模板定义转换处理传入参数类型
      JRParameter[] params = jasperReport.getParameters();
      for (Map.Entry<String, Object> val : reportParameters.entrySet()) {
        String key = val.getKey();

        if (val.getValue() == null) {
          continue;
        }
        String[] vals = (String[]) val.getValue();
        for (JRParameter param : params) {
          if (!param.isSystemDefined() && param.isForPrompting()) {
            String name = param.getName();
            Class<?> clazz = param.getValueClass();
            if (!name.equals(key)) {
              continue;
            }
            // TODO: 先初步添加集合处理,后续逐步添加数字、日期等类型转换处理
            if (Collection.class.isAssignableFrom(clazz)) {
              // 集合类型参数处理,TODO: 可以考虑进一步添加param.getNestedType()处理
              jasperReportParameters.put(key, vals);
            } else {
              // 其余情况把参数转换为普通字符串传入
              jasperReportParameters.put(val.getKey(), StringUtils.join(vals, ","));
            }
          }
        }
      }

      // 设置一些缺省属性供模板内部使用
      jasperReportParameters.put("_RPT_ID", reportId);
      jasperReportParameters.put("_RPT_FORMAT", this.getFormat());
      String url = request.getRequestURL().toString();
      logger.debug("Report URL: " + url);
      jasperReportParameters.put("_RPT_URL", url);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new WebException(e.getMessage(), e);
    }
    return jasperReportParameters;
  }
 public JREvaluator loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab)
     throws JRException {
   JRReportCompileData reportCompileData = (JRReportCompileData) jasperReport.getCompileData();
   String unitName = reportCompileData.getUnitName(jasperReport, crosstab);
   Serializable compileData = reportCompileData.getCrosstabCompileData(crosstab);
   return loadEvaluator(compileData, unitName);
 }
 public JREvaluator loadEvaluator(JasperReport jasperReport, JRDataset dataset)
     throws JRException {
   JRReportCompileData reportCompileData = (JRReportCompileData) jasperReport.getCompileData();
   String unitName = reportCompileData.getUnitName(jasperReport, dataset);
   Serializable compileData = reportCompileData.getDatasetCompileData(dataset);
   return loadEvaluator(compileData, unitName);
 }
Beispiel #8
0
  public List<ReportParameter> getReportParameters() throws ClassNotFoundException, IOException {
    if (reportParameters == null) {
      final JasperReport[] jra = reportCard.getRichReportJRA();
      final JasperReport masterReport = jra[0];
      reportParameters = new LinkedList<ReportParameter>();

      final JRParameter[] jrParameters = masterReport.getParameters();
      for (int i = 0; i < jrParameters.length; i++) {
        if (jrParameters[i].isForPrompting() && !jrParameters[i].isSystemDefined()) {
          final JRParameter jrParameter = jrParameters[i];
          final ReportParameter rp = ReportParameter.parseJrParameter(jrParameter);
          reportParameters.add(rp);
        }
      }
    }
    return reportParameters;
  }
Beispiel #9
0
  private static JRDataset findSubdataset(JRDatasetRun datasetRun, JasperReport report) {
    JRDataset[] datasets = report.getDatasets();
    JRDataset reportDataset = null;
    if (datasets != null) {
      for (int i = 0; i < datasets.length; i++) {
        if (datasetRun.getDatasetName().equals(datasets[i].getName())) {
          reportDataset = datasets[i];
          break;
        }
      }
    }

    if (reportDataset == null) {
      throw new JRRuntimeException(
          "Could not find subdataset named \""
              + datasetRun.getDatasetName()
              + "\" in report \""
              + report.getName()
              + "\"");
    }
    return reportDataset;
  }
 /** @deprecated Replaced by {@link JasperCompileManager#loadEvaluator(JasperReport)}. */
 public JREvaluator loadEvaluator(JasperReport jasperReport) throws JRException {
   return loadEvaluator(jasperReport, jasperReport.getMainDataset());
 }
 /**
  * Returns the name of the expression evaluator unit for a dataset of a report.
  *
  * @param report the report
  * @param dataset the dataset
  * @return the generated expression evaluator unit name
  */
 public static String getUnitName(JasperReport report, JRDataset dataset) {
   return getUnitName(report, dataset, report.getCompileNameSuffix());
 }
 /**
  * Returns the name of the expression evaluator unit for a crosstab of a report.
  *
  * @param report the report
  * @param crosstab the crosstab
  * @return the generated expression evaluator unit name
  */
 public static String getUnitName(JasperReport report, JRCrosstab crosstab) {
   return getUnitName(report, crosstab.getId(), report.getCompileNameSuffix());
 }