Skip to content

Commit 1c3219e

Browse files
authored
WW-5455 Defines a new plugin to support Jasper Reports 7 (#1124)
* WW-5455 Defines a new plugin to support Jasper Reports 7 * WW-5455 Allows action to modify result behaviour * WW-5455 Defines exporter as an extension point * WW-5455 Extracts logic to create connection or dataSource * WW-5455 Uses defaultDelimiter as more meaningful name * WW-5455 Fixes parent version after re-basing * WW-5455 Updates pom to match the latest SNAPSHOT version * WW-5455 Cleans up code * WW-5455 Adds the new plugin to BOM * WW-5455 Fixes broken test
1 parent 9861b83 commit 1c3219e

24 files changed

+2063
-0
lines changed

assembly/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@
172172
<artifactId>struts2-jasperreports-plugin</artifactId>
173173
</dependency>
174174

175+
<dependency>
176+
<groupId>org.apache.struts</groupId>
177+
<artifactId>struts2-jasperreports7-plugin</artifactId>
178+
</dependency>
179+
175180
<dependency>
176181
<groupId>org.apache.struts</groupId>
177182
<artifactId>struts2-jfreechart-plugin</artifactId>

bom/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<artifactId>struts2-jasperreports-plugin</artifactId>
8787
<version>${project.version}</version>
8888
</dependency>
89+
<dependency>
90+
<groupId>org.apache.struts</groupId>
91+
<artifactId>struts2-jasperreports7-plugin</artifactId>
92+
<version>${project.version}</version>
93+
</dependency>
8994
<dependency>
9095
<groupId>org.apache.struts</groupId>
9196
<artifactId>struts2-javatemplates-plugin</artifactId>

plugins/jasperreports7/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Jasper Reports plugin
2+
This plugin allows to use Jasper reports as a one of the result types.
3+
You will find more details in [documentation](https://struts.apache.org/plugins/jasperreports/).
4+
5+
## Installation
6+
Just drop this plugin JAR into `WEB-INF/lib` folder or add it as a Maven dependency.

plugins/jasperreports7/pom.xml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<groupId>org.apache.struts</groupId>
27+
<artifactId>struts2-plugins</artifactId>
28+
<version>7.0.4-SNAPSHOT</version>
29+
</parent>
30+
31+
<artifactId>struts2-jasperreports7-plugin</artifactId>
32+
<packaging>jar</packaging>
33+
<name>Struts 2 Jasper Reports 7 Plugin [EXPERIMENTAL]</name>
34+
35+
<properties>
36+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37+
<jasperreports7.version>7.0.1</jasperreports7.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>net.sf.jasperreports</groupId>
43+
<artifactId>jasperreports</artifactId>
44+
<version>${jasperreports7.version}</version>
45+
<exclusions>
46+
<!-- not necessary to compile and it force dependency convergence issues -->
47+
<exclusion>
48+
<groupId>com.fasterxml.jackson.core</groupId>
49+
<artifactId>jackson-databind</artifactId>
50+
</exclusion>
51+
<exclusion>
52+
<groupId>com.fasterxml.jackson.core</groupId>
53+
<artifactId>jackson-annotations</artifactId>
54+
</exclusion>
55+
</exclusions>
56+
</dependency>
57+
<dependency>
58+
<groupId>net.sf.jasperreports</groupId>
59+
<artifactId>jasperreports-pdf</artifactId>
60+
<version>${jasperreports7.version}</version>
61+
<optional>true</optional>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.fasterxml.jackson.core</groupId>
65+
<artifactId>jackson-databind</artifactId>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.apache.struts</groupId>
69+
<artifactId>struts2-junit-plugin</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.springframework</groupId>
74+
<artifactId>spring-web</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.easymock</groupId>
79+
<artifactId>easymock</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
</dependencies>
83+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.struts2.views.jasperreports7;
20+
21+
import net.sf.jasperreports.engine.JasperReport;
22+
import org.apache.struts2.ActionInvocation;
23+
import org.apache.struts2.StrutsException;
24+
25+
import java.util.Locale;
26+
27+
public interface JasperReport7Aware {
28+
29+
/**
30+
* Used to perform an action before report is going to be generated
31+
*
32+
* @param invocation current {@link ActionInvocation}
33+
*/
34+
default void beforeReportGeneration(ActionInvocation invocation) throws StrutsException {
35+
}
36+
37+
/**
38+
* Used to perform an action before report is going to be generated
39+
*
40+
* @param invocation current {@link ActionInvocation}
41+
*/
42+
default void afterReportGeneration(ActionInvocation invocation, JasperReport jasperReport) throws StrutsException {
43+
}
44+
45+
/**
46+
* Allows to specify action specific CSV delimiter, if returns null,
47+
* default one specified by {@link JasperReport7Constants#STRUTS_JASPER_REPORT_CSV_DELIMITER} will be used
48+
*
49+
* @return delimiter or null
50+
*/
51+
default String getCsvDelimiter(ActionInvocation invocation) {
52+
return null;
53+
}
54+
55+
/**
56+
* Allows to specify different local than used by the framework or an action
57+
*
58+
* @param invocation current {@link ActionInvocation}
59+
* @return locale or null
60+
*/
61+
default Locale getReportLocale(ActionInvocation invocation) {
62+
return invocation.getInvocationContext().getLocale();
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.struts2.views.jasperreports7;
20+
21+
public interface JasperReport7Constants {
22+
23+
/**
24+
* PDF format constant
25+
*/
26+
String FORMAT_PDF = "pdf";
27+
28+
/**
29+
* XML format constant
30+
*/
31+
String FORMAT_XML = "xml";
32+
33+
/**
34+
* HTML format constant
35+
*/
36+
String FORMAT_HTML = "html";
37+
38+
/**
39+
* XLSX format constant
40+
*/
41+
String FORMAT_XLSX = "xlsx";
42+
43+
/**
44+
* CSV format constant
45+
*/
46+
String FORMAT_CSV = "csv";
47+
48+
/**
49+
* RTF format constant
50+
*/
51+
String FORMAT_RTF = "rtf";
52+
53+
/**
54+
* Allows to define a custom default delimiter when exporting report into CSV file
55+
*/
56+
String STRUTS_JASPER_REPORT_CSV_DELIMITER = "struts.jasperReport7.csv.defaultDelimiter";
57+
58+
/**
59+
* Allows to define a custom url to image servlet used when exporting report into HTML
60+
*/
61+
String STRUTS_JASPER_REPORT_HTML_IMAGE_SERVLET_URL = "struts.jasperReport7.html.imageServletUrl";
62+
63+
}

0 commit comments

Comments
 (0)