java/cewolf-1.0/src/main/java/de/laures/cewolf/storage/AbstractSessionStorage.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.
23 package de.laures.cewolf.storage;
25 import java.io.Serializable;
27 import javax.servlet.ServletContext;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpSession;
30 import javax.servlet.jsp.PageContext;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
35 import de.laures.cewolf.CewolfException;
36 import de.laures.cewolf.ChartImage;
37 import de.laures.cewolf.Storage;
38 import de.laures.cewolf.taglib.util.KeyGenerator;
43 public abstract class AbstractSessionStorage implements Storage
46 private static final Log log = LogFactory.getLog(AbstractSessionStorage.class);
49 * @see de.laures.cewolf.Storage#storeChartImage(ChartImage, ServletContext)
51 public String storeChartImage( ChartImage cid, PageContext pageContext ) throws CewolfException
53 if ( contains(cid, pageContext) )
57 log.debug("storing chart " + cid);
58 final HttpSession session = pageContext.getSession();
59 //String key = getKey(cid);
60 return storeChartImage(cid, session);
65 * @see de.laures.cewolf.Storage#getChartImage(String)
67 public ChartImage getChartImage( String id, HttpServletRequest request )
69 HttpSession session = request.getSession();
70 return (ChartImage) session.getAttribute(id);
73 public boolean contains( ChartImage cid, PageContext pageContext )
75 return pageContext.getSession().getAttribute(getKey(cid)) != null;
78 public final String getKey( ChartImage cid )
80 return String.valueOf(KeyGenerator.generateKey((Serializable) cid));
83 protected String storeChartImage( ChartImage cid, HttpSession session ) throws CewolfException
85 final String sessionKey = getKey(cid);
86 synchronized (session)
88 session.setAttribute(sessionKey, getCacheObject(cid));
95 public String removeChartImage(String imgKey, HttpServletRequest request)
96 throws CewolfException {
97 final HttpSession session = request.getSession();
102 return removeChartImage(imgKey, session);
109 * @throws CewolfException
111 protected String removeChartImage(String cid, HttpSession session)
112 throws CewolfException {
113 synchronized (session) {
114 session.removeAttribute(cid);
119 protected abstract Object getCacheObject( ChartImage cid ) throws CewolfException;
122 * @see de.laures.cewolf.Storage#init(ServletContext)
124 public void init( ServletContext servletContext ) throws CewolfException