Exemplo n.º 1
0
  @Override
  public void render(
      final Map<String, ?> model,
      final HttpServletRequest request,
      final HttpServletResponse response)
      throws Exception {
    if (m_view == null) {
      String fileName = getFileName(request);
      response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    } else {
      final String outputParameter = request.getParameter("output");
      m_formatter.setOutput(outputParameter);
    }
    if (model.containsKey("report")) {
      final SystemReportInfo info = (SystemReportInfo) model.get("report");
      LOG.debug("found report = {}", info);
      final OutputStream output;

      if (m_view == null) {
        output = response.getOutputStream();
      } else {
        output =
            new OutputStream() {
              @Override
              public void write(int b) throws IOException {}
            };
      }

      try {
        LOG.debug("beginning output");
        m_formatter.setOutputStream(output);
        m_formatter.begin();

        for (final SystemReportPlugin plugin : info.getPlugins()) {
          LOG.debug("running plugin {}", plugin);
          m_formatter.write(plugin);
          output.flush();
        }

        LOG.debug("finishing output");
        m_formatter.end();
      } catch (final Throwable e) {
        LOG.warn("Error while formatting system report output", e);
        throw new SystemReportException(e);
      } finally {
        IOUtils.closeQuietly(output);
      }
    } else {
      LOG.info("Invalid form input: {}", model);
      throw new SystemReportException("Form input was invalid.");
    }
    LOG.debug("done");
    if (m_view != null) {
      m_view.render(model, request, response);
    }
  }
Exemplo n.º 2
0
 @Override
 public String getContentType() {
   if (m_view != null) return m_view.getContentType();
   if (m_formatter == null) return "application/octet-stream";
   return m_formatter.getContentType();
 }