KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > sections > def > SectionManager


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.drftpd.sections.def;
19
20 import java.io.FileNotFoundException JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26
27 import net.sf.drftpd.master.ConnectionManager;
28 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface;
29
30 import org.drftpd.remotefile.FileUtils;
31 import org.drftpd.sections.SectionInterface;
32 import org.drftpd.sections.SectionManagerInterface;
33
34 /**
35  * @author mog
36  * @version $Id: SectionManager.java,v 1.6 2004/04/25 17:46:19 mog Exp $
37  */

38 public class SectionManager implements SectionManagerInterface {
39
40     public class Section implements SectionInterface {
41         private LinkedRemoteFileInterface _lrf;
42
43         public Section(LinkedRemoteFileInterface lrf) {
44             _lrf = lrf;
45         }
46
47         public LinkedRemoteFileInterface getFile() {
48             return _lrf;
49         }
50
51         public Collection JavaDoc getFiles() {
52             return Collections.singletonList(_lrf);
53         }
54
55         public LinkedRemoteFileInterface getFirstDirInSection(LinkedRemoteFileInterface dir) {
56             try {
57                 return FileUtils.getSubdirOfDirectory(getFile(), dir);
58             } catch (FileNotFoundException JavaDoc e) {
59                 return dir;
60             }
61         }
62
63         public String JavaDoc getName() {
64             return _lrf.getName();
65         }
66
67         public String JavaDoc getPath() {
68             return _lrf.getPath();
69         }
70     }
71
72     private ConnectionManager _cm;
73
74     public SectionManager(ConnectionManager cm) {
75         _cm = cm;
76     }
77
78     public ConnectionManager getConnectionManager() {
79         return _cm;
80     }
81
82     public SectionInterface getSection(String JavaDoc string) {
83         try {
84             return new Section(_cm.getRoot().getFile(string));
85         } catch (FileNotFoundException JavaDoc e) {
86             return new Section(_cm.getRoot());
87         }
88     }
89
90     public Collection JavaDoc getSections() {
91         ArrayList JavaDoc sections = new ArrayList JavaDoc();
92         for (Iterator JavaDoc iter =
93             _cm.getRoot().getDirectories().iterator();
94             iter.hasNext();
95             ) {
96             LinkedRemoteFileInterface dir =
97                 (LinkedRemoteFileInterface) iter.next();
98             sections.add(new Section(dir));
99         }
100         return sections;
101     }
102
103     public SectionInterface lookup(String JavaDoc string) {
104         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(string, "/");
105         try {
106             return new Section(_cm.getRoot().getFile(st.nextToken()));
107         } catch (FileNotFoundException JavaDoc e) {
108             return new Section(_cm.getRoot());
109         }
110     }
111
112     public void reload() {
113     }
114 }
115
Popular Tags