1 4 5 9 10 package org.openlaszlo.servlets; 11 12 import java.io.File ; 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import javax.servlet.ServletContext ; 16 import javax.servlet.http.HttpSessionBindingEvent ; 17 import javax.servlet.http.HttpSessionBindingListener ; 18 import org.apache.log4j.*; 19 20 24 public class LZBindingListener 25 implements HttpSessionBindingListener 26 { 27 30 private static Logger mLogger = Logger.getLogger(LZBindingListener.class); 31 32 35 HashSet mTempFileNameSet; 36 37 40 public LZBindingListener(String fileName) 41 { 42 mTempFileNameSet = new HashSet (); 43 addTempFile(fileName); 44 } 45 46 50 public void valueBound(HttpSessionBindingEvent event) 51 { 52 mLogger.info("SessId bound " + event.getSession().getId()); 53 } 54 55 58 public synchronized void valueUnbound(HttpSessionBindingEvent event) 59 { 60 mLogger.info("SessID unbound " + event.getSession().getId()); 61 62 Iterator iter = mTempFileNameSet.iterator(); 64 while (iter.hasNext()) { 65 String fileName = (String )iter.next(); 66 File file = new File (fileName); 67 file.delete(); 68 } 69 mTempFileNameSet.clear(); 70 } 71 72 73 76 public synchronized void addTempFile(String fileName) 77 { 78 if (fileName == null || fileName.length() == 0) 79 return; 80 81 if (! mTempFileNameSet.contains(fileName)) 82 mTempFileNameSet.add(fileName); 83 } 84 85 86 89 public synchronized boolean delTempFile(String fileName) 90 { 91 if (fileName != null && mTempFileNameSet.contains(fileName)) { 92 mTempFileNameSet.remove(fileName); 93 File file = new File (fileName); 94 return file.delete(); 95 } 96 97 return false; 98 } 99 100 } 101 | Popular Tags |