KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > servlet > ChartDeleter


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -----------------
27  * ChartDeleter.java
28  * -----------------
29   * (C) Copyright 2002-2004, by Richard Atkinson and Contributors.
30  *
31  * Original Author: Richard Atkinson;
32  * Contributor(s): -;
33  *
34  * $Id: ChartDeleter.java,v 1.2 2005/03/09 14:07:16 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 19-Aug-2002 : Version 1;
39  * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG);
40  *
41  */

42 package org.jfree.chart.servlet;
43
44 import java.io.File JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47
48 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
49 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
50
51 /**
52  * Used for deleting charts from the temporary directory when the users session
53  * expires.
54  *
55  * @author Richard Atkinson
56  */

57 public class ChartDeleter implements HttpSessionBindingListener JavaDoc {
58
59     /** The chart names. */
60     private List JavaDoc chartNames = new java.util.ArrayList JavaDoc();
61
62     /**
63      * Blank constructor.
64      */

65     public ChartDeleter() {
66         super();
67     }
68
69     /**
70      * Add a chart to be deleted when the session expires
71      *
72      * @param filename the name of the chart in the temporary directory to be
73      * deleted.
74      */

75     public void addChart(String JavaDoc filename) {
76         this.chartNames.add(filename);
77     }
78
79     /**
80      * Checks to see if a chart is in the list of charts to be deleted
81      *
82      * @param filename the name of the chart in the temporary directory.
83      *
84      * @return A boolean value indicating whether the chart is present in the
85      * list.
86      */

87     public boolean isChartAvailable(String JavaDoc filename) {
88         return (this.chartNames.contains(filename));
89     }
90
91     /**
92      * Binding this object to the session has no additional effects.
93      *
94      * @param event the session bind event.
95      */

96     public void valueBound(HttpSessionBindingEvent JavaDoc event) {
97         return;
98     }
99
100     /**
101      * When this object is unbound from the session (including upon session
102      * expiry) the files that have been added to the ArrayList are iterated
103      * and deleted.
104      *
105      * @param event the session unbind event.
106      */

107     public void valueUnbound(HttpSessionBindingEvent JavaDoc event) {
108
109         Iterator JavaDoc iter = this.chartNames.listIterator();
110         while (iter.hasNext()) {
111             String JavaDoc filename = (String JavaDoc) iter.next();
112             File JavaDoc file = new File JavaDoc(
113                 System.getProperty("java.io.tmpdir"), filename
114             );
115             if (file.exists()) {
116                 file.delete();
117             }
118         }
119         return;
120
121     }
122
123 }
124
Popular Tags