This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/main by this push:
new a2ed3bc9f WW-5732 fix(jasperreports7): match the report format
case-insensitively (#1922)
a2ed3bc9f is described below
commit a2ed3bc9f073fce26ce9bd484392de68185faa43
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sat Sep 12 12:32:28 2026 +0200
WW-5732 fix(jasperreports7): match the report format case-insensitively
(#1922)
The exporter providers are registered under the lower-case names in
JasperReport7Constants and the container lookup is exact, so the
upper-case "CSV" from the class Javadoc example (and from any config
migrated from the 6.x plugin, whose constants are upper-case) failed
with "No exporter found for format: CSV".
The result now retries the lookup with the lower-cased name, so a
custom provider registered under a mixed-case name keeps working while
csv, Csv and CSV all resolve to the bundled one. The example uses the
canonical lower-case spelling.
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
.../struts2/views/jasperreports7/JasperReport7Result.java | 12 +++++++++---
.../views/jasperreports7/JasperReport7ResultTest.java | 14 ++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git
a/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java
b/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java
index fde8590bc..7744cefc4 100644
---
a/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java
+++
b/plugins/jasperreports7/src/main/java/org/apache/struts2/views/jasperreports7/JasperReport7Result.java
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ActionInvocation;
import org.apache.struts2.StrutsException;
+import org.apache.struts2.inject.Container;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.result.StrutsResultSupport;
import org.apache.struts2.security.NotExcludedAcceptedPatternsChecker;
@@ -71,7 +72,8 @@ import java.util.TimeZone;
* <li><b>parse</b> - true by default. If set to false, all the parameters will
* not be parsed for EL expressions.</li>
* <li><b>format</b> - the format in which the report should be generated.
Valid
- * values can be found in {@link JasperReport7Constants}. If no format is
+ * values can be found in {@link JasperReport7Constants} and are matched
case-insensitively,
+ * so <code>csv</code> and <code>CSV</code> select the same exporter. If no
format is
* specified, PDF will be used.</li>
* <li><b>contentDisposition</b> - disposition (defaults to "inline", values
are
* typically <i>filename="document.pdf"</i>).</li>
@@ -103,7 +105,7 @@ import java.util.TimeZone;
* <result name="success" type="jasperReport7">
* <param name="location">foo.jasper</param>
* <param name="dataSource">mySource</param>
- * <param name="format">CSV</param>
+ * <param name="format">csv</param>
* </result>
* <!-- END SNIPPET: example1 -->
* </pre>
@@ -211,7 +213,11 @@ public class JasperReport7Result extends
StrutsResultSupport implements JasperRe
try {
LOG.debug("Export the print object to the desired output format:
{}", format);
- JasperReport7ExporterProvider<?> exporterProvider =
invocation.getInvocationContext().getContainer().getInstance(JasperReport7ExporterProvider.class,
format);
+ Container container =
invocation.getInvocationContext().getContainer();
+ JasperReport7ExporterProvider<?> exporterProvider =
container.getInstance(JasperReport7ExporterProvider.class, format);
+ if (exporterProvider == null) {
+ exporterProvider =
container.getInstance(JasperReport7ExporterProvider.class,
format.toLowerCase(Locale.ROOT));
+ }
if (exporterProvider == null) {
throw new StrutsException("No exporter found for format: " +
format);
}
diff --git
a/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java
b/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java
index 2ef9d2ace..d7c3aadc3 100644
---
a/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java
+++
b/plugins/jasperreports7/src/test/java/org/apache/struts2/views/jasperreports7/JasperReport7ResultTest.java
@@ -289,6 +289,20 @@ public class JasperReport7ResultTest extends
StrutsTestCase {
assertThat(csv.lines()).containsExactly("Qux Report", "Hello Foo
Bar!", "Hello Baz Qux!");
}
+ public void testFormatLookupIsCaseInsensitive() throws Exception {
+ // given
+ result.setDataSource("{#{'firstName':'ignore', 'lastName':'ignore'}}");
+ result.setReportParameters("#{'title':'Qux'}");
+ result.setFormat("CSV");
+
+ // when
+ result.execute(this.invocation);
+
+ // then
+ assertThat(response.getContentType()).isEqualTo("text/csv");
+ assertThat(response.getContentAsString()).contains("Qux Report");
+ }
+
public void testExportToRtf() throws Exception {
// given
result.setDataSource("{#{'firstName':'ignore', 'lastName':'ignore'}}");