Compilation compatibility with JasperReports 5.5.2

This commit is contained in:
Juergen Hoeller
2014-05-12 20:34:38 +02:00
parent 782d10c66f
commit e04fb15a5e
9 changed files with 110 additions and 78 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -20,8 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import org.springframework.ui.jasperreports.JasperReportsUtils;
@@ -36,12 +34,17 @@ import org.springframework.web.util.WebUtils;
* to create a JasperReports exporter for a specific output format, and
* {@code useWriter} to determine whether to write text or binary content.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.5
* @see #createExporter()
* @see #useWriter()
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasperReportsView {
@Override
@@ -54,12 +57,13 @@ public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasp
* for a pre-defined output format.
*/
@Override
@SuppressWarnings("unchecked")
protected void renderReport(JasperPrint populatedReport, Map<String, Object> model, HttpServletResponse response)
throws Exception {
JRExporter exporter = createExporter();
net.sf.jasperreports.engine.JRExporter exporter = createExporter();
Map<JRExporterParameter, Object> mergedExporterParameters = getConvertedExporterParameters();
Map<net.sf.jasperreports.engine.JRExporterParameter, Object> mergedExporterParameters = getConvertedExporterParameters();
if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
exporter.setParameters(mergedExporterParameters);
}
@@ -79,12 +83,12 @@ public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasp
* @param response the HTTP response the report should be rendered to
* @throws Exception if rendering failed
*/
protected void renderReportUsingWriter(
JRExporter exporter, JasperPrint populatedReport, HttpServletResponse response) throws Exception {
protected void renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter,
JasperPrint populatedReport, HttpServletResponse response) throws Exception {
// Copy the encoding configured for the report into the response.
String contentType = getContentType();
String encoding = (String) exporter.getParameter(JRExporterParameter.CHARACTER_ENCODING);
String encoding = (String) exporter.getParameter(net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING);
if (encoding != null) {
// Only apply encoding if content type is specified but does not contain charset clause already.
if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
@@ -104,8 +108,8 @@ public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasp
* @param response the HTTP response the report should be rendered to
* @throws Exception if rendering failed
*/
protected void renderReportUsingOutputStream(
JRExporter exporter, JasperPrint populatedReport, HttpServletResponse response) throws Exception {
protected void renderReportUsingOutputStream(net.sf.jasperreports.engine.JRExporter exporter,
JasperPrint populatedReport, HttpServletResponse response) throws Exception {
// IE workaround: write into byte array first.
ByteArrayOutputStream baos = createTemporaryOutputStream();
@@ -121,7 +125,7 @@ public abstract class AbstractJasperReportsSingleFormatView extends AbstractJasp
* output will be written as text or as binary content.
* @see #useWriter()
*/
protected abstract JRExporter createExporter();
protected abstract net.sf.jasperreports.engine.JRExporter createExporter();
/**
* Return whether to use a {@code java.io.Writer} to write text content

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -35,7 +35,6 @@ import javax.sql.DataSource;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRDataSourceProvider;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
@@ -101,6 +100,10 @@ import org.springframework.web.servlet.view.AbstractUrlBasedView;
* so that reports render correctly in Internet Explorer. However, you can override this
* setting through the {@code headers} property.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.3
@@ -112,6 +115,7 @@ import org.springframework.web.servlet.view.AbstractUrlBasedView;
* @see #setExporterParameters
* @see #setJdbcDataSource
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
/**
@@ -157,7 +161,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
/**
* Stores the converted exporter parameters - keyed by {@code JRExporterParameter}.
*/
private Map<JRExporterParameter, Object> convertedExporterParameters;
private Map<net.sf.jasperreports.engine.JRExporterParameter, Object> convertedExporterParameters;
/**
* Stores the {@code DataSource}, if any, used as the report data source.
@@ -261,14 +265,14 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
/**
* Allows subclasses to populate the converted exporter parameters.
*/
protected void setConvertedExporterParameters(Map<JRExporterParameter, Object> convertedExporterParameters) {
this.convertedExporterParameters = convertedExporterParameters;
protected void setConvertedExporterParameters(Map<net.sf.jasperreports.engine.JRExporterParameter, Object> parameters) {
this.convertedExporterParameters = parameters;
}
/**
* Allows subclasses to retrieve the converted exporter parameters.
*/
protected Map<JRExporterParameter, Object> getConvertedExporterParameters() {
protected Map<net.sf.jasperreports.engine.JRExporterParameter, Object> getConvertedExporterParameters() {
return this.convertedExporterParameters;
}
@@ -353,9 +357,10 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
*/
protected final void convertExporterParameters() {
if (!CollectionUtils.isEmpty(this.exporterParameters)) {
this.convertedExporterParameters = new HashMap<JRExporterParameter, Object>(this.exporterParameters.size());
this.convertedExporterParameters =
new HashMap<net.sf.jasperreports.engine.JRExporterParameter, Object>(this.exporterParameters.size());
for (Map.Entry<?, ?> entry : this.exporterParameters.entrySet()) {
JRExporterParameter exporterParameter = getExporterParameter(entry.getKey());
net.sf.jasperreports.engine.JRExporterParameter exporterParameter = getExporterParameter(entry.getKey());
this.convertedExporterParameters.put(
exporterParameter, convertParameterValue(exporterParameter, entry.getValue()));
}
@@ -364,7 +369,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
/**
* Convert the supplied parameter value into the actual type required by the
* corresponding {@link JRExporterParameter}.
* corresponding {@code JRExporterParameter}.
* <p>The default implementation simply converts the String values "true" and
* "false" into corresponding {@code Boolean} objects, and tries to convert
* String values that start with a digit into {@code Integer} objects
@@ -373,7 +378,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
* @param value the parameter value
* @return the converted parameter value
*/
protected Object convertParameterValue(JRExporterParameter parameter, Object value) {
protected Object convertParameterValue(net.sf.jasperreports.engine.JRExporterParameter parameter, Object value) {
if (value instanceof String) {
String str = (String) value;
if ("true".equals(str)) {
@@ -403,9 +408,9 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
* @return a JRExporterParameter for the given parameter object
* @see #convertToExporterParameter(String)
*/
protected JRExporterParameter getExporterParameter(Object parameter) {
if (parameter instanceof JRExporterParameter) {
return (JRExporterParameter) parameter;
protected net.sf.jasperreports.engine.JRExporterParameter getExporterParameter(Object parameter) {
if (parameter instanceof net.sf.jasperreports.engine.JRExporterParameter) {
return (net.sf.jasperreports.engine.JRExporterParameter) parameter;
}
if (parameter instanceof String) {
return convertToExporterParameter((String) parameter);
@@ -422,7 +427,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
* (e.g. "net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI")
* @return the corresponding JRExporterParameter instance
*/
protected JRExporterParameter convertToExporterParameter(String fqFieldName) {
protected net.sf.jasperreports.engine.JRExporterParameter convertToExporterParameter(String fqFieldName) {
int index = fqFieldName.lastIndexOf('.');
if (index == -1 || index == fqFieldName.length()) {
throw new IllegalArgumentException(
@@ -437,9 +442,9 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
Class<?> cls = ClassUtils.forName(className, getApplicationContext().getClassLoader());
Field field = cls.getField(fieldName);
if (JRExporterParameter.class.isAssignableFrom(field.getType())) {
if (net.sf.jasperreports.engine.JRExporterParameter.class.isAssignableFrom(field.getType())) {
try {
return (JRExporterParameter) field.get(null);
return (net.sf.jasperreports.engine.JRExporterParameter) field.get(null);
}
catch (IllegalAccessException ex) {
throw new IllegalArgumentException(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,8 +16,6 @@
package org.springframework.web.servlet.view.jasperreports;
import net.sf.jasperreports.engine.JRExporter;
import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;
@@ -25,6 +23,10 @@ import org.springframework.util.Assert;
* Configurable JasperReports View, allowing to specify the JasperReports exporter
* to be specified through bean properties rather than through the view class name.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @since 2.0
* @see JasperReportsCsvView
@@ -32,25 +34,26 @@ import org.springframework.util.Assert;
* @see JasperReportsPdfView
* @see JasperReportsXlsView
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFormatView {
private Class<? extends JRExporter> exporterClass;
private Class<? extends net.sf.jasperreports.engine.JRExporter> exporterClass;
private boolean useWriter = true;
/**
* Set the {@link JRExporter} implementation {@code Class} to use. Throws
* Set the {@code JRExporter} implementation {@code Class} to use. Throws
* {@link IllegalArgumentException} if the {@code Class} doesn't implement
* {@link JRExporter}. Required setting, as it does not have a default.
* {@code JRExporter}. Required setting, as it does not have a default.
*/
public void setExporterClass(Class<? extends JRExporter> exporterClass) {
Assert.isAssignable(JRExporter.class, exporterClass);
public void setExporterClass(Class<? extends net.sf.jasperreports.engine.JRExporter> exporterClass) {
Assert.isAssignable(net.sf.jasperreports.engine.JRExporter.class, exporterClass);
this.exporterClass = exporterClass;
}
/**
* Specifies whether or not the {@link JRExporter} writes to the {@link java.io.PrintWriter}
* Specifies whether or not the {@code JRExporter} writes to the {@link java.io.PrintWriter}
* of the associated with the request ({@code true}) or whether it writes directly to the
* {@link java.io.InputStream} of the request ({@code false}). Default is {@code true}.
*/
@@ -70,17 +73,17 @@ public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFo
/**
* Returns a new instance of the specified {@link JRExporter} class.
* Returns a new instance of the specified {@link net.sf.jasperreports.engine.JRExporter} class.
* @see #setExporterClass(Class)
* @see BeanUtils#instantiateClass(Class)
*/
@Override
protected JRExporter createExporter() {
protected net.sf.jasperreports.engine.JRExporter createExporter() {
return BeanUtils.instantiateClass(this.exporterClass);
}
/**
* Indicates how the {@link JRExporter} should render its data.
* Indicates how the {@code JRExporter} should render its data.
* @see #setUseWriter(boolean)
*/
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,17 +16,21 @@
package org.springframework.web.servlet.view.jasperreports;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JRCsvExporter;
/**
* Implementation of {@code AbstractJasperReportsSingleFormatView}
* that renders report results in CSV format.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.3
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public class JasperReportsCsvView extends AbstractJasperReportsSingleFormatView {
public JasperReportsCsvView() {
@@ -34,7 +38,7 @@ public class JasperReportsCsvView extends AbstractJasperReportsSingleFormatView
}
@Override
protected JRExporter createExporter() {
protected net.sf.jasperreports.engine.JRExporter createExporter() {
return new JRCsvExporter();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,17 +16,19 @@
package org.springframework.web.servlet.view.jasperreports;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
/**
* Implementation of {@code AbstractJasperReportsSingleFormatView}
* that renders report results in HTML format.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.3
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public class JasperReportsHtmlView extends AbstractJasperReportsSingleFormatView {
public JasperReportsHtmlView() {
@@ -34,8 +36,8 @@ public class JasperReportsHtmlView extends AbstractJasperReportsSingleFormatView
}
@Override
protected JRExporter createExporter() {
return new JRHtmlExporter();
protected net.sf.jasperreports.engine.JRExporter createExporter() {
return new net.sf.jasperreports.engine.export.JRHtmlExporter();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,17 +16,21 @@
package org.springframework.web.servlet.view.jasperreports;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
/**
* Implementation of {@code AbstractJasperReportsSingleFormatView}
* that renders report results in PDF format.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.3
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public class JasperReportsPdfView extends AbstractJasperReportsSingleFormatView {
public JasperReportsPdfView() {
@@ -34,7 +38,7 @@ public class JasperReportsPdfView extends AbstractJasperReportsSingleFormatView
}
@Override
protected JRExporter createExporter() {
protected net.sf.jasperreports.engine.JRExporter createExporter() {
return new JRPdfExporter();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,17 +16,21 @@
package org.springframework.web.servlet.view.jasperreports;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
/**
* Implementation of {@code AbstractJasperReportsSingleFormatView}
* that renders report results in XLS format.
*
* <p><b>This class is compatible with classic JasperReports releases back until 2.x.</b>
* As a consequence, it keeps using the {@link net.sf.jasperreports.engine.JRExporter}
* API which got deprecated as of JasperReports 5.5.2 (early 2014).
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 1.1.3
*/
@SuppressWarnings({"deprecation", "rawtypes"})
public class JasperReportsXlsView extends AbstractJasperReportsSingleFormatView {
public JasperReportsXlsView() {
@@ -34,7 +38,7 @@ public class JasperReportsXlsView extends AbstractJasperReportsSingleFormatView
}
@Override
protected JRExporter createExporter() {
protected net.sf.jasperreports.engine.JRExporter createExporter() {
return new JRXlsExporter();
}