1 11 package org.eclipse.core.internal.runtime; 12 13 import java.io.*; 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.core.runtime.IPath; 18 import org.eclipse.osgi.util.NLS; 19 import org.osgi.framework.Bundle; 20 21 public class PlatformURLMetaConnection extends PlatformURLConnection { 22 private Bundle target = null; 23 private static boolean isRegistered = false; 24 public static final String META = "meta"; 26 29 public PlatformURLMetaConnection(URL url) { 30 super(url); 31 } 32 33 36 protected URL resolve() throws IOException { 37 String spec = url.getFile().trim(); 38 if (spec.startsWith("/")) spec = spec.substring(1); 40 if (!spec.startsWith(META)) 41 throw new IOException(NLS.bind(CommonMessages.url_badVariant, url.toString())); 42 int ix = spec.indexOf("/", META.length() + 1); String ref = ix == -1 ? spec.substring(META.length() + 1) : spec.substring(META.length() + 1, ix); 44 String id = getId(ref); 45 Activator activator = Activator.getDefault(); 46 if (activator == null) 47 throw new IOException(CommonMessages.activator_not_available); 48 target = activator.getBundle(id); 49 if (target == null) 50 throw new IOException(NLS.bind(CommonMessages.url_resolvePlugin, url.toString())); 51 IPath path = MetaDataKeeper.getMetaArea().getStateLocation(target); 52 if (ix != -1 || (ix + 1) <= spec.length()) 53 path = path.append(spec.substring(ix + 1)); 54 return path.toFile().toURL(); 55 } 56 57 public static void startup() { 58 if (isRegistered) 60 return; 61 PlatformURLHandler.register(META, PlatformURLMetaConnection.class); 62 isRegistered = true; 63 } 64 65 68 public OutputStream getOutputStream() throws IOException { 69 URL resolved = getResolvedURL(); 71 if (resolved != null) { 72 String fileString = resolved.getFile(); 73 if (fileString != null) { 74 File file = new File(fileString); 75 String parent = file.getParent(); 76 if (parent != null) 77 new File(parent).mkdirs(); 78 return new FileOutputStream(file); 79 } 80 } 81 return null; 82 } 83 } 84 | Popular Tags |