use of org.knime.core.node.web.WebResourceLocator.WebResourceType in project knime-core by knime.
the class WebResourceController method getResourcesFromExtension.
private static Set<WebResourceLocator> getResourcesFromExtension(final IConfigurationElement resConfig) {
if (resConfig == null) {
return Collections.emptySet();
}
String pluginName = resConfig.getContributor().getName();
LinkedHashSet<WebResourceLocator> locators = new LinkedHashSet<WebResourceLocator>();
Map<String, String> resMap = getWebResources(resConfig);
Set<String> imports = new HashSet<String>();
// collect dependencies
for (IConfigurationElement depElement : resConfig.getChildren(ID_DEPENDENCY)) {
String dependencyID = depElement.getAttribute(ATTR_RES_BUNDLE_ID);
IConfigurationElement depConfig = getConfigurationFromID(ID_WEB_RES, ATTR_RES_BUNDLE_ID, dependencyID);
if (depConfig == null) {
LOGGER.error("Web ressource dependency could not be found: " + dependencyID + ". This is most likely an implementation error.");
continue;
}
locators.addAll(getResourcesFromExtension(depConfig));
}
// collect own import files
for (IConfigurationElement resElement : resConfig.getChildren(ID_IMPORT_RES)) {
String path = resElement.getAttribute(ATTR_PATH);
String type = resElement.getAttribute(ATTR_TYPE);
if (path != null && type != null) {
WebResourceType resType = WebResourceType.FILE;
if (type.equalsIgnoreCase("javascript")) {
resType = WebResourceType.JAVASCRIPT;
} else if (type.equalsIgnoreCase("css")) {
resType = WebResourceType.CSS;
}
String parent = path.substring(0, path.lastIndexOf('/') + 1);
String newParent = resMap.get(parent);
String sourcePath;
if (newParent != null) {
sourcePath = path.replace(parent, newParent);
} else {
sourcePath = path;
}
locators.add(new WebResourceLocator(pluginName, sourcePath, path, resType));
imports.add(sourcePath);
}
}
/* for (Entry<String, String> entry :resMap.entrySet()) {
String targetPath = entry.getKey();
String sourcePath = entry.getValue();
try {
URL url = new URL("platform:/plugin/" + pluginName);
File dir = new File(FileLocator.resolve(url).getFile());
File file = new File(dir, sourcePath);
if (file.exists()) {
addLocators(pluginName, locators, imports, file, sourcePath, targetPath);
}
} catch (Exception e) {
LOGGER.warn("Could not resolve web resource " + sourcePath, e);
}
}*/
return locators;
}
Aggregations