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();
}
Aggregations