1 19 20 package org.netbeans.core.startup.layers; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URI ; 25 import java.net.URISyntaxException ; 26 import java.net.URL ; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.URLMapper; 29 import org.openide.modules.InstalledFileLocator; 30 import org.openide.util.Exceptions; 31 32 42 public class NbinstURLMapper extends URLMapper { 43 44 public static final String PROTOCOL = "nbinst"; 46 47 public NbinstURLMapper() { 48 } 49 50 55 public FileObject[] getFileObjects(URL url) { 56 return (PROTOCOL.equals(url.getProtocol())) ? decodeURL (url) : null; 57 } 58 59 62 public URL getURL(FileObject fo, int type) { 63 return null; 64 } 65 66 71 static FileObject[] decodeURL (URL url) { 72 assert url != null; 73 try { 74 URI uri = new URI (url.toExternalForm()); 75 String protocol = uri.getScheme(); 76 if (PROTOCOL.equals(protocol)) { 77 String module = uri.getHost(); 78 String path = uri.getPath(); 79 if (path.length()>0) { 80 try { 81 File file = InstalledFileLocator.getDefault().locate(path.substring(1),module,false); 82 if (file != null) { 83 return new FileObject[] {URLMapper.findFileObject(file.toURI().toURL())}; 84 } 85 } 86 catch (MalformedURLException mue) { 87 Exceptions.printStackTrace(mue); 88 } 89 } 90 } 91 } catch (URISyntaxException use) { 92 Exceptions.printStackTrace(use); 93 } 94 return null; 95 } 96 97 } 98 | Popular Tags |