1 18 package net.sf.drftpd.master.queues; 19 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import net.sf.drftpd.ObjectNotFoundException; 27 import net.sf.drftpd.event.NukeEvent; 28 29 import org.jdom.Element; 30 import org.jdom.output.XMLOutputter; 31 32 37 public class NukeLog { 38 ArrayList nukes = new ArrayList (); 39 public NukeLog() { 40 } 41 42 public NukeEvent get(String path) throws ObjectNotFoundException { 43 for (Iterator iter = nukes.iterator(); iter.hasNext();) { 44 NukeEvent nuke= (NukeEvent) iter.next(); 45 if(nuke.getPath().equals(path)) return nuke; 46 } 47 throw new ObjectNotFoundException("No nukelog for: "+path); 48 } 49 50 public void remove(String path) throws ObjectNotFoundException { 51 for (Iterator iter = nukes.iterator(); iter.hasNext();) { 52 NukeEvent nuke= (NukeEvent) iter.next(); 53 if(nuke.getPath().equals(path)) { 54 iter.remove(); 55 return; 56 } 57 } 58 throw new ObjectNotFoundException("No nukelog for: "+path); 59 } 60 61 public void add(NukeEvent nuke) { 62 nukes.add(nuke); 63 XMLOutputter outputter = new XMLOutputter(" ", true); 70 try { 71 outputter.output(this.toXML(), new FileOutputStream ("nukelog.xml")); 72 } catch (IOException e) { 73 e.printStackTrace(); 74 } 75 } 76 public List getAll() { 77 return nukes; 78 } 79 public Element toXML() { 80 Element element = new Element("nukes"); 81 for (Iterator iter = getAll().iterator(); iter.hasNext();) { 82 NukeEvent nuke = (NukeEvent) iter.next(); 83 element.addContent(nuke.toJDOM()); 84 } 85 return element; 86 } 87 } 88 | Popular Tags |