01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * 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;
21: import java.util.Collection;
22: import java.util.Collections;
23: import java.util.Properties;
24:
25: import org.drftpd.PropertyHelper;
26: import org.drftpd.remotefile.FileUtils;
27: import org.drftpd.remotefile.LinkedRemoteFileInterface;
28: import org.drftpd.sections.SectionInterface;
29:
30: /**
31: * @author mog
32: * @version $Id: PlainSection.java 847 2004-12-02 03:32:41Z mog $
33: */
34: public class PlainSection implements SectionInterface {
35: private String _dir;
36: private SectionManager _mgr;
37: private String _name;
38:
39: public PlainSection(SectionManager mgr, int i, Properties p) {
40: this (mgr, PropertyHelper.getProperty(p, i + ".name"),
41: PropertyHelper.getProperty(p, i + ".path"));
42: }
43:
44: public PlainSection(SectionManager mgr, String name, String path) {
45: _mgr = mgr;
46: _name = name;
47: _dir = path;
48:
49: if (!_dir.endsWith("/")) {
50: _dir += "/";
51: }
52:
53: //getFile();
54: }
55:
56: public LinkedRemoteFileInterface getFile() {
57: try {
58: return _mgr.getConnectionManager().getGlobalContext()
59: .getRoot().lookupFile(_dir);
60: } catch (FileNotFoundException e) {
61: return _mgr.getConnectionManager().getGlobalContext()
62: .getRoot().createDirectories(_dir);
63: }
64: }
65:
66: public Collection getFiles() {
67: return Collections.singletonList(getFile());
68: }
69:
70: public LinkedRemoteFileInterface getFirstDirInSection(
71: LinkedRemoteFileInterface dir) {
72: try {
73: return FileUtils.getSubdirOfDirectory(getFile(), dir);
74: } catch (FileNotFoundException e) {
75: return dir;
76: }
77: }
78:
79: public String getName() {
80: return _name;
81: }
82:
83: public String getPath() {
84: return _dir;
85: }
86:
87: public LinkedRemoteFileInterface getBaseFile() {
88: return getFile();
89: }
90:
91: public String getBasePath() {
92: return getPath();
93: }
94: }
|