Search in sources :

Example 1 with JRCsvDataSource

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

Example 2 with JRCsvDataSource

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();
    }
}
Also used : JRCsvDataSource(net.sf.jasperreports.engine.data.JRCsvDataSource) JRException(net.sf.jasperreports.engine.JRException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) NoTemplateException(org.meveo.admin.exception.NoTemplateException)

Example 3 with JRCsvDataSource

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;
}
Also used : JRCsvDataSource(net.sf.jasperreports.engine.data.JRCsvDataSource)

Aggregations

JRCsvDataSource (net.sf.jasperreports.engine.data.JRCsvDataSource)3 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 JREmptyDataSource (net.sf.jasperreports.engine.JREmptyDataSource)1 JRException (net.sf.jasperreports.engine.JRException)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 NoTemplateException (org.meveo.admin.exception.NoTemplateException)1