@Named @Dependent public class JasperReportsBatchlet extends Object implements javax.batch.api.Batchlet
@BatchProperty
injections, or through CDI injections of objects created and
configured by other parts of the application. Batch properties generally have higher precedence than CDI-injected
counterparts.
The Jasper Reports data source is configured through either resource
property, or jrDataSourceInstance
injection. Directly passing a java.sql.Connection
instance to this class is not supported. For JDBC
data source, The application should instead inject net.sf.jasperreports.engine.JRResultSetDataSource
into jrDataSourceInstance
.
Report can be saved to a file, or directed to a java.io.OutputStream
.
This class supports all output report formats implemented in Jasper Reports. If exporterInstance
field is
injected with an instance of net.sf.jasperreports.export.Exporter
, it will be used to export and generate the
final report. Otherwise, if outputType
batch property is set to pdf, html, or jrprint, a PDF, HTML or
Jasper jrprint report is generated respectively.
Modifier and Type | Field and Description |
---|---|
protected String |
charset
If
resource is specified, and is a csv resource, this property specifies the charset name for reading
the csv resource. |
protected String[] |
columnNames
If
resource is specified, and is a csv, xls, or xlsx resource, this property specifies an array of
strings representing column names matching field names in the report template. |
protected String |
datePattern
If
resource is specified, this property specifies the date pattern string value. |
protected static String |
DEFAULT_OUTPUT_TYPE |
protected javax.enterprise.inject.Instance<net.sf.jasperreports.export.Exporter> |
exporterInstance
Optional injection of an implementation of Jasper Reports
net.sf.jasperreports.export.Exporter . |
protected String |
fieldDelimiter
If
resource is specified, and is a CSV resource, this property specifies the field or column delimiter. |
protected javax.enterprise.inject.Instance<net.sf.jasperreports.engine.JRDataSource> |
jrDataSourceInstance
Optional injection of Jasper Reports
net.sf.jasperreports.engine.JRDataSource , which allows for more
control over the JRDataSource creation and configuration. |
protected String |
locale
If
resource is specified, this property specifies the locale string value. |
protected String |
numberPattern
If
resource is specified, this property specifies the number pattern string value. |
protected String |
outputFile
The file path of the generated report.
|
protected javax.enterprise.inject.Instance<OutputStream> |
outputStreamInstance
Optional injection of report output stream, which allows for more control over the output stream creation,
sharing, and configuration.
|
protected String |
outputType
The format of report output.
|
protected String |
recordDelimiter
If
resource is specified, and is a csv resource, this property specifies the delimiter between records,
typically new line character (CR/LF). |
protected Map |
reportParameters
Report parameters for generating the report.
|
protected javax.enterprise.inject.Instance<Map<String,Object>> |
reportParametersInstance
Optional injection of Jasper Reports report parameters, which allows for more complex, non-string values.
|
protected String |
resource
The resource that provides the data source for generating report.
|
protected String |
template
Resource path of the compiled Jasper Reports template (*.jasper file).
|
protected String |
timeZone
If
resource is specified, this property specifies the time zone string value. |
protected String |
useFirstRowAsHeader
If
resource is specified, and is a csv, xls, or xlsx resource, this property specifies whether to use
the first row as header. |
Constructor and Description |
---|
JasperReportsBatchlet() |
Modifier and Type | Method and Description |
---|---|
protected void |
fillAndExportReport(InputStream templateInputStream,
Map<String,Object> reportParameters,
net.sf.jasperreports.engine.JRDataSource jrDataSource,
net.sf.jasperreports.export.Exporter exporter) |
protected net.sf.jasperreports.export.Exporter |
getExporter() |
protected net.sf.jasperreports.engine.JRDataSource |
getJrDataSource() |
protected OutputStream |
getOutputStream() |
protected Map<String,Object> |
getReportParameters() |
protected InputStream |
getTemplateInputStream() |
String |
process() |
void |
stop() |
protected static final String DEFAULT_OUTPUT_TYPE
@Inject protected String resource
JRDataSource
into jrDataSourceInstance
. If neither resource
nor jrDataSourceInstance
is
specified, an net.sf.jasperreports.engine.JREmptyDataSource
is used.
JRDataSource
injection allows for more flexible instantiation and configuration, such as setting
locale, datePattern, numberPattern, timeZone, recordDelimiter, useFirstRowAsHeader, columnNames, fieldDelimiter,
etc, before making the instance available to this class.
This property has higher precedence than jrDataSourceInstance
injection.
jrDataSourceInstance
@Inject protected String recordDelimiter
resource
is specified, and is a csv resource, this property specifies the delimiter between records,
typically new line character (CR/LF). Optional property. See net.sf.jasperreports.engine.data.JRCsvDataSource
for details.@Inject protected String useFirstRowAsHeader
resource
is specified, and is a csv, xls, or xlsx resource, this property specifies whether to use
the first row as header. Optional property and valid values are "true" and "false".
See net.sf.jasperreports.engine.data.JRCsvDataSource
or
net.sf.jasperreports.engine.data.AbstractXlsDataSource
for details.@Inject protected String fieldDelimiter
resource
is specified, and is a CSV resource, this property specifies the field or column delimiter.
Optional property. See net.sf.jasperreports.engine.data.JRCsvDataSource
for details.@Inject protected String[] columnNames
resource
is specified, and is a csv, xls, or xlsx resource, this property specifies an array of
strings representing column names matching field names in the report template. Optional property.
See net.sf.jasperreports.engine.data.JRCsvDataSource
or
net.sf.jasperreports.engine.data.AbstractXlsDataSource
for details.@Inject protected String datePattern
resource
is specified, this property specifies the date pattern string value. Optional property.
See net.sf.jasperreports.engine.data.JRAbstractTextDataSource#setDatePattern(java.lang.String)
for details.@Inject protected String numberPattern
resource
is specified, this property specifies the number pattern string value. Optional property.
See net.sf.jasperreports.engine.data.JRAbstractTextDataSource#setNumberPattern(java.lang.String)
for details.@Inject protected String timeZone
resource
is specified, this property specifies the time zone string value. Optional property.
See net.sf.jasperreports.engine.data.JRAbstractTextDataSource#setTimeZone(java.lang.String)
for details.@Inject protected String locale
resource
is specified, this property specifies the locale string value. Optional property.
See net.sf.jasperreports.engine.data.JRAbstractTextDataSource#setLocale(java.lang.String)
for details.@Inject protected String charset
resource
is specified, and is a csv resource, this property specifies the charset name for reading
the csv resource. Optional property.
See net.sf.jasperreports.engine.data.JRCsvDataSource#JRCsvDataSource(java.io.File, java.lang.String)
for detail.@Inject protected String template
@Inject protected String outputType
exporterInstance
with a properly
configured instance of net.sf.jasperreports.export.Exporter
.@Inject protected String outputFile
java.io.OutputStream
into outputStreamInstance
.
For instance, in order to stream the report to servlet response, a javax.servlet.ServletOutputStream
can be injected into outputStreamInstance
.
This property has higher precedence than outputStreamInstance
injection.
outputStreamInstance
@Inject protected Map reportParameters
reportParametersInstance
.
This property has higher precedence than reportParametersInstance
injection.
reportParametersInstance
@Inject protected javax.enterprise.inject.Instance<OutputStream> outputStreamInstance
OutputStream
is closed at the end of process()
method.outputFile
@Inject protected javax.enterprise.inject.Instance<net.sf.jasperreports.engine.JRDataSource> jrDataSourceInstance
net.sf.jasperreports.engine.JRDataSource
, which allows for more
control over the JRDataSource
creation and configuration.resource
@Inject protected javax.enterprise.inject.Instance<Map<String,Object>> reportParametersInstance
reportParameters
@Inject protected javax.enterprise.inject.Instance<net.sf.jasperreports.export.Exporter> exporterInstance
net.sf.jasperreports.export.Exporter
. The
injected instance should have been properly configured, including appropriate
net.sf.jasperreports.export.ExporterOutput
. net.sf.jasperreports.export.ExporterInput
will be
set to a net.sf.jasperreports.engine.JasperPrint
by this class.
Some built-in implementations of net.sf.jasperreports.export.ExporterOutput
:
net.sf.jasperreports.engine.export.JRPdfExporter
net.sf.jasperreports.engine.export.HtmlExporter
net.sf.jasperreports.engine.export.ooxml.JRDocxExporter
net.sf.jasperreports.engine.export.ooxml.JRPptxExporter
net.sf.jasperreports.engine.export.JRXlsExporter
net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter
net.sf.jasperreports.engine.export.JRTextExporter
net.sf.jasperreports.engine.export.JRRtfExporter
net.sf.jasperreports.engine.export.JRXmlExporter
net.sf.jasperreports.engine.export.JRCsvExporter
net.sf.jasperreports.engine.export.JsonExporter
net.sf.jasperreports.engine.export.oasis.JROdsExporter
net.sf.jasperreports.engine.export.oasis.JROdtExporter
public String process() throws Exception
process
in interface javax.batch.api.Batchlet
Exception
public void stop() throws Exception
stop
in interface javax.batch.api.Batchlet
Exception
protected InputStream getTemplateInputStream()
protected OutputStream getOutputStream() throws FileNotFoundException
FileNotFoundException
protected net.sf.jasperreports.engine.JRDataSource getJrDataSource() throws IOException, net.sf.jasperreports.engine.JRException
IOException
net.sf.jasperreports.engine.JRException
protected net.sf.jasperreports.export.Exporter getExporter() throws Exception
Exception
protected void fillAndExportReport(InputStream templateInputStream, Map<String,Object> reportParameters, net.sf.jasperreports.engine.JRDataSource jrDataSource, net.sf.jasperreports.export.Exporter exporter) throws net.sf.jasperreports.engine.JRException
net.sf.jasperreports.engine.JRException
Copyright © 2018 JBoss by Red Hat. All rights reserved.