ChartServlet.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:5k
源码类别:
OA系统
开发平台:
Java
- // Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-12-05 9:36:14
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: ChartServlet.java
- package cn.com.fcsoft.chart;
- import cn.com.fcsoft.chart.jpeg.JpegEncoder;
- import java.awt.*;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.Enumeration;
- import java.util.StringTokenizer;
- import javax.servlet.*;
- // Referenced classes of package com.objectplanet.chart:
- // ChartApplet, Chart, BarChartApplet, LineChartApplet,
- // PieChartApplet
- public class ChartServlet extends GenericServlet
- {
- public String encodeChartImage(Image image, OutputStream outputstream)
- throws IOException
- {
- if(image != null && outputstream != null)
- {
- JpegEncoder jpegencoder = new JpegEncoder(image, 75, outputstream);
- jpegencoder.Compress();
- outputstream.flush();
- }
- return "image/jpeg";
- }
- public ChartServlet()
- {
- }
- private final boolean hasValidLicense()
- {
- return true;
- }
- protected static Double[] getDoubleValues(String s)
- {
- Double adouble[] = null;
- if(s != null && !s.equals(""))
- {
- StringTokenizer stringtokenizer = new StringTokenizer(s, ",");
- adouble = new Double[stringtokenizer.countTokens()];
- for(int i = 0; i < adouble.length; i++)
- try
- {
- adouble[i] = new Double(stringtokenizer.nextToken());
- }
- catch(NumberFormatException _ex) { }
- }
- return adouble;
- }
- public synchronized void service(ServletRequest servletrequest, ServletResponse servletresponse)
- throws ServletException, IOException
- {
- Object obj = null;
- String s = servletrequest.getParameter("chart");
- s = s == null ? "bar" : s;
- if(s.equals("bar"))
- obj = barChart;
- else
- if(s.equals("line"))
- obj = lineChart;
- else
- if(s.equals("pie"))
- obj = pieChart;
- if(obj == null)
- return;
- ((ChartApplet) (obj)).theChart.setSize(300, 200);
- ((ChartApplet) (obj)).reset();
- ((ChartApplet) (obj)).setParameter("seriesCount", servletrequest.getParameter("seriesCount"));
- String s1 = servletrequest.getParameter("sampleCount");
- if(s1 == null || s1.trim().length() == 0)
- {
- Double adouble[] = getDoubleValues(servletrequest.getParameter("sampleValues"));
- int i = adouble == null ? 0 : adouble.length;
- int j = ((ChartApplet) (obj)).theChart.getSeriesCount();
- for(int k = 0; k < j; k++)
- {
- Double adouble1[] = getDoubleValues(servletrequest.getParameter("sampleValues_" + k));
- i = adouble1 == null ? i : Math.max(i, adouble1.length);
- }
- ((ChartApplet) (obj)).setParameter("sampleCount", i + "");
- } else
- {
- ((ChartApplet) (obj)).setParameter("sampleCount", s1);
- }
- String s2;
- String s3;
- for(Enumeration enumeration = servletrequest.getParameterNames(); enumeration.hasMoreElements(); ((ChartApplet) (obj)).setParameter(s2, s3))
- {
- s2 = (String)enumeration.nextElement();
- s3 = servletrequest.getParameter(s2);
- }
- ((ChartApplet) (obj)).setParameter("rangeStep", servletrequest.getParameter("rangeStep"));
- ((ChartApplet) (obj)).setParameter("range", servletrequest.getParameter("range"));
- ((ChartApplet) (obj)).setParameter("lowerRange", servletrequest.getParameter("lowerRange"));
- ((ChartApplet) (obj)).setParameter("rangeStep_2", servletrequest.getParameter("rangeStep_2"));
- ((ChartApplet) (obj)).setParameter("range_2", servletrequest.getParameter("range_2"));
- ((ChartApplet) (obj)).setParameter("lowerRange_2", servletrequest.getParameter("lowerRange_2"));
- Dimension dimension = ((ChartApplet) (obj)).theChart.getSize();
- Image image = ((ChartApplet) (obj)).theChart.getImage(dimension.width, dimension.height);
- if(!hasValidLicense())
- {
- Graphics g = image.getGraphics();
- g.setColor(Color.white);
- g.fillRect(0, dimension.height - 8, dimension.width, 8);
- g.setColor(Color.gray);
- g.setFont(new Font("Arial", 0, 9));
- g.drawString("www.fcsoft.com.cn www.fcsoft.com.cn www.fcsoft.com.cn www.fcsoft.com.cn www.fcsoft.com.cn", 0, dimension.height - 2);
- }
- String s4 = encodeChartImage(image, servletresponse.getOutputStream());
- if(s4 != null && s4.length() > 0)
- servletresponse.setContentType(s4);
- else
- servletresponse.setContentType("image");
- }
- public void init(ServletConfig servletconfig)
- {
- try
- {
- super.init(servletconfig);
- }
- catch(ServletException _ex) { }
- barChart = new BarChartApplet();
- lineChart = new LineChartApplet();
- pieChart = new PieChartApplet();
- barChart.init();
- lineChart.init();
- pieChart.init();
- }
- protected BarChartApplet barChart;
- protected LineChartApplet lineChart;
- protected PieChartApplet pieChart;
- }