| 1 18 package org.drftpd.sections.conf; 19 20 import java.io.FileNotFoundException ; 21 import java.text.SimpleDateFormat ; 22 import java.util.Collection ; 23 import java.util.Date ; 24 import java.util.Properties ; 25 26 import net.sf.drftpd.master.config.FtpConfig; 27 import net.sf.drftpd.remotefile.LinkedRemoteFile; 28 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface; 29 30 import org.drftpd.remotefile.FileUtils; 31 import org.drftpd.sections.SectionInterface; 32 33 37 public class DatedSection implements SectionInterface { 38 private String _basePath; 39 private SimpleDateFormat _dateFormat; 40 41 private SectionManager _mgr; 42 private String _name; 43 44 public DatedSection(SectionManager mgr, int i, Properties p) { 45 _mgr = mgr; 46 _name = FtpConfig.getProperty(p, i + ".name"); 47 _basePath = FtpConfig.getProperty(p, i + ".path"); 48 if(!_basePath.endsWith("/")) _basePath += "/"; 49 _dateFormat = 50 new SimpleDateFormat (FtpConfig.getProperty(p, i + ".dated")); 51 getBaseFile(); 52 } 53 54 public LinkedRemoteFile getBaseFile() { 55 try { 56 return _mgr.getConnectionManager().getRoot().lookupFile(_basePath); 57 } catch (FileNotFoundException e) { 58 return _mgr.getConnectionManager().getRoot().createDirectories(_basePath); 59 } 60 } 61 62 public LinkedRemoteFileInterface getFile() { 63 String dateDir = _dateFormat.format(new Date ()); 64 try { 65 return getBaseFile().lookupFile(dateDir); 66 } catch (FileNotFoundException e) { 67 return getBaseFile().createDirectories(dateDir); 68 } 69 } 70 71 public Collection getFiles() { 72 return getBaseFile().getDirectories(); 73 } 74 75 public LinkedRemoteFileInterface getFirstDirInSection(LinkedRemoteFileInterface dir) { 76 try { 77 return FileUtils.getSubdirOfDirectory(getFile(), dir); 78 } catch (FileNotFoundException e) { 79 return dir; 80 } 81 } 82 83 public String getName() { 84 return _name; 85 } 86 87 public String getPath() { 88 return getFile().getPath(); 89 } 90 } 91 | Popular Tags |