1 19 20 package org.netbeans.modules.apisupport.jnlplauncher; 21 22 import java.io.File ; 23 import java.net.URI ; 24 import java.net.URL ; 25 import java.util.Iterator ; 26 import org.openide.modules.InstalledFileLocator; 27 import org.openide.util.NbBundle; 28 29 35 public class InstalledFileLocatorImpl extends InstalledFileLocator { 36 37 public InstalledFileLocatorImpl() {} 38 39 public File locate(String relativePath, String codeNameBase, boolean localized) { 40 if (localized) { 41 int i = relativePath.lastIndexOf('.'); 42 String baseName, ext; 43 if (i == -1 || i < relativePath.lastIndexOf('/')) { 44 baseName = relativePath; 45 ext = ""; 46 } else { 47 baseName = relativePath.substring(0, i); 48 ext = relativePath.substring(i); 49 } 50 Iterator <String > it = NbBundle.getLocalizingSuffixes(); 51 while (it.hasNext()) { 52 String locName = baseName + it.next() + ext; 53 File f = locate(locName, codeNameBase, false); 54 if (f != null) { 55 return f; 56 } 57 } 58 } else { 59 String userdir = System.getProperty("netbeans.user"); 60 if (userdir != null) { 61 File f = new File (userdir, relativePath.replace('/', File.separatorChar)); 62 if (f.exists()) { 63 return f; 64 } 65 } 66 String resource = "META-INF/clusterpath/" + relativePath; 67 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 68 URL found = loader.getResource(resource); 69 if (found != null) { 70 String foundS = found.toExternalForm(); 71 String prefix = "jar:"; 72 String suffix = "!/" + resource; 73 if (foundS.startsWith(prefix) && foundS.endsWith(suffix)) { 74 String infix = foundS.substring(prefix.length(), foundS.length() - suffix.length()); 75 if (infix.startsWith("file:")) { 76 File jar = new File (URI.create(infix)); 77 assert jar.isFile(); 78 return jar; 79 } 80 } 81 } 82 } 83 return null; 84 } 85 86 } 87 | Popular Tags |