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