Finally added generics to JasperReports API signatures (motivated by JasperReports 5.0)
This commit is contained in:
parent
230dec8e6f
commit
48f405e8fd
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -117,14 +117,13 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param writer the <code>Writer</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsCsv(JasperReport report, Map parameters, Object reportData, Writer writer)
|
||||
throws JRException {
|
||||
public static void renderAsCsv(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
Writer writer) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
render(new JRCsvExporter(), print, writer);
|
||||
|
|
@ -136,15 +135,14 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param writer the <code>Writer</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @param exporterParameters a {@link Map} of {@link JRExporterParameter exporter parameters}
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsCsv(JasperReport report, Map parameters, Object reportData, Writer writer,
|
||||
Map exporterParameters) throws JRException {
|
||||
public static void renderAsCsv(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
Writer writer, Map<JRExporterParameter, Object> exporterParameters) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
JRCsvExporter exporter = new JRCsvExporter();
|
||||
|
|
@ -158,14 +156,13 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param writer the <code>Writer</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsHtml(JasperReport report, Map parameters, Object reportData, Writer writer)
|
||||
throws JRException {
|
||||
public static void renderAsHtml(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
Writer writer) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
render(new JRHtmlExporter(), print, writer);
|
||||
|
|
@ -177,15 +174,14 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param writer the <code>Writer</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @param exporterParameters a {@link Map} of {@link JRExporterParameter exporter parameters}
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsHtml(JasperReport report, Map parameters, Object reportData, Writer writer,
|
||||
Map exporterParameters) throws JRException {
|
||||
public static void renderAsHtml(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
Writer writer, Map<JRExporterParameter, Object> exporterParameters) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
JRHtmlExporter exporter = new JRHtmlExporter();
|
||||
|
|
@ -199,14 +195,13 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param stream the <code>OutputStream</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsPdf(JasperReport report, Map parameters, Object reportData, OutputStream stream)
|
||||
throws JRException {
|
||||
public static void renderAsPdf(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
OutputStream stream) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
render(new JRPdfExporter(), print, stream);
|
||||
|
|
@ -218,15 +213,14 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param stream the <code>OutputStream</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @param exporterParameters a {@link Map} of {@link JRExporterParameter exporter parameters}
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsPdf(JasperReport report, Map parameters, Object reportData, OutputStream stream,
|
||||
Map exporterParameters) throws JRException {
|
||||
public static void renderAsPdf(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
OutputStream stream, Map<JRExporterParameter, Object> exporterParameters) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
JRPdfExporter exporter = new JRPdfExporter();
|
||||
|
|
@ -240,14 +234,13 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param stream the <code>OutputStream</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsXls(JasperReport report, Map parameters, Object reportData, OutputStream stream)
|
||||
throws JRException {
|
||||
public static void renderAsXls(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
OutputStream stream) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
render(new JRXlsExporter(), print, stream);
|
||||
|
|
@ -259,15 +252,14 @@ public abstract class JasperReportsUtils {
|
|||
* @param report the <code>JasperReport</code> instance to render
|
||||
* @param parameters the parameters to use for rendering
|
||||
* @param stream the <code>OutputStream</code> to write the rendered report to
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code>
|
||||
* or object array (converted accordingly), representing the report data to read
|
||||
* fields from
|
||||
* @param reportData a <code>JRDataSource</code>, <code>java.util.Collection</code> or object array
|
||||
* (converted accordingly), representing the report data to read fields from
|
||||
* @param exporterParameters a {@link Map} of {@link JRExporterParameter exporter parameters}
|
||||
* @throws JRException if rendering failed
|
||||
* @see #convertReportData
|
||||
*/
|
||||
public static void renderAsXls(JasperReport report, Map parameters, Object reportData, OutputStream stream,
|
||||
Map exporterParameters) throws JRException {
|
||||
public static void renderAsXls(JasperReport report, Map<String, Object> parameters, Object reportData,
|
||||
OutputStream stream, Map<JRExporterParameter, Object> exporterParameters) throws JRException {
|
||||
|
||||
JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData));
|
||||
JRXlsExporter exporter = new JRXlsExporter();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,6 +28,7 @@ import java.util.ResourceBundle;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.jasperreports.engine.JRDataSource;
|
||||
import net.sf.jasperreports.engine.JRExporterParameter;
|
||||
import net.sf.jasperreports.engine.JRParameter;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
|
@ -71,12 +72,12 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
|
||||
public void testRenderAsCsvWithExporterParameters() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
Map exporterParameters = new HashMap();
|
||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||
exporterParameters.put(JRCsvExporterParameter.FIELD_DELIMITER, "~");
|
||||
JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getData(), writer, exporterParameters);
|
||||
String output = writer.getBuffer().toString();
|
||||
assertCsvOutputCorrect(output);
|
||||
assertTrue("Delimiter is incorrect", output.indexOf("~") > -1);
|
||||
assertTrue("Delimiter is incorrect", output.contains("~"));
|
||||
}
|
||||
|
||||
public void testRenderAsHtmlWithDataSource() throws Exception {
|
||||
|
|
@ -95,13 +96,13 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
|
||||
public void testRenderAsHtmlWithExporterParameters() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
Map exporterParameters = new HashMap();
|
||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||
String uri = "/my/uri";
|
||||
exporterParameters.put(JRHtmlExporterParameter.IMAGES_URI, uri);
|
||||
JasperReportsUtils.renderAsHtml(getReport(), getParameters(), getData(), writer, exporterParameters);
|
||||
String output = writer.getBuffer().toString();
|
||||
assertHtmlOutputCorrect(output);
|
||||
assertTrue("URI not included", output.indexOf(uri) > -1);
|
||||
assertTrue("URI not included", output.contains(uri));
|
||||
}
|
||||
|
||||
public void testRenderAsPdfWithDataSource() throws Exception {
|
||||
|
|
@ -120,12 +121,12 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
|
||||
public void testRenderAsPdfWithExporterParameters() throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Map exporterParameters = new HashMap();
|
||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||
exporterParameters.put(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_6.toString());
|
||||
JasperReportsUtils.renderAsPdf(getReport(), getParameters(), getData(), os, exporterParameters);
|
||||
byte[] output = os.toByteArray();
|
||||
assertPdfOutputCorrect(output);
|
||||
assertTrue(new String(output).indexOf("PDF-1.6") > -1);
|
||||
assertTrue(new String(output).contains("PDF-1.6"));
|
||||
}
|
||||
|
||||
public void testRenderAsXlsWithDataSource() throws Exception {
|
||||
|
|
@ -144,7 +145,7 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
|
||||
public void testRenderAsXlsWithExporterParameters() throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Map exporterParameters = new HashMap();
|
||||
Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
|
||||
|
||||
SimpleProgressMonitor monitor = new SimpleProgressMonitor();
|
||||
exporterParameters.put(JRXlsExporterParameter.PROGRESS_MONITOR, monitor);
|
||||
|
|
@ -174,13 +175,13 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
private void assertCsvOutputCorrect(String output) {
|
||||
assertTrue("Output length should be greater than 0", (output.length() > 0));
|
||||
assertTrue("Output should start with Dear Lord!", output.startsWith("Dear Lord!"));
|
||||
assertTrue("Output should contain 'MeineSeite'", output.indexOf("MeineSeite") > -1);
|
||||
assertTrue("Output should contain 'MeineSeite'", output.contains("MeineSeite"));
|
||||
}
|
||||
|
||||
private void assertHtmlOutputCorrect(String output) {
|
||||
assertTrue("Output length should be greater than 0", (output.length() > 0));
|
||||
assertTrue("Output should contain <html>", output.indexOf("<html>") > -1);
|
||||
assertTrue("Output should contain 'MeineSeite'", output.indexOf("MeineSeite") > -1);
|
||||
assertTrue("Output should contain <html>", output.contains("<html>"));
|
||||
assertTrue("Output should contain 'MeineSeite'", output.contains("MeineSeite"));
|
||||
}
|
||||
|
||||
private void assertPdfOutputCorrect(byte[] output) throws Exception {
|
||||
|
|
@ -205,8 +206,8 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
return (JasperReport) JRLoader.loadObject(resource.getInputStream());
|
||||
}
|
||||
|
||||
private Map getParameters() {
|
||||
Map model = new HashMap();
|
||||
private Map<String, Object> getParameters() {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("ReportTitle", "Dear Lord!");
|
||||
model.put(JRParameter.REPORT_LOCALE, Locale.GERMAN);
|
||||
model.put(JRParameter.REPORT_RESOURCE_BUNDLE,
|
||||
|
|
@ -218,8 +219,8 @@ public class JasperReportsUtilsTests extends TestCase {
|
|||
return new JRBeanCollectionDataSource(getData());
|
||||
}
|
||||
|
||||
private List getData() {
|
||||
List list = new ArrayList();
|
||||
private List<PersonBean> getData() {
|
||||
List<PersonBean> list = new ArrayList<PersonBean>();
|
||||
for (int x = 0; x < 10; x++) {
|
||||
PersonBean bean = new PersonBean();
|
||||
bean.setId(x);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -59,7 +59,7 @@ public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasp
|
|||
|
||||
JRExporter exporter = createExporter();
|
||||
|
||||
Map mergedExporterParameters = getConvertedExporterParameters();
|
||||
Map<JRExporterParameter, Object> mergedExporterParameters = getConvertedExporterParameters();
|
||||
if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
|
||||
exporter.setParameters(mergedExporterParameters);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue