| 1 18 package org.drftpd.sections.def; 19 20 import java.io.FileNotFoundException ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.StringTokenizer ; 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 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 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 e) { 59 return dir; 60 } 61 } 62 63 public String getName() { 64 return _lrf.getName(); 65 } 66 67 public String 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 string) { 83 try { 84 return new Section(_cm.getRoot().getFile(string)); 85 } catch (FileNotFoundException e) { 86 return new Section(_cm.getRoot()); 87 } 88 } 89 90 public Collection getSections() { 91 ArrayList sections = new ArrayList (); 92 for (Iterator 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 string) { 104 StringTokenizer st = new StringTokenizer (string, "/"); 105 try { 106 return new Section(_cm.getRoot().getFile(st.nextToken())); 107 } catch (FileNotFoundException e) { 108 return new Section(_cm.getRoot()); 109 } 110 } 111 112 public void reload() { 113 } 114 } 115 | Popular Tags |