Class JasperReports

java.lang.Object
is.codion.plugin.jasperreports.JasperReports

public final class JasperReports extends Object
Factory for Report based on JasperReports.
  • Method Summary

    Modifier and Type
    Method
    Description
    static JRReport<net.sf.jasperreports.engine.JasperPrint>
    classPathReport(Class<?> resourceClass, String reportPath)
    Instantiates a JRReport for a classpath based report.
    static <R> JRReport<R>
    export(JRReport<net.sf.jasperreports.engine.JasperPrint> report, JRExport<R> export)
    Returns a report producing the result of the given export when filled, instead of a JasperPrint.
    static <R> R
    export(net.sf.jasperreports.engine.JasperPrint print, JRExport<R> export)
    Exports the given filled report, for a JasperPrint already at hand, such as one returned by fillReport(JRReport, JRDataSource).
    static JRReport<net.sf.jasperreports.engine.JasperPrint>
    fileReport(String reportPath)
    Instantiates a JRReport for a file based report, either loaded from a URL or from the filesystem.
    static JRReport<net.sf.jasperreports.engine.JasperPrint>
    fileReport(String reportPath, boolean cacheReport)
    Instantiates a JRReport for a file based report, either loaded from a URL or from the filesystem.
    static net.sf.jasperreports.engine.JasperPrint
    fillReport(JRReport<net.sf.jasperreports.engine.JasperPrint> report, net.sf.jasperreports.engine.JRDataSource dataSource)
    Fills the report using the data source wrapped by the given data wrapper
    static net.sf.jasperreports.engine.JasperPrint
    fillReport(JRReport<net.sf.jasperreports.engine.JasperPrint> report, net.sf.jasperreports.engine.JRDataSource dataSource, Map<String,Object> reportParameters)
    Fills the report using the given data.
    static net.sf.jasperreports.engine.JasperPrint
    loadPrint(byte[] bytes)
    Reconstructs a JasperPrint from the bytes JRExport.SERIALIZED produced, for a client receiving them from a report exported to it, letting a client with the reporting engine keep a JasperPrint report over a connection which can not transfer one, such as a JSON one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • classPathReport

      public static JRReport<net.sf.jasperreports.engine.JasperPrint> classPathReport(Class<?> resourceClass, String reportPath)
      Instantiates a JRReport for a classpath based report. Note that classpath reports are always cached.
      Parameters:
      resourceClass - the class owning the report resource
      reportPath - the report path, relative to the resource class
      Returns:
      a report wrapper
    • fileReport

      public static JRReport<net.sf.jasperreports.engine.JasperPrint> fileReport(String reportPath)
      Instantiates a JRReport for a file based report, either loaded from a URL or from the filesystem.
      Parameters:
      reportPath - the report path, relative to the central report path Report.REPORT_PATH
      Returns:
      a report wrapper
    • fileReport

      public static JRReport<net.sf.jasperreports.engine.JasperPrint> fileReport(String reportPath, boolean cacheReport)
      Instantiates a JRReport for a file based report, either loaded from a URL or from the filesystem.
      Parameters:
      reportPath - the report path, relative to the central report path Report.REPORT_PATH
      cacheReport - if true the report is only loaded once and cached
      Returns:
      a report wrapper
    • export

      public static <R> JRReport<R> export(JRReport<net.sf.jasperreports.engine.JasperPrint> report, JRExport<R> export)
      Returns a report producing the result of the given export when filled, instead of a JasperPrint.

      The export runs wherever the report is filled, on the server in case of a remote connection, so a report exported to JRExport.PDF reaches the client as bytes, requiring no reporting engine there.

       ReportType<Map<String, Object>, byte[]> REPORT = reportType("customer_report");
      
       add(REPORT, export(classPathReport(Store.class, "customer_report.jasper"), PDF));
      

      The loaded report and its cache are shared with the given report, so exporting the same report to more than one format loads and caches it once.

      Type Parameters:
      R - the export result type
      Parameters:
      report - the report to export
      export - the export to apply to the filled report
      Returns:
      a report producing the result of the given export
      See Also:
    • export

      public static <R> R export(net.sf.jasperreports.engine.JasperPrint print, JRExport<R> export)
      Exports the given filled report, for a JasperPrint already at hand, such as one returned by fillReport(JRReport, JRDataSource).
      Type Parameters:
      R - the export result type
      Parameters:
      print - the filled report to export
      export - the export to apply
      Returns:
      the exported report
      Throws:
      ReportException - in case of an exception
      See Also:
    • loadPrint

      public static net.sf.jasperreports.engine.JasperPrint loadPrint(byte[] bytes)
      Reconstructs a JasperPrint from the bytes JRExport.SERIALIZED produced, for a client receiving them from a report exported to it, letting a client with the reporting engine keep a JasperPrint report over a connection which can not transfer one, such as a JSON one.
       JasperPrint print = loadPrint(connection.report(REPORT, parameters));
      
      Parameters:
      bytes - the bytes JRExport.SERIALIZED produced
      Returns:
      the reconstructed report
      Throws:
      ReportException - in case of an exception
      See Also:
    • fillReport

      public static net.sf.jasperreports.engine.JasperPrint fillReport(JRReport<net.sf.jasperreports.engine.JasperPrint> report, net.sf.jasperreports.engine.JRDataSource dataSource)
      Fills the report using the data source wrapped by the given data wrapper
      Parameters:
      report - the report to fill
      dataSource - the data provider to use for the report generation
      Returns:
      a filled report ready for display
      Throws:
      ReportException - in case of an exception
    • fillReport

      public static net.sf.jasperreports.engine.JasperPrint fillReport(JRReport<net.sf.jasperreports.engine.JasperPrint> report, net.sf.jasperreports.engine.JRDataSource dataSource, Map<String,Object> reportParameters)
      Fills the report using the given data.
      Parameters:
      report - the report to fill
      dataSource - the data provider to use for the report generation
      reportParameters - the report parameters, must be modifiable
      Returns:
      a filled report ready for display
      Throws:
      ReportException - in case of an exception