use of net.sf.jasperreports.engine.data.JRCsvDataSource 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();
}
use of net.sf.jasperreports.engine.data.JRCsvDataSource in project meveo by meveo-org.
the class FileProducer method generatePDFfile.
/**
* @param dataSourceFile Data source CSV file
* @param fileName Filename of new file
* @param reportFileName Report template
* @param parameters template parameters
*/
public void generatePDFfile(File dataSourceFile, String fileName, String reportFileName, Map<String, Object> parameters) {
try {
InputStream reportTemplate = new FileInputStream(reportFileName);
jasperReport = (JasperReport) JRLoader.loadObject(reportTemplate);
if (dataSourceFile != null) {
JRCsvDataSource dataSource = createDataSource(dataSourceFile);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, fileName);
}
} catch (JRException e) {
log.error("failed to generate PDF file", e);
} catch (FileNotFoundException e) {
throw new NoTemplateException();
}
}
use of net.sf.jasperreports.engine.data.JRCsvDataSource in project meveo by meveo-org.
the class FileProducer method createDataSource.
public JRCsvDataSource createDataSource(File dataSourceFile) throws FileNotFoundException {
JRCsvDataSource ds = new JRCsvDataSource(dataSourceFile);
// DecimalFormat df = new DecimalFormat("0.00");
// NumberFormat nf = NumberFormat.getInstance(Locale.US);
// ds.setNumberFormat(nf);
ds.setFieldDelimiter(';');
ds.setRecordDelimiter("\n");
ds.setUseFirstRowAsHeader(true);
// ds.setColumnNames(columnNames);
return ds;
}
Aggregations