001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package net.sf.drftpd.master.queues;
019:
020: import net.sf.drftpd.ObjectNotFoundException;
021: import net.sf.drftpd.event.NukeEvent;
022:
023: import org.jdom.Element;
024:
025: import org.jdom.output.XMLOutputter;
026:
027: import java.io.FileOutputStream;
028: import java.io.IOException;
029:
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033: import java.util.Vector;
034: import java.util.Arrays;
035:
036: /**
037: * @author mog
038: *
039: * @version $Id: NukeLog.java 1187 2005-05-01 23:35:36Z zubov $
040: */
041: public class NukeLog {
042: ArrayList nukes = new ArrayList();
043:
044: public NukeLog() {
045: }
046:
047: public NukeEvent get(String path) throws ObjectNotFoundException {
048: for (Iterator iter = nukes.iterator(); iter.hasNext();) {
049: NukeEvent nuke = (NukeEvent) iter.next();
050:
051: if (nuke.getPath().equals(path)) {
052: return nuke;
053: }
054: }
055:
056: throw new ObjectNotFoundException("No nukelog for: " + path);
057: }
058:
059: public synchronized void remove(String path)
060: throws ObjectNotFoundException {
061: for (Iterator iter = nukes.iterator(); iter.hasNext();) {
062: NukeEvent nuke = (NukeEvent) iter.next();
063:
064: if (nuke.getPath().equals(path)) {
065: iter.remove();
066:
067: //Removes the <nuke> entry from nukelog.xml
068: XMLOutputter outputter = new XMLOutputter(" ", true);
069:
070: try {
071: outputter.output(toXML(), new FileOutputStream(
072: "nukelog.xml"));
073: } catch (IOException e) {
074: e.printStackTrace();
075: }
076:
077: return;
078: }
079: }
080:
081: throw new ObjectNotFoundException("No nukelog for: " + path);
082: }
083:
084: public synchronized void add(NukeEvent nuke) {
085: nukes.add(nuke);
086:
087: // try {
088: // ObjOut out = new ObjOut(new FileWriter("nukelog.xml"));
089: // out.writeObject(this);
090: // } catch (IOException e) {
091: // logger.warn("", e);
092: // }
093: XMLOutputter outputter = new XMLOutputter(" ", true);
094:
095: try {
096: outputter.output(toXML(), new FileOutputStream(
097: "nukelog.xml"));
098: } catch (IOException e) {
099: e.printStackTrace();
100: }
101: }
102:
103: public List getAll() {
104: return nukes;
105: }
106:
107: public synchronized Element toXML() {
108: Element element = new Element("nukes");
109:
110: for (Iterator iter = getAll().iterator(); iter.hasNext();) {
111: NukeEvent nuke = (NukeEvent) iter.next();
112: element.addContent(nuke.toJDOM());
113: }
114:
115: return element;
116: }
117:
118: public boolean find_fullpath(String path) {
119: for (Iterator iter = nukes.iterator(); iter.hasNext();) {
120: NukeEvent nuke = (NukeEvent) iter.next();
121: if (nuke.getPath().equals(path))
122: return true;
123: }
124: return false;
125: }
126: }
|