1 19 20 package org.netbeans.modules.options; 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileSystem; 28 import org.openide.filesystems.Repository; 29 import org.openide.util.Lookup; 30 31 public class Utils { 32 33 34 private static Map <String , FileObject> filesCache = new HashMap <String , FileObject> (); 35 public static FileObject getFileObject (String name, String ext, boolean create) 36 throws IOException { 37 FileObject r = (FileObject) filesCache.get (name + '.' + ext); 38 if (r != null) return r; 39 FileSystem fs = Repository.getDefault (). 40 getDefaultFileSystem (); 41 FileObject rootFolder = fs.getRoot (); 42 FileObject optionsFolder = rootFolder.getFileObject ("Options"); 43 if (optionsFolder == null) { 44 if (create) 45 optionsFolder = rootFolder.createFolder ("Options"); 46 else 47 return null; 48 } 49 FileObject fileObject = optionsFolder.getFileObject (name, ext); 50 if (fileObject == null) { 51 if (create) 52 fileObject = optionsFolder.createData (name, ext); 53 else 54 return null; 55 } 56 filesCache.put (name + '.' + ext, fileObject); 57 return fileObject; 58 } 59 60 public static Enumeration getInputStreams (String name, String ext) 61 throws IOException { 62 ClassLoader classLoader = (ClassLoader ) Lookup.getDefault (). 63 lookup (ClassLoader .class); 64 return classLoader.getResources ("META-INF/options/" + name + "." + ext); 65 } 66 } 67 | Popular Tags |