1 5 11 package com.opensymphony.webwork.dispatcher; 12 13 import com.opensymphony.webwork.ServletActionContext; 14 import com.opensymphony.xwork.ActionInvocation; 15 import com.opensymphony.xwork.Result; 16 import org.jfree.chart.ChartUtilities; 17 import org.jfree.chart.JFreeChart; 18 19 import javax.servlet.http.HttpServletResponse ; 20 import java.io.OutputStream ; 21 22 23 30 public class ChartResult implements Result { 31 33 JFreeChart chart; 34 boolean chartSet = false; 35 private int height; 36 private int width; 37 38 40 45 public void setChart(JFreeChart chart) { 46 this.chart = chart; 47 chartSet = true; 48 } 49 50 55 public void setHeight(int height) { 56 this.height = height; 57 } 58 59 64 public void setWidth(int width) { 65 this.width = width; 66 } 67 68 74 public void execute(ActionInvocation invocation) throws Exception { 75 JFreeChart chart = null; 76 77 if (chartSet) { 78 chart = this.chart; 79 } else { 80 chart = (JFreeChart) invocation.getStack().findValue("chart"); 81 } 82 83 if (chart == null) { 84 throw new NullPointerException ("No chart found"); 85 } 86 87 HttpServletResponse response = ServletActionContext.getResponse(); 88 OutputStream os = response.getOutputStream(); 89 ChartUtilities.writeChartAsPNG(os, chart, width, height); 90 os.flush(); 91 } 92 } 93 | Popular Tags |