Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,12 +129,12 @@ private void readIncludedTemplates(Collection<TemplatePersistenceData> 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);
Expand All @@ -160,6 +161,28 @@ private void readIncludedTemplates(Collection<TemplatePersistenceData> templates
}
}

/**
* Resolves a resource location to a URL. Supports plain bundle-relative paths
* as well as <code>platform:/</code> 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
* <code>platform:/</code> URI)
* @return the resolved URL, or <code>null</code> 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 <code>true</code> if no registry is
Expand Down
Loading