Esempio n. 1
0
  protected JRBaseParameter(JRParameter parameter, JRBaseObjectFactory factory) {
    factory.put(parameter, this);

    name = parameter.getName();
    description = parameter.getDescription();
    valueClassName = parameter.getValueClassName();
    nestedTypeName = parameter.getNestedTypeName();
    isSystemDefined = parameter.isSystemDefined();
    isForPrompting = parameter.isForPrompting();

    defaultValueExpression = factory.getExpression(parameter.getDefaultValueExpression());

    propertiesMap = parameter.getPropertiesMap().cloneProperties();
  }
Esempio n. 2
0
  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;
  }
  @SuppressWarnings("unchecked")
  public void recalculateKeys() {

    List l = (List) lock();
    l.clear();
    if (IReportManager.getPreferences().getBoolean("filter_parameters", false)) {
      List paramsAll = dataset.getParametersList();
      for (int i = 0; i < paramsAll.size(); ++i) {
        JRParameter p = (JRParameter) paramsAll.get(i);
        if (!p.isSystemDefined()) {
          l.add(p);
        }
      }
    } else {
      l.addAll(dataset.getParametersList());
    }

    if (getNode() != null && getNode() instanceof ParametersNode) {
      if (((ParametersNode) getNode()).isSort()) {
        // Order elements by name...
        Object[] parameters = l.toArray();
        Arrays.sort(
            parameters,
            new Comparator() {

              public int compare(Object o1, Object o2) {
                return ((JRDesignParameter) o1)
                    .getName()
                    .compareToIgnoreCase(((JRDesignParameter) o2).getName());
              }
            });
        l.clear();
        l.addAll(Arrays.asList(parameters));
      }
    }

    update();
  }