1 11 package org.eclipse.core.internal.runtime; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 import org.eclipse.core.internal.boot.PlatformURLConnection; 16 import org.eclipse.core.internal.boot.PlatformURLHandler; 17 import org.eclipse.osgi.util.NLS; 18 import org.osgi.framework.Bundle; 19 20 24 public class PlatformURLPluginConnection extends PlatformURLConnection { 25 26 private Bundle target = null; 27 private static boolean isRegistered = false; 28 public static final String PLUGIN = "plugin"; 30 33 public PlatformURLPluginConnection(URL url) { 34 super(url); 35 } 36 37 40 protected boolean allowCaching() { 41 return true; 42 } 43 44 47 protected URL resolve() throws IOException { 48 String spec = url.getFile().trim(); 49 if (spec.startsWith("/")) spec = spec.substring(1); 51 if (!spec.startsWith(PLUGIN)) 52 throw new IOException (NLS.bind(CommonMessages.url_badVariant, url)); 53 int ix = spec.indexOf("/", PLUGIN.length() + 1); String ref = ix == -1 ? spec.substring(PLUGIN.length() + 1) : spec.substring(PLUGIN.length() + 1, ix); 55 String id = getId(ref); 56 Activator activator = Activator.getDefault(); 57 if (activator == null) 58 throw new IOException (CommonMessages.activator_not_available); 59 target = activator.getBundle(id); 60 if (target == null) 61 throw new IOException (NLS.bind(CommonMessages.url_resolvePlugin, url)); 62 if (ix == -1 || (ix + 1) >= spec.length()) 63 return target.getEntry("/"); URL result = target.getEntry(spec.substring(ix + 1)); 65 if (result != null) 66 return result; 67 return new URL (target.getEntry("/"), spec.substring(ix + 1)); 70 } 71 72 public static void startup() { 73 if (isRegistered) 75 return; 76 PlatformURLHandler.register(PLUGIN, PlatformURLPluginConnection.class); 77 isRegistered = true; 78 } 79 80 83 public URL [] getAuxillaryURLs() throws IOException { 84 if (target == null) { 85 String spec = url.getFile().trim(); 86 if (spec.startsWith("/")) spec = spec.substring(1); 88 if (!spec.startsWith(PLUGIN)) 89 throw new IOException (NLS.bind(CommonMessages.url_badVariant, url)); 90 int ix = spec.indexOf("/", PLUGIN.length() + 1); String ref = ix == -1 ? spec.substring(PLUGIN.length() + 1) : spec.substring(PLUGIN.length() + 1, ix); 92 String id = getId(ref); 93 Activator activator = Activator.getDefault(); 94 if (activator == null) 95 throw new IOException (CommonMessages.activator_not_available); 96 target = activator.getBundle(id); 97 if (target == null) 98 throw new IOException (NLS.bind(CommonMessages.url_resolvePlugin, url)); 99 } 100 Bundle[] fragments = Activator.getDefault().getFragments(target); 101 int fragmentLength = (fragments == null) ? 0 : fragments.length; 102 if (fragmentLength == 0) 103 return null; 104 URL [] result = new URL [fragmentLength]; 105 for (int i = 0; i < fragmentLength; i++) 106 result[i] = fragments[i].getEntry("/"); return result; 108 } 109 } 110 | Popular Tags |