01: /*
02: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19:
20: package com.nabhinc.portlet.chart;
21:
22: import java.util.Hashtable;
23:
24: import com.nabhinc.core.AbstractServlet;
25: import javax.servlet.http.HttpSession;
26:
27: /**
28: *
29: *
30: * @author Padmanabh Dabke
31: * (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
32: */
33: public class ChartServlet extends AbstractServlet {
34:
35: private static final long serialVersionUID = -6141385940140502846L;
36:
37: private static final String CHART_ID_PARAM = "chartid";
38:
39: private static Hashtable csChartsTable = new Hashtable();
40:
41: /**
42: * Process incoming HTTP GET requests
43: *
44: * @param request Object that encapsulates the request to the servlet
45: * @param response Object that encapsulates the response from the servlet
46: */
47: public void doGet(javax.servlet.http.HttpServletRequest request,
48: javax.servlet.http.HttpServletResponse response)
49: throws javax.servlet.ServletException, java.io.IOException {
50:
51: Object[] chartData = null;
52:
53: String chartID = request.getParameter(CHART_ID_PARAM);
54: if (chartID == null) {
55: throw new javax.servlet.ServletException(
56: "Missing chart ID.");
57: }
58:
59: chartData = (Object[]) csChartsTable.get(chartID);
60:
61: if (chartData == null) {
62: HttpSession session = request.getSession();
63: chartData = (Object[]) session.getAttribute(chartID);
64: }
65:
66: if (chartData == null) {
67: throw new javax.servlet.ServletException("Chart with ID "
68: + chartID + " does not exist.");
69: }
70:
71: response.setContentType((String) chartData[0]);
72: byte[] bytes = (byte[]) chartData[1];
73: response.setContentLength(bytes.length);
74: response.getOutputStream().write(bytes);
75:
76: }
77:
78: }
|