001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------------
028: * ChartDeleter.java
029: * -----------------
030: * (C) Copyright 2002-2007, by Richard Atkinson and Contributors.
031: *
032: * Original Author: Richard Atkinson;
033: * Contributor(s): -;
034: *
035: * $Id: ChartDeleter.java,v 1.2.2.3 2007/02/02 15:03:19 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 19-Aug-2002 : Version 1;
040: * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041: * ------------- JFREECHART 1.0.x ---------------------------------------------
042: * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
043: *
044: */
045: package org.jfree.chart.servlet;
046:
047: import java.io.File;
048: import java.io.Serializable;
049: import java.util.Iterator;
050: import java.util.List;
051:
052: import javax.servlet.http.HttpSessionBindingEvent;
053: import javax.servlet.http.HttpSessionBindingListener;
054:
055: /**
056: * Used for deleting charts from the temporary directory when the users session
057: * expires.
058: */
059: public class ChartDeleter implements HttpSessionBindingListener,
060: Serializable {
061:
062: /** The chart names. */
063: private List chartNames = new java.util.ArrayList();
064:
065: /**
066: * Blank constructor.
067: */
068: public ChartDeleter() {
069: super ();
070: }
071:
072: /**
073: * Add a chart to be deleted when the session expires
074: *
075: * @param filename the name of the chart in the temporary directory to be
076: * deleted.
077: */
078: public void addChart(String filename) {
079: this .chartNames.add(filename);
080: }
081:
082: /**
083: * Checks to see if a chart is in the list of charts to be deleted
084: *
085: * @param filename the name of the chart in the temporary directory.
086: *
087: * @return A boolean value indicating whether the chart is present in the
088: * list.
089: */
090: public boolean isChartAvailable(String filename) {
091: return (this .chartNames.contains(filename));
092: }
093:
094: /**
095: * Binding this object to the session has no additional effects.
096: *
097: * @param event the session bind event.
098: */
099: public void valueBound(HttpSessionBindingEvent event) {
100: return;
101: }
102:
103: /**
104: * When this object is unbound from the session (including upon session
105: * expiry) the files that have been added to the ArrayList are iterated
106: * and deleted.
107: *
108: * @param event the session unbind event.
109: */
110: public void valueUnbound(HttpSessionBindingEvent event) {
111:
112: Iterator iter = this .chartNames.listIterator();
113: while (iter.hasNext()) {
114: String filename = (String) iter.next();
115: File file = new File(System.getProperty("java.io.tmpdir"),
116: filename);
117: if (file.exists()) {
118: file.delete();
119: }
120: }
121: return;
122:
123: }
124:
125: }
|