1 11 12 package org.eclipse.osgi.baseadaptor.bundlefile; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.util.Enumeration ; 17 import java.util.NoSuchElementException ; 18 import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg; 19 import org.eclipse.osgi.util.NLS; 20 21 25 public class DirBundleFile extends BundleFile { 26 27 32 public DirBundleFile(File basefile) throws IOException { 33 super(basefile); 34 if (!BundleFile.secureAction.exists(basefile) || !BundleFile.secureAction.isDirectory(basefile)) { 35 throw new IOException (NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_EXCEPTION, basefile)); 36 } 37 } 38 39 public File getFile(String path, boolean nativeCode) { 40 File filePath = new File (this.basefile, path); 41 if (BundleFile.secureAction.exists(filePath)) { 42 return filePath; 43 } 44 return null; 45 } 46 47 public BundleEntry getEntry(String path) { 48 File filePath = new File (this.basefile, path); 49 if (!BundleFile.secureAction.exists(filePath)) { 50 return null; 51 } 52 return new FileBundleEntry(filePath, path); 53 } 54 55 public boolean containsDir(String dir) { 56 File dirPath = new File (this.basefile, dir); 57 return BundleFile.secureAction.exists(dirPath) && BundleFile.secureAction.isDirectory(dirPath); 58 } 59 60 public Enumeration getEntryPaths(String path) { 61 if (path.length() > 0 && path.charAt(0) == '/') 62 path = path.substring(1); 63 final java.io.File pathFile = new java.io.File (basefile, path); 64 if (!BundleFile.secureAction.exists(pathFile)) 65 return null; 66 if (!BundleFile.secureAction.isDirectory(pathFile)) 67 return null; 68 final String [] fileList = BundleFile.secureAction.list(pathFile); 69 if (fileList == null || fileList.length == 0) 70 return null; 71 final String dirPath = path.length() == 0 || path.charAt(path.length() - 1) == '/' ? path : path + '/'; 72 return new Enumeration () { 73 int cur = 0; 74 75 public boolean hasMoreElements() { 76 return fileList != null && cur < fileList.length; 77 } 78 79 public Object nextElement() { 80 if (!hasMoreElements()) { 81 throw new NoSuchElementException (); 82 } 83 java.io.File childFile = new java.io.File (pathFile, fileList[cur]); 84 StringBuffer sb = new StringBuffer (dirPath).append(fileList[cur++]); 85 if (BundleFile.secureAction.isDirectory(childFile)) { 86 sb.append("/"); } 88 return sb.toString(); 89 } 90 }; 91 } 92 93 public void close() { 94 } 96 97 public void open() { 98 } 100 } 101 | Popular Tags |