This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/struts-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new d752915  Adds a simple JFreeChart example
d752915 is described below

commit d75291545aa40f5b013ec3b9b1694db9a37382e0
Author: Lukasz Lenart <lukaszlen...@apache.org>
AuthorDate: Tue Jul 12 08:02:37 2022 +0200

    Adds a simple JFreeChart example
---
 jfreechart/pom.xml                                 | 90 ++++++++++++++++++++++
 .../main/java/org/apache/struts/example/Chart.java | 65 ++++++++++++++++
 jfreechart/src/main/resources/log4j2.xml           | 37 +++++++++
 jfreechart/src/main/resources/struts.xml           | 47 +++++++++++
 jfreechart/src/main/webapp/WEB-INF/index.jsp       | 32 ++++++++
 jfreechart/src/main/webapp/WEB-INF/web.xml         | 46 +++++++++++
 jfreechart/src/main/webapp/index.html              | 30 ++++++++
 pom.xml                                            |  1 +
 8 files changed, 348 insertions(+)

diff --git a/jfreechart/pom.xml b/jfreechart/pom.xml
new file mode 100644
index 0000000..d4ffa85
--- /dev/null
+++ b/jfreechart/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>struts-examples</artifactId>
+        <groupId>org.apache.struts</groupId>
+        <version>1.1.0</version>
+    </parent>
+
+    <artifactId>jfreechart</artifactId>
+    <packaging>war</packaging>
+    <name>jfreechart</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.struts</groupId>
+            <artifactId>struts2-jfreechart-plugin</artifactId>
+            <version>${struts2.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jfree</groupId>
+            <artifactId>jfreechart</artifactId>
+            <version>1.5.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <version>3.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>jsp-api</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-maven-plugin</artifactId>
+                <version>${jetty-plugin.version}</version>
+                <configuration>
+                    <webApp>
+                        <contextPath>/${project.artifactId}</contextPath>
+                    </webApp>
+                    <stopKey>CTRL+C</stopKey>
+                    <stopPort>8999</stopPort>
+                    <scanIntervalSeconds>10</scanIntervalSeconds>
+                    <scanTargets>
+                        
<scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
+                    </scanTargets>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/jfreechart/src/main/java/org/apache/struts/example/Chart.java 
b/jfreechart/src/main/java/org/apache/struts/example/Chart.java
new file mode 100644
index 0000000..7548c6f
--- /dev/null
+++ b/jfreechart/src/main/java/org/apache/struts/example/Chart.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.struts.example;
+
+import com.opensymphony.xwork2.ActionSupport;
+import org.apache.commons.lang3.RandomUtils;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+
+public class Chart extends ActionSupport {
+
+    private JFreeChart chart;
+
+    public String execute() throws Exception {
+        XYSeries dataSeries = new XYSeries(1);
+        for (int i = 0; i <= 100; i++) {
+            dataSeries.add(i, RandomUtils.nextInt());
+        }
+        XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
+
+        ValueAxis xAxis = new NumberAxis("Raw Marks");
+        ValueAxis yAxis = new NumberAxis("Moderated Marks");
+
+        chart = new JFreeChart(
+                        "Moderation Function",
+                        JFreeChart.DEFAULT_TITLE_FONT,
+                        new XYPlot(
+                                xyDataset,
+                                xAxis,
+                                yAxis,
+                                new 
StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
+                        false
+        );
+
+        chart.setBackgroundPaint(java.awt.Color.white);
+
+        return SUCCESS;
+    }
+
+    public JFreeChart getChart() {
+        return chart;
+    }
+}
diff --git a/jfreechart/src/main/resources/log4j2.xml 
b/jfreechart/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..91d6d4e
--- /dev/null
+++ b/jfreechart/src/main/resources/log4j2.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+-->
+
+<Configuration>
+    <Appenders>
+        <Console name="STDOUT" target="SYSTEM_OUT">
+            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Logger name="com.opensymphony.xwork2" level="info"/>
+        <Logger name="org.apache.struts2" level="info"/>
+        <Logger name="org.apache.struts" level="info"/>
+        <Root level="warn">
+            <AppenderRef ref="STDOUT"/>
+        </Root>
+    </Loggers>
+</Configuration>
diff --git a/jfreechart/src/main/resources/struts.xml 
b/jfreechart/src/main/resources/struts.xml
new file mode 100644
index 0000000..e0323cd
--- /dev/null
+++ b/jfreechart/src/main/resources/struts.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+-->
+
+<!DOCTYPE struts PUBLIC
+        "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+        "http://struts.apache.org/dtds/struts-6.0.dtd";>
+<struts>
+    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
+    <constant name="struts.devMode" value="true"/>
+
+    <package name="default" namespace="/" extends="jfreechart-default">
+
+        <default-action-ref name="index"/>
+
+        <action name="index">
+            <result>/WEB-INF/index.jsp</result>
+        </action>
+
+        <action name="chart" class="org.apache.struts.example.Chart">
+            <result name="success" type="chart">
+                <param name="width">400</param>
+                <param name="height">300</param>
+            </result>
+        </action>
+
+    </package>
+
+</struts>
diff --git a/jfreechart/src/main/webapp/WEB-INF/index.jsp 
b/jfreechart/src/main/webapp/WEB-INF/index.jsp
new file mode 100644
index 0000000..b3de84e
--- /dev/null
+++ b/jfreechart/src/main/webapp/WEB-INF/index.jsp
@@ -0,0 +1,32 @@
+<%--
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+--%>
+
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+    <title>JFreeChart</title>
+</head>
+
+<body>
+    <img src="chart" alt="JFreeChart Chart">
+</body>
+</html>
diff --git a/jfreechart/src/main/webapp/WEB-INF/web.xml 
b/jfreechart/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..03d5eda
--- /dev/null
+++ b/jfreechart/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+-->
+
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";
+         version="3.1">
+
+    <display-name>Struts JFreeChart example</display-name>
+
+    <filter>
+        <filter-name>struts2</filter-name>
+        <filter-class>
+            org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
+        </filter-class>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>struts2</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <welcome-file-list>
+        <welcome-file>index.html</welcome-file>
+    </welcome-file-list>
+</web-app>
diff --git a/jfreechart/src/main/webapp/index.html 
b/jfreechart/src/main/webapp/index.html
new file mode 100644
index 0000000..e43a075
--- /dev/null
+++ b/jfreechart/src/main/webapp/index.html
@@ -0,0 +1,30 @@
+<!--
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*  http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=/index">
+</head>
+
+<body>
+<p>Loading ...</p>
+</body>
+</html>
diff --git a/pom.xml b/pom.xml
index b1fd24b..7b57590 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,7 @@
         <module>helloworld</module>
         <module>http-session</module>
         <module>interceptors</module>
+        <module>jfreechart</module>
         <module>json</module>
         <module>json-customize</module>
         <module>mailreader2</module>

Reply via email to