Пример #1
0
  public void doRun() {
    try {
      log.info("Export started");

      openDocument(writer);

      // -----------------------------------------------------------------
      // XML
      // -----------------------------------------------------------------

      beforeXML(writer);

      for (XMLHrConverter converter : xmlConverters) {
        converter.write(writer, params);
      }

      afterXML(writer);

      closeDocument(writer);

      StreamUtils.closeZipEntry(zipOutputStream);

      log.info("Export done");
    } catch (Exception ex) {
      ex.printStackTrace();

      throw new RuntimeException("Writing failed" + ex);
    } finally {
      writer.closeWriter();

      StreamUtils.closeOutputStream(zipOutputStream);

      NameMappingUtil.clearMapping();
    }
  }
  @Override
  public String execute() throws Exception {
    HttpServletResponse response = ServletActionContext.getResponse();

    Map<String, String> typeTemplateMap = new HashMap<String, String>();
    typeTemplateMap.put(TYPE_JASPER, TEMPLATE_JASPER);
    typeTemplateMap.put(TYPE_HTML, TEMPLATE_HTML);

    Map<String, String> typeContentTypeMap = new HashMap<String, String>();
    typeContentTypeMap.put(TYPE_JASPER, ContextUtils.CONTENT_TYPE_XML);
    typeContentTypeMap.put(TYPE_HTML, ContextUtils.CONTENT_TYPE_HTML);

    if (type != null & typeTemplateMap.containsKey(type)) {
      String template = typeTemplateMap.get(type);
      String contentType = typeContentTypeMap.get(type);

      ContextUtils.configureResponse(response, contentType, false, template, true);

      StreamUtils.streamcopy(
          new BufferedInputStream(new ClassPathResource(template).getInputStream()),
          new BufferedOutputStream(response.getOutputStream()));
    }

    return SUCCESS;
  }
Пример #3
0
  /** Writes a Jasper Reports representation of the given Grid to the given OutputStream. */
  public static void toJasperReport(Grid grid, Map<String, Object> params, OutputStream out)
      throws Exception {
    if (grid == null) {
      return;
    }

    final StringWriter writer = new StringWriter();

    render(grid, params, writer, JASPER_TEMPLATE);

    String report = writer.toString();

    JasperReport jasperReport =
        JasperCompileManager.compileReport(StreamUtils.getInputStream(report));

    JasperPrint print = JasperFillManager.fillReport(jasperReport, params, grid);

    JasperExportManager.exportReportToPdfStream(print, out);
  }