Search in sources :

Example 1 with JRXmlDataSource

use of net.sf.jasperreports.engine.data.JRXmlDataSource in project DynamicJasper by intive-FDV.

the class XmlReportTest method getDataSource.

protected JRDataSource getDataSource() {
    try {
        Document document;
        document = JRXmlUtils.parse(JRLoader.getLocationInputStream("sample-data.xml"));
        JRXmlDataSource ds = new JRXmlDataSource(document, "/data/linea");
        // params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT,document);
        return ds;
    } catch (JRException e) {
        throw new RuntimeException(e);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) Document(org.w3c.dom.Document) JRXmlDataSource(net.sf.jasperreports.engine.data.JRXmlDataSource)

Example 2 with JRXmlDataSource

use of net.sf.jasperreports.engine.data.JRXmlDataSource 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 3 with JRXmlDataSource

use of net.sf.jasperreports.engine.data.JRXmlDataSource in project meveo by meveo-org.

the class ReportExecution method generatePDF.

/**
 * Generates PDF report using XML file Data source.
 *
 * @param filename Report template filename.
 * @param reportName Report name
 * @param xmlDS xml datasource XML DS string.
 * @param recordPath Current XML DS row path.
 * @param executionDate execution date.
 * @param exportFileName export file name.
 */
public void generatePDF(String filename, String reportName, InputStream xmlDS, String recordPath, Date executionDate, String exportFileName) {
    InputStream reportTemplate = this.getClass().getClassLoader().getResourceAsStream(filename);
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(xmlDS, recordPath);
        dataSource.setDatePattern(DATE_PATERN);
        JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportTemplate);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
        JasperExportManager.exportReportToPdfFile(jasperPrint, generateFileName(exportFileName, executionDate));
        log.info("Created file: " + generateFileName(exportFileName, executionDate));
    } catch (JRException e) {
        log.error("error on generate PDF", e);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JasperReport(net.sf.jasperreports.engine.JasperReport) JRXmlDataSource(net.sf.jasperreports.engine.data.JRXmlDataSource)

Example 4 with JRXmlDataSource

use of net.sf.jasperreports.engine.data.JRXmlDataSource in project meveo by meveo-org.

the class ReportExecution method generatePDF.

/**
 * Generates PDF report using String data source.
 *
 * @param filename Report template filename.
 * @param reportName Report name.
 * @param dsString XML DS string.
 * @param recordPath Current XML DS row path.
 * @param executionDate execution date.
 */
public void generatePDF(String filename, String reportName, String dsString, String recordPath, Date executionDate) {
    InputStream reportTemplate = this.getClass().getClassLoader().getResourceAsStream(filename);
    InputStream xmlDS;
    try {
        xmlDS = new ByteArrayInputStream(dsString.getBytes("UTF-8"));
        // parameters.put("param_03", "value of your param");
        JRXmlDataSource dataSource = new JRXmlDataSource(xmlDS, recordPath);
        dataSource.setDatePattern(DATE_PATERN);
        JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportTemplate);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
        JasperExportManager.exportReportToPdfFile(jasperPrint, generateFileName(reportName, executionDate));
        log.info("Created file: " + generateFileName(reportName, executionDate));
    } catch (JRException e) {
        log.error("failed to generatePDF,JR exception", e);
    } catch (UnsupportedEncodingException e) {
        log.error("failed to generatePDF,unsupported encoding exception", e);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JasperPrint(net.sf.jasperreports.engine.JasperPrint) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JasperReport(net.sf.jasperreports.engine.JasperReport) JRXmlDataSource(net.sf.jasperreports.engine.data.JRXmlDataSource)

Aggregations

JRXmlDataSource (net.sf.jasperreports.engine.data.JRXmlDataSource)4 JRException (net.sf.jasperreports.engine.JRException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 JasperPrint (net.sf.jasperreports.engine.JasperPrint)2 JasperReport (net.sf.jasperreports.engine.JasperReport)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 JREmptyDataSource (net.sf.jasperreports.engine.JREmptyDataSource)1 JRCsvDataSource (net.sf.jasperreports.engine.data.JRCsvDataSource)1 JRXlsxDataSource (net.sf.jasperreports.engine.data.JRXlsxDataSource)1 JsonDataSource (net.sf.jasperreports.engine.data.JsonDataSource)1 XlsDataSource (net.sf.jasperreports.engine.data.XlsDataSource)1 Document (org.w3c.dom.Document)1