KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > sections > conf > PlainSection


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.conf;
19
20 import java.io.FileNotFoundException JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import net.sf.drftpd.master.config.FtpConfig;
26 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface;
27
28 import org.drftpd.remotefile.FileUtils;
29 import org.drftpd.sections.SectionInterface;
30
31 /**
32  * @author mog
33  * @version $Id: PlainSection.java,v 1.6 2004/04/25 17:46:19 mog Exp $
34  */

35 public class PlainSection implements SectionInterface {
36     private String JavaDoc _dir;
37
38     private SectionManager _mgr;
39     private String JavaDoc _name;
40
41     public PlainSection(SectionManager mgr, int i, Properties JavaDoc p) {
42         this(mgr, FtpConfig.getProperty(p, i + ".name"), FtpConfig.getProperty(p, i + ".path"));
43     }
44
45     public PlainSection(SectionManager mgr, String JavaDoc name, String JavaDoc path) {
46         _mgr = mgr;
47         _name = name;
48         _dir = path;
49         if(!_dir.endsWith("/")) _dir += "/";
50         //getFile();
51
}
52
53     public LinkedRemoteFileInterface getFile() {
54         try {
55             return _mgr.getConnectionManager().getRoot().lookupFile(_dir);
56         } catch (FileNotFoundException JavaDoc e) {
57             return _mgr.getConnectionManager().getRoot().createDirectories(_dir);
58         }
59     }
60
61     public Collection JavaDoc getFiles() {
62         return Collections.singletonList(getFile());
63     }
64
65     public LinkedRemoteFileInterface getFirstDirInSection(LinkedRemoteFileInterface dir) {
66         try {
67             return FileUtils.getSubdirOfDirectory(getFile(), dir);
68         } catch (FileNotFoundException JavaDoc e) {
69             return dir;
70         }
71     }
72
73     public String JavaDoc getName() {
74         return _name;
75     }
76
77     public String JavaDoc getPath() {
78         return _dir;
79     }
80 }
81
Popular Tags