From 2337b4dcd73a5aa020dc109f1f6bb20a7962ca50 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Fri, 11 Jan 2013 00:35:43 +0100 Subject: [PATCH] removed servlet dependency --- pom.xml | 10 --- .../java/com/xeiam/xchart/ServletEncoder.java | 55 ------------- .../xchart/example/ChartServletExample.java | 79 ------------------- 3 files changed, 144 deletions(-) delete mode 100644 src/main/java/com/xeiam/xchart/ServletEncoder.java delete mode 100644 src/test/java/com/xeiam/xchart/example/ChartServletExample.java diff --git a/pom.xml b/pom.xml index 2af598c0..320399c0 100644 --- a/pom.xml +++ b/pom.xml @@ -42,16 +42,6 @@ <url>http://ci.xeiam.com/</url> </ciManagement> - <dependencies> - <!-- only needed if using XCharts as part of a webapp --> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <version>3.0.1</version> - <scope>provided</scope> - </dependency> - </dependencies> - <build> <plugins> <!-- Ensure compilation is done under Java 6 in all environments --> diff --git a/src/main/java/com/xeiam/xchart/ServletEncoder.java b/src/main/java/com/xeiam/xchart/ServletEncoder.java deleted file mode 100644 index ca8a699b..00000000 --- a/src/main/java/com/xeiam/xchart/ServletEncoder.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2011-2013 Xeiam LLC. - * - * Licensed 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.io.IOException; - -import javax.imageio.ImageIO; -import javax.servlet.ServletOutputStream; - -/** - * A helper class to be used in conjuction with a Servlet for streaming a Chart to an HTTP client - * - * @author timmolter - */ -public final class ServletEncoder { - - /** - * Constructor - Private constructor to prevent instantiation - */ - private ServletEncoder() { - - } - - /** - * Streams a chart as a PNG file - * - * @param out - * @param chart - * @throws IOException - */ - public static void streamPNG(ServletOutputStream out, Chart chart) throws IOException { - - BufferedImage lBufferedImage = new BufferedImage(chart.width, chart.height, BufferedImage.TYPE_INT_RGB); - Graphics2D lGraphics2D = lBufferedImage.createGraphics(); - chart.paint(lGraphics2D); - - ImageIO.write(lBufferedImage, "png", out); - out.close(); - } -} diff --git a/src/test/java/com/xeiam/xchart/example/ChartServletExample.java b/src/test/java/com/xeiam/xchart/example/ChartServletExample.java deleted file mode 100644 index bcb8e05c..00000000 --- a/src/test/java/com/xeiam/xchart/example/ChartServletExample.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright 2011-2013 Xeiam LLC. - * - * Licensed 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 com.xeiam.xchart.example; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import com.xeiam.xchart.Chart; -import com.xeiam.xchart.QuickChart; -import com.xeiam.xchart.ServletEncoder; - -/** - * Generates, stores, and serves charts - * - * @author timmolter - */ -@javax.servlet.annotation.WebServlet(name = "ChartServlet", urlPatterns = { "/chart" }, asyncSupported = true) -public class ChartServletExample extends HttpServlet { - - private static Map<String, Chart> chartMap = new HashMap<String, Chart>(); - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { - - String id = request.getParameter("id"); - - Chart chart = chartMap.get(id); - - response.setContentType("image/png"); - ServletOutputStream out = response.getOutputStream(); - - try { - ServletEncoder.streamPNG(out, chart); - } catch (Exception e) { - e.printStackTrace(); - } - - out.close(); - - chart = null; - - chartMap.remove(id); - } - - /** - * Generates a chart and puts it in chartMap - * - * @return UUID uniquely identifying chart in the chartMap - */ - public static String generateDummyChart() { - - Chart chart = QuickChart.getChart("Sample Chart", "X", "Y", null, null, new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); - String uuid = UUID.randomUUID().toString(); - chartMap.put(uuid, chart); - - return uuid; - } - -} -- GitLab