| 1 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 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 35 public class PlainSection implements SectionInterface { 36 private String _dir; 37 38 private SectionManager _mgr; 39 private String _name; 40 41 public PlainSection(SectionManager mgr, int i, Properties p) { 42 this(mgr, FtpConfig.getProperty(p, i + ".name"), FtpConfig.getProperty(p, i + ".path")); 43 } 44 45 public PlainSection(SectionManager mgr, String name, String path) { 46 _mgr = mgr; 47 _name = name; 48 _dir = path; 49 if(!_dir.endsWith("/")) _dir += "/"; 50 } 52 53 public LinkedRemoteFileInterface getFile() { 54 try { 55 return _mgr.getConnectionManager().getRoot().lookupFile(_dir); 56 } catch (FileNotFoundException e) { 57 return _mgr.getConnectionManager().getRoot().createDirectories(_dir); 58 } 59 } 60 61 public Collection 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 e) { 69 return dir; 70 } 71 } 72 73 public String getName() { 74 return _name; 75 } 76 77 public String getPath() { 78 return _dir; 79 } 80 } 81 | Popular Tags |