Search in sources :

Example 1 with XlsDataSource

use of net.sf.jasperreports.engine.data.XlsDataSource in project jberet-support by jberet.

the class JasperReportsBatchlet method getJrDataSource.

protected JRDataSource getJrDataSource() throws IOException, JRException {
    if (resource != null) {
        final String res = resource.toLowerCase();
        resourceInputStream = ItemReaderWriterBase.getInputStream(resource, false);
        if (res.endsWith(".csv")) {
            final JRCsvDataSource csvDataSource = charset == null ? new JRCsvDataSource(resourceInputStream) : new JRCsvDataSource(resourceInputStream, charset);
            setCommonJRDataSourceProperties(csvDataSource);
            if (useFirstRowAsHeader != null) {
                csvDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
            }
            if (recordDelimiter != null) {
                csvDataSource.setRecordDelimiter(recordDelimiter);
            }
            if (fieldDelimiter != null) {
                csvDataSource.setFieldDelimiter(fieldDelimiter.trim().charAt(0));
            }
            if (columnNames != null) {
                csvDataSource.setColumnNames(columnNames);
            }
            return csvDataSource;
        }
        if (res.endsWith(".xls")) {
            final XlsDataSource xlsDataSource = new XlsDataSource(resourceInputStream);
            setCommonJRDataSourceProperties(xlsDataSource);
            if (columnNames != null) {
                xlsDataSource.setColumnNames(columnNames);
            }
            if (useFirstRowAsHeader != null) {
                xlsDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
            }
            return xlsDataSource;
        }
        if (res.endsWith(".xlsx")) {
            final JRXlsxDataSource jrXlsxDataSource = new JRXlsxDataSource(resourceInputStream);
            setCommonJRDataSourceProperties(jrXlsxDataSource);
            if (columnNames != null) {
                jrXlsxDataSource.setColumnNames(columnNames);
            }
            if (useFirstRowAsHeader != null) {
                jrXlsxDataSource.setUseFirstRowAsHeader(Boolean.parseBoolean(useFirstRowAsHeader));
            }
            return jrXlsxDataSource;
        }
        if (res.endsWith(".xml")) {
            final JRXmlDataSource jrXmlDataSource = new JRXmlDataSource(resourceInputStream);
            setCommonJRDataSourceProperties(jrXmlDataSource);
            return jrXmlDataSource;
        }
        if (res.endsWith(".json")) {
            final JsonDataSource jsonDataSource = new JsonDataSource(resourceInputStream);
            setCommonJRDataSourceProperties(jsonDataSource);
            return jsonDataSource;
        }
        throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, resource, "resource");
    } else {
        if (jrDataSourceInstance != null && !jrDataSourceInstance.isUnsatisfied()) {
            return jrDataSourceInstance.get();
        }
    }
    return new JREmptyDataSource();
}
Also used : JRCsvDataSource(net.sf.jasperreports.engine.data.JRCsvDataSource) JsonDataSource(net.sf.jasperreports.engine.data.JsonDataSource) JREmptyDataSource(net.sf.jasperreports.engine.JREmptyDataSource) XlsDataSource(net.sf.jasperreports.engine.data.XlsDataSource) JRXlsxDataSource(net.sf.jasperreports.engine.data.JRXlsxDataSource) JRXmlDataSource(net.sf.jasperreports.engine.data.JRXmlDataSource)

Aggregations

JREmptyDataSource (net.sf.jasperreports.engine.JREmptyDataSource)1 JRCsvDataSource (net.sf.jasperreports.engine.data.JRCsvDataSource)1 JRXlsxDataSource (net.sf.jasperreports.engine.data.JRXlsxDataSource)1 JRXmlDataSource (net.sf.jasperreports.engine.data.JRXmlDataSource)1 JsonDataSource (net.sf.jasperreports.engine.data.JsonDataSource)1 XlsDataSource (net.sf.jasperreports.engine.data.XlsDataSource)1