@Test
  public void testJsonObject() {

    List l = new ArrayList();

    l.add("111");
    l.add("222");

    List ls = new ArrayList();

    ls.add("333");
    ls.add("444");

    JSONObject json = new JSONObject();

    JSONObject jsont = new JSONObject();

    json.put("inName", l);
    json.put("cnName", ls);

    System.out.println(json.toString());
  }
Exemple #2
0
  /**
   * 得到JasperPrint的list.用于一个报表有多页的情况(非循环多页)
   *
   * <p>实现方法:通过读取zip包,将zip包里每一个报表文件进行填充并放入List返回.
   *
   * <p>注意:zip包里报表名命名规则:第一张应该为1.jasper,依次类推;若报表有detail,则在数字后边加上detail如2detail.jasper;
   * 若报表有子报表则命名时后缀为.zip有detail则加,无则不加.
   *
   * @param jasperInStream
   * @param page
   * @param parameters
   * @param detailEntity
   * @param detailCollection
   * @return
   * @throws JRException
   * @throws IOException
   * @throws ParseException
   */
  @SuppressWarnings("unchecked")
  protected List<JasperPrint> getJasperPrintList(
      IRequestCycle cycle,
      InputStream jasperInStream,
      IPage page,
      Map<Object, Object> parameters,
      String detailEntity,
      String detailCollection)
      throws JRException, IOException, ParseException {

    List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();

    int pageNumber = 0;
    JasperPrint jasperPrint = null;
    Object[] jasperName = parameters.keySet().toArray();
    Arrays.sort(jasperName);

    for (int i = 0; i < jasperName.length; i++) {

      jasperInStream = (InputStream) parameters.get(jasperName[i]);
      getJasperParameters(jasperInStream, parameters);
      IPageRooted<Object, Object> activePage = (IPageRooted<Object, Object>) page;

      if (parameters.containsKey(TEMPLATE_PAGE)) {

        InputStream propStream = (InputStream) parameters.get(TEMPLATE_PAGE);
        String jsonParam = getLinkParameter(propStream);
        parameters.remove(TEMPLATE_PAGE);

        if (jsonParam != null) {
          JSONObject json = new JSONObject(jsonParam);

          String activePageName = null;
          if (json.has(PAGE)) {
            activePageName = (String) json.get(PAGE);
            activePage = (IPageRooted<Object, Object>) cycle.getPage(activePageName);
            ((IPageRooted<Object, Object>) activePage)
                .setRootedObject(((IPageRooted<Object, Object>) page).getRootedObject());
            cycle.activate(activePage);
          }
        }
      }

      if (((String) jasperName[i])
          .substring(0, ((String) jasperName[i]).indexOf("."))
          .endsWith(DETAIL)) {

        jasperPrint =
            this.getJasperPrint(
                jasperInStream, activePage, parameters, detailEntity, detailCollection, pageNumber);
      } else {

        jasperPrint =
            this.getJasperPrint(jasperInStream, activePage, parameters, null, null, pageNumber);
      }

      jasperPrintList.add(jasperPrint);

      int pageSize = jasperPrint.getPages().size();

      pageNumber += pageSize; // 将前边的JasperPrint的页数进行记录
    }

    return jasperPrintList;
  }