diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/templates/ContributionTemplateStore.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/templates/ContributionTemplateStore.java index 1d9167b0126..18fb42cfe02 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/templates/ContributionTemplateStore.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/templates/ContributionTemplateStore.java @@ -17,6 +17,7 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -128,12 +129,12 @@ private void readIncludedTemplates(Collection templates String file= element.getAttribute(FILE); if (file != null) { Bundle plugin = Platform.getBundle(element.getContributor().getName()); - URL url= FileLocator.find(plugin, IPath.fromOSString(file), null); + URL url= resolveResource(plugin, file); if (url != null) { ResourceBundle bundle= null; String translations= element.getAttribute(TRANSLATIONS); if (translations != null) { - URL bundleURL= FileLocator.find(plugin, IPath.fromOSString(translations), null); + URL bundleURL= resolveResource(plugin, translations); if (bundleURL != null) { try (InputStream bundleStream= bundleURL.openStream()) { bundle= new PropertyResourceBundle(bundleStream); @@ -160,6 +161,28 @@ private void readIncludedTemplates(Collection templates } } + /** + * Resolves a resource location to a URL. Supports plain bundle-relative paths + * as well as platform:/ URIs which allow referencing files + * contributed by other plug-ins. + * + * @param plugin the contributing bundle, used for bundle-relative lookups + * @param location the resource location (a bundle-relative path or a + * platform:/ URI) + * @return the resolved URL, or null if it could not be found + */ + private static URL resolveResource(Bundle plugin, String location) { + if (location.startsWith("platform:/")) { //$NON-NLS-1$ + try { + return FileLocator.find(new URI(location).toURL()); + } catch (java.net.URISyntaxException | java.net.MalformedURLException e) { + EditorsPlugin.log(e); + return null; + } + } + return FileLocator.find(plugin, IPath.fromOSString(location), null); + } + /** * Validates a template against the context type registered in the context * type registry. Returns always true if no registry is