java/cewolf-1.0/src/main/java/de/laures/cewolf/storage/LongTermSessionStorage.java
1 /* ================================================================
2 * Cewolf : Chart enabling Web Objects Framework
3 * ================================================================
5 * Project Info: http://cewolf.sourceforge.net
6 * Project Lead: Guido Laures (guido@laures.de);
8 * (C) Copyright 2002, by Guido Laures
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 package de.laures.cewolf.storage;
24 import java.io.Serializable;
26 import javax.servlet.ServletContext;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29 import javax.servlet.jsp.PageContext;
31 import de.laures.cewolf.CewolfException;
32 import de.laures.cewolf.ChartImage;
33 import de.laures.cewolf.Storage;
34 import de.laures.cewolf.taglib.util.KeyGenerator;
37 * Storage stores images in session, but expires them after a certain time.
38 * This expiration time defaults to 300 seconds, and can be changed by adding
39 * the timeout="xxx" parameter to <cewolf:img> and <cewolf:legend> tags.
43 public class LongTermSessionStorage implements Storage
46 public final String getKey( ChartImage cid )
48 return String.valueOf(KeyGenerator.generateKey((Serializable) cid));
54 * @see de.laures.cewolf.Storage#storeChartImage(de.laures.cewolf.ChartImage,
55 * javax.servlet.jsp.PageContext)
57 public String storeChartImage( ChartImage chartImage, PageContext pageContext ) throws CewolfException
59 HttpSession session = pageContext.getSession();
60 SessionStorageGroup ssg = (SessionStorageGroup) session.getAttribute("CewolfCharts");
63 ssg = new SessionStorageGroup();
64 session.setAttribute("CewolfCharts", ssg);
66 String cid = getKey(chartImage);
67 SessionStorageItem ssi = new SessionStorageItem(chartImage, cid, chartImage.getTimeoutTime());
76 * @see de.laures.cewolf.Storage#getChartImage(java.lang.String,
77 * javax.servlet.http.HttpServletRequest)
79 public ChartImage getChartImage( String id, HttpServletRequest request )
81 HttpSession session = request.getSession();
82 ChartImage chart = null;
83 SessionStorageGroup ssg = (SessionStorageGroup) session.getAttribute("CewolfCharts");
86 SessionStorageItem ssi = (SessionStorageItem) ssg.get(id);
89 chart = ssi.getChart();
98 * @see de.laures.cewolf.Storage#init(javax.servlet.ServletContext)
100 public void init( ServletContext servletContext ) throws CewolfException {
104 * @see de.laures.cewolf.Storage#removeChartImage(java.lang.String, javax.servlet.jsp.PageContext)
106 public String removeChartImage(String cid, HttpServletRequest request) throws CewolfException {
107 HttpSession session = request.getSession();
113 SessionStorageGroup ssg = (SessionStorageGroup) session.getAttribute("CewolfCharts");