Examples of JRExporter


Examples of net.sf.jasperreports.engine.JRExporter

                }

                response.setHeader("Content-disposition", tmp.toString());
            }

            JRExporter exporter;

            if (format.equals(FORMAT_PDF)) {
                response.setContentType("application/pdf");
                exporter = new JRPdfExporter();
            } else if (format.equals(FORMAT_CSV)) {
                response.setContentType("text/csv");
                exporter = new JRCsvExporter();
            } else if (format.equals(FORMAT_HTML)) {
                response.setContentType("text/html");

                // IMAGES_MAPS seems to be only supported as "backward compatible" from JasperReports 1.1.0

                Map imagesMap = new HashMap();
                request.getSession(true).setAttribute("IMAGES_MAP", imagesMap);

                exporter = new JRHtmlExporter();
                exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
                exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl);

                // Needed to support chart images:
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint);
            } else if (format.equals(FORMAT_XLS)) {
                response.setContentType("application/vnd.ms-excel");
                exporter = new JRXlsExporter();
            } else if (format.equals(FORMAT_XML)) {
                response.setContentType("text/xml");
                exporter = new JRXmlExporter();
            } else if (format.equals(FORMAT_RTF)) {
                response.setContentType("application/rtf");
                exporter = new JRRtfExporter();
            } else {
                throw new ServletException("Unknown report format: " + format);
            }

            Map exportParams = (Map) stack.findValue(exportParameters);
            if (exportParams != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Found export parameters; adding to exporter parameters...");
                }
                exporter.getParameters().putAll(exportParams);
            }

            output = exportReportToBytes(jasperPrint, exporter);
        } catch (JRException e) {
            String message = "Error producing " + format + " report for uri " + systemId;
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

   * for a pre-defined output format.
   */
  protected void renderReport(JasperPrint populatedReport, Map model, HttpServletResponse response)
      throws Exception {

    JRExporter exporter = createExporter();

    // Set exporter parameters - overriding with values from the Model.
    Map mergedExporterParameters = mergeExporterParameters(model);
    if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
      exporter.setParameters(mergedExporterParameters);
    }

    if (useWriter()) {
      renderReportUsingWriter(exporter, populatedReport, response);
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

                    response.setContentType("application/pdf");

                    // response.setHeader("Content-disposition", "inline; filename=report.pdf");
                    output = JasperExportManager.exportReportToPdf(jasperPrint);
                } else {
                    JRExporter exporter;

                    if (format.equals(FORMAT_CSV)) {
                        response.setContentType("text/plain");
                        exporter = new JRCsvExporter();
                    } else if (format.equals(FORMAT_HTML)) {
                        response.setContentType("text/html");

                        // IMAGES_MAPS seems to be only supported as "backward compatible" from JasperReports 1.1.0

                        Map imagesMap = new HashMap();

                        request.getSession(true).setAttribute("IMAGES_MAP", imagesMap);
                        exporter = new JRHtmlExporter();
                        exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
                        exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl);
                        // Needed to support chart images:
                        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                        request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint);

                    } else if (format.equals(FORMAT_XLS)) {
                        response.setContentType("application/vnd.ms-excel");
                        exporter = new JRXlsExporter();
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

   */
  @Override
  protected void renderReport(JasperPrint populatedReport, Map<String, Object> model, HttpServletResponse response)
      throws Exception {

    JRExporter exporter = createExporter();

    Map<JRExporterParameter, Object> mergedExporterParameters = getConvertedExporterParameters();
    if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
      exporter.setParameters(mergedExporterParameters);
    }

    if (useWriter()) {
      renderReportUsingWriter(exporter, populatedReport, response);
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

   * @param exporter
   * @return
   * @throws JRException
   */
    protected byte[] exportReportToBytes(JasperPrint jasperPrint, String type ) throws JRException {   
      JRExporter exporter = null;
       
    if( FORMAT_PDF.equalsIgnoreCase( type ) ){ 
      contentType = "application/pdf";
      exporter = new JRPdfExporter( );
    }else if( FORMAT_XML.equalsIgnoreCase( type ) ){
      contentType = "text/xml";
      exporter = new JRXmlExporter();
    }else if( FORMAT_HTML.equalsIgnoreCase( type ) ){
      contentType = "text/html";
      exporter = new JRHtmlExporter();
      //... ...
    }else if( FORMAT_CSV.equalsIgnoreCase( type ) ){
      contentType = "text/csv";
      exporter = new JRCsvExporter();
    }else if( FORMAT_RTF.equalsIgnoreCase( type ) ){
      contentType = "application/msword";
      exporter = new JRRtfExporter();
    }else if( FORMAT_XLS.equalsIgnoreCase( type ) ){
      contentType = "application/vnd.ms-excel";
      //exporter = new JRXlsExporter();
      exporter = new JExcelApiExporter();
    }else{
      log.warn( "Export type not in ['PDF','XML','CSV','RTF','XLS','HTML'], use 'XLS'");
      contentType = "application/vnd.ms-excel";
      exporter = new JExcelApiExporter();
    }
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);  
        exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
        exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
        exporter.exportReport();

        return baos.toByteArray();
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

   */
  protected void renderReport(JasperPrint populatedReport, Map model, HttpServletResponse response)
      throws Exception {

    // Prepare report for rendering.
    JRExporter exporter = createExporter();

    // Set exporter parameters - overriding with values from the Model.
    Map mergedExporterParameters = mergeExporterParameters(model);
    if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
      exporter.setParameters(mergedExporterParameters);
    }

    if (useWriter()) {
      // We need to write text to the response Writer.

      // Copy the encoding configured for the report into the response.
      String contentType = getContentType();
      String encoding = (String) exporter.getParameter(JRExporterParameter.CHARACTER_ENCODING);
      if (encoding != null) {
        // Only apply encoding if content type is specified but does not contain charset clause already.
        if (contentType != null && contentType.toLowerCase().indexOf(WebUtils.CONTENT_TYPE_CHARSET_PREFIX) == -1) {
          contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
        }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

                }

                response.setHeader("Content-disposition", tmp.toString());
            }

            JRExporter exporter;

            if (format.equals(FORMAT_PDF)) {
                response.setContentType("application/pdf");
                exporter = new JRPdfExporter();
            } else if (format.equals(FORMAT_CSV)) {
                response.setContentType("text/plain");
                exporter = new JRCsvExporter();
            } else if (format.equals(FORMAT_HTML)) {
                response.setContentType("text/html");

                // IMAGES_MAPS seems to be only supported as "backward compatible" from JasperReports 1.1.0

                Map imagesMap = new HashMap();
                request.getSession(true).setAttribute("IMAGES_MAP", imagesMap);

                exporter = new JRHtmlExporter();
                exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
                exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl);
               
                // Needed to support chart images:
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint);
            } else if (format.equals(FORMAT_XLS)) {
                response.setContentType("application/vnd.ms-excel");
                exporter = new JRXlsExporter();
            } else if (format.equals(FORMAT_XML)) {
                response.setContentType("text/xml");
                exporter = new JRXmlExporter();
            } else if (format.equals(FORMAT_RTF)) {
                response.setContentType("application/rtf");
                exporter = new JRRtfExporter();
            } else {
                throw new ServletException("Unknown report format: " + format);
            }
           
            Map exportParams = (Map) stack.findValue(exportParameters);
            if (exportParams != null) {
              LOG.debug("Found export parameters; adding to exporter parameters...");
              exporter.getParameters().putAll(exportParams);
            }

            output = exportReportToBytes(jasperPrint, exporter);
        } catch (JRException e) {
            String message = "Error producing " + format + " report for uri " + systemId;
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

      {
        res.addOutput("contentType", "application/pdf");
        res.addOutput("fileName", "Report.pdf");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRPdfExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("csv".equals(reportFormat))
      {
        res.addOutput("contentType", "text/plain");
        res.addOutput("fileName", "Report.csv");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRCsvExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("csv".equals(reportFormat))
      {
        res.addOutput("contentType", "text/xml");
        res.addOutput("fileName", "Report.xml");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRXmlExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("xls".equals(reportFormat))
      {
        res.addOutput("contentType", "application/xls");
        res.addOutput("fileName", "Report.xls");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRXlsExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else
      {
        StringBuffer buf = new StringBuffer();
        JRExporter exporter = new JRHtmlExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, buf);
        exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
        exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
        exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
        exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(true));
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(page - 1));
        exporter.exportReport();
        outReport.setContent(buf.toString());

        createPageNavigationControls(req, res, page, reportPrint.getPages().size(), backModel);
      }
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

      {
        res.addOutput("contentType", "application/pdf");
        res.addOutput("fileName", "Report.pdf");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRPdfExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("csv".equals(format))
      {
        res.addOutput("contentType", "text/plain");
        res.addOutput("fileName", "Report.csv");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JasperCSVExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS, true);
        exporter.setParameter(JRExporterParameter.FILTER, noLayoutFilter);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("xml".equals(format))
      {
        res.addOutput("contentType", "text/xml");
        res.addOutput("fileName", "Report.xml");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRXmlExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS, true);
        exporter.setParameter(JRExporterParameter.FILTER, noLayoutFilter);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else if ("xls".equals(format))
      {
        res.addOutput("contentType", "application/xls");
        res.addOutput("fileName", "Report.xls");

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        JRExporter exporter = new JRXlsExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
        exporter.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS, true);
        exporter.setParameter(JRExporterParameter.FILTER, noLayoutFilter);
        exporter.exportReport();
        outReport.setContent(buf.toByteArray());
      }
      else
      {
        StringBuffer buf = new StringBuffer();
        JRExporter exporter = new JRHtmlExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, buf);
        exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
        exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
        exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
        exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(true));
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(page - 1));
        exporter.exportReport();
        outReport.setContent(buf.toString());

        createPageNavigationControls(req, res, page, reportPrint.getPages().size(), reportModel, backModel);
      }
    }
View Full Code Here

Examples of net.sf.jasperreports.engine.JRExporter

public abstract class AbstractJasperReportRenderer implements ReportRenderer<JasperSeamReport> {

    @Override
    public void render(JasperSeamReport reportInstance, OutputStream output) throws IOException {
        JRExporter exporter = getExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportInstance.getDelegate());
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
        try {
            exporter.exportReport();
        } catch (JRException e) {
            throw new ReportException(e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.