1 11 package org.eclipse.pde.internal.core.schema; 12 13 import java.io.File ; 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.core.plugin.PluginRegistry; 21 import org.eclipse.pde.internal.core.ischema.ISchema; 22 import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor; 23 24 public class IncludedSchemaDescriptor implements ISchemaDescriptor { 25 private URL fSchemaURL; 26 private String fSchemaLocation; 27 private Schema fSchema; 28 private long fLastModified; 29 30 public IncludedSchemaDescriptor(URL schemaURL) { 31 fSchemaURL = schemaURL; 32 File file = new File (fSchemaURL.getFile()); 33 if (file.exists()) 34 fLastModified = file.lastModified(); 35 } 36 37 public static URL computeURL(ISchemaDescriptor parentDesc, String schemaLocation) throws MalformedURLException { 38 URL parentURL = parentDesc == null ? null : parentDesc.getSchemaURL(); 39 if (schemaLocation.startsWith("schema://")) { IPath path = new Path( schemaLocation.substring(9)); 42 return getPluginRelativePath(path.segment(0), path.removeFirstSegments(1), parentURL); 43 } 44 45 if (parentURL == null) 46 return null; 47 48 IPath path = new Path(parentURL.getPath()); 50 path = path.removeLastSegments(1).append(schemaLocation); 51 return new URL (parentURL.getProtocol(), parentURL.getHost(), path.toString()); 52 } 53 54 private static URL getPluginRelativePath(String pluginID, IPath path, URL parentURL) { 55 URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString()); 56 if (url == null) { 57 IPluginModelBase model = PluginRegistry.findModel(pluginID); 58 if (model != null) 59 url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path); 60 } 61 try { 62 if (url == null && parentURL != null) { 63 String parentFile = parentURL.getFile(); 64 if (parentFile == null) 65 return null; 66 int lastSep = parentFile.lastIndexOf(File.separatorChar); 67 parentFile = parentFile.substring(0, lastSep + 1); 68 File file = new File (parentFile + "../../" + pluginID + "/" + path.toString()); if (file.exists() && file.isFile()) 71 url = file.toURL(); 72 } 73 } catch (MalformedURLException e) { 74 } 75 return url; 76 } 77 78 81 public boolean isEnabled() { 82 return true; 83 } 84 85 88 public String getPointId() { 89 int dotLoc = fSchemaLocation.lastIndexOf('.'); 90 if (dotLoc!= -1) { 91 return fSchemaLocation.substring(0, dotLoc); 92 } 93 return null; 94 } 95 96 99 public URL getSchemaURL() { 100 return fSchemaURL; 101 } 102 103 106 public ISchema getSchema(boolean abbreviated) { 107 if (fSchema == null && fSchemaURL != null) { 108 fSchema = new Schema(this, fSchemaURL, abbreviated); 109 fSchema.load(); 110 } 111 return fSchema; 112 } 113 114 117 public boolean isStandalone() { 118 return false; 119 } 120 121 124 public long getLastModified() { 125 return fLastModified; 126 } 127 128 } 129 | Popular Tags |