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 PlatformURLFragmentConnection extends PlatformURLConnection { 25 26 private Bundle target = null; 27 private static boolean isRegistered = false; 28 public static final String FRAGMENT = "fragment"; 30 33 public PlatformURLFragmentConnection(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(FRAGMENT)) 52 throw new IOException (NLS.bind(CommonMessages.url_badVariant, url)); 53 int ix = spec.indexOf("/", FRAGMENT.length() + 1); String ref = ix == -1 ? spec.substring(FRAGMENT.length() + 1) : spec.substring(FRAGMENT.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_resolveFragment, url)); 62 URL result = target.getEntry("/"); if (ix == -1 || (ix + 1) >= spec.length()) 64 return result; 65 return new URL (result, spec.substring(ix + 1)); 66 } 67 68 public static void startup() { 69 if (isRegistered) 71 return; 72 PlatformURLHandler.register(FRAGMENT, PlatformURLFragmentConnection.class); 73 isRegistered = true; 74 } 75 } 76 | Popular Tags |