use of org.knime.workbench.repository.model.Root in project knime-core by knime.
the class NodeDescriptionConverter method writeCategoryTocFile.
private void writeCategoryTocFile(final Category c) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
doc.appendChild(doc.createProcessingInstruction("NLS", "TYPE=\"org.eclipse.help.toc\""));
Element root = doc.createElement("toc");
if (c.getParent() instanceof Root) {
root.setAttribute("link_to", "../" + "org.knime.workbench.help" + "/toc.xml#" + ROOT_ANCHOR);
root.setAttribute("label", fileName(getFullPath(c)));
/*
* <toc link_to=../org.knime.workbench.help/toc.xml#root
* label=c.getID()
*/
} else {
String parentsPluginID = ((Category) c.getParent()).getContributingPlugin();
String parent = fileName(getFullPath((Category) c.getParent()));
root.setAttribute("link_to", "../" + parentsPluginID + "/" + TOC_DIR + "/" + parent + ".xml#" + parent);
root.setAttribute("label", parent);
/*
* <toc link_to="../c.getParent().getPluginID()/
* c.getParent().getID.xml#c.getID() label=c.getID() >
*/
}
Element topic = doc.createElement("topic");
topic.setAttribute("label", htmlString(c.getName()));
Element anchor = doc.createElement("anchor");
anchor.setAttribute("id", fileName(getFullPath(c)));
topic.appendChild(anchor);
root.appendChild(topic);
doc.appendChild(root);
/*
* <topic label="htmlString(c.getName());> <anchor id=c.getID />
* </topic> </toc>
*/
writeTocToPluginXML(c, false);
/*
* <extension point="org.eclipse.help.toc"> <toc file="toc.xml"> </toc>
* </extension>
*/
writeNodeTocFile(doc, fileName(getFullPath(c)));
}
use of org.knime.workbench.repository.model.Root in project knime-core by knime.
the class RepositoryManager method readNodes.
/**
* @param isInExpertMode
*/
private void readNodes(final IProgressMonitor monitor) {
//
// Second, process the contributed nodes
//
IContainerObject uncategorized = m_root.findContainer("/uncategorized");
if (uncategorized == null) {
// this should never happen, but who knows...
uncategorized = m_root;
}
Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
while (it.hasNext()) {
IConfigurationElement elem = it.next();
if (monitor.isCanceled()) {
return;
}
try {
NodeTemplate node = RepositoryFactory.createNode(elem);
LOGGER.debug("Found node extension '" + node.getID() + "': " + node.getName());
for (Listener l : m_loadListeners) {
l.newNode(m_root, node);
}
m_nodesById.put(node.getID(), node);
String nodeName = node.getID();
nodeName = nodeName.substring(nodeName.lastIndexOf('.') + 1);
// Ask the root to lookup the category-container located at
// the given path
IContainerObject parentContainer = m_root.findContainer(node.getCategoryPath());
// the node to the repository root.
if (parentContainer == null) {
LOGGER.coding("Unknown category for node " + node.getID() + " (plugin: " + node.getContributingPlugin() + "): " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
uncategorized.addChild(node);
} else {
String nodePluginId = elem.getNamespaceIdentifier();
String categoryPluginId = parentContainer.getContributingPlugin();
if (categoryPluginId == null) {
categoryPluginId = "";
}
int secondDotIndex = nodePluginId.indexOf('.', nodePluginId.indexOf('.') + 1);
if (secondDotIndex == -1) {
secondDotIndex = 0;
}
if (!parentContainer.isLocked() || nodePluginId.equals(categoryPluginId) || nodePluginId.startsWith("org.knime.") || nodePluginId.startsWith("com.knime.") || nodePluginId.regionMatches(0, categoryPluginId, 0, secondDotIndex)) {
// container not locked, or node and category from same plug-in
// or the vendor is the same (comparing the first two parts of the plug-in ids)
parentContainer.addChild(node);
} else {
LOGGER.coding("Locked category for node " + node.getID() + ": " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
uncategorized.addChild(node);
}
}
} catch (Throwable t) {
String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
Bundle bundle = Platform.getBundle(elem.getNamespaceIdentifier());
if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
// if the plugin is null, the plugin could not
// be activated maybe due to a not
// activateable plugin (plugin class cannot be found)
message += " The corresponding plugin " + "bundle could not be activated!";
}
LOGGER.error(message, t);
}
}
// for configuration elements
}
use of org.knime.workbench.repository.model.Root in project knime-core by knime.
the class RepositoryManager method readNodeSets.
/**
* @param isInExpertMode
*/
private void readNodeSets(final IProgressMonitor monitor) {
//
// Process the contributed node sets
//
Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE_SET)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
while (it.hasNext()) {
IConfigurationElement elem = it.next();
try {
Collection<DynamicNodeTemplate> dynamicNodeTemplates = RepositoryFactory.createNodeSet(m_root, elem);
for (DynamicNodeTemplate node : dynamicNodeTemplates) {
if (monitor.isCanceled()) {
return;
}
for (Listener l : m_loadListeners) {
l.newNode(m_root, node);
}
m_nodesById.put(node.getID(), node);
String nodeName = node.getID();
nodeName = nodeName.substring(nodeName.lastIndexOf('.') + 1);
// Ask the root to lookup the category-container located
// at
// the given path
IContainerObject parentContainer = m_root.findContainer(node.getCategoryPath());
// the node to the repository root.
if (parentContainer == null) {
LOGGER.warn("Invalid category-path for node " + "contribution: '" + node.getCategoryPath() + "' - adding to root instead");
m_root.addChild(node);
} else {
// everything is fine, add the node to its parent
// category
parentContainer.addChild(node);
}
}
} catch (Throwable t) {
String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created.";
Bundle bundle = Platform.getBundle(elem.getNamespaceIdentifier());
if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
// if the plugin is null, the plugin could not
// be activated maybe due to a not
// activateable plugin (plugin class cannot be found)
message += " The corresponding plugin " + "bundle could not be activated!";
}
LOGGER.error(message, t);
}
}
}
use of org.knime.workbench.repository.model.Root in project knime-core by knime.
the class TanimotoTextualViewFilter method doSelect.
/**
* Copied from {@link TextualViewFilter}.
*/
@Override
protected boolean doSelect(final Object parentElement, final Object element, final boolean recurse) {
boolean selectThis = false;
// Node Template : Match against name
if (element instanceof AbstractNodeTemplate) {
// check against node name
selectThis = match(((AbstractNodeTemplate) element).getName());
if (element instanceof MetaNodeTemplate) {
// with meta nodes also check the name of the workflow manager
selectThis |= match(((MetaNodeTemplate) element).getManager().getName());
}
if (selectThis) {
return true;
}
// we must also check towards root, as we want to include all
// children of a selected category
IRepositoryObject temp = (IRepositoryObject) parentElement;
while (!(temp instanceof Root)) {
// check parent category, but do *not* recurse !!!!
if (doSelect(temp.getParent(), temp, false)) {
return true;
}
temp = temp.getParent();
}
} else // Category: Match against name and children
if (element instanceof Category) {
// check against node name
selectThis = match(((Category) element).getName());
if (selectThis) {
return true;
}
// check recursively against children, if needed
if (recurse) {
Category category = (Category) element;
IRepositoryObject[] children = category.getChildren();
for (int i = 0; i < children.length; i++) {
// recursively check. return true on first matching child
if (doSelect(category, children[i], true)) {
return true;
}
}
}
}
return false;
}
use of org.knime.workbench.repository.model.Root in project knime-core by knime.
the class NodeDocuGenerator method generate.
/**
* Recursively generates the nodes description documents and the menu entries.
*
* @param directory
* @param current
* @param parent parent repository object as some nodes pointing to "frequently used"-repository object as a parent
* @throws Exception
* @throws TransformerException
*
* @return true, if the element was added to the documentation, false if it has been skipped
*/
private boolean generate(final File directory, final IRepositoryObject current, final IRepositoryObject parent) throws TransformerException, Exception {
// current length of the repository string to be able to revert it to
// the current state
int currentLength = m_nodeRepository.length();
if (current instanceof NodeTemplate) {
// skip node if not part of the specified plugin
if (m_pluginId != null && !current.getContributingPlugin().equals(m_pluginId)) {
return false;
}
// as argument
if (m_catPath.length() > 0) {
String catIdentifier = getCategoryIdentifier((Category) parent);
if (!catIdentifier.startsWith(m_catPath)) {
return false;
}
}
// ((NodeTemplate)current).getID();
String nodeIdentifier = cleanNodeIdForFileName((NodeTemplate) current);
// write icon to disc
URL iconURL = ((NodeTemplate) current).createFactoryInstance().getIcon();
String nodeIcon;
if (iconURL != null) {
writeStreamToFile(iconURL.openStream(), nodeIdentifier + ".png");
nodeIcon = nodeIdentifier + ".png";
} else {
nodeIcon = "knime_default_icon.png";
}
// the node repository-like menu
m_nodeRepository.append("<li style=\"list-style-image: url(");
m_nodeRepository.append(nodeIcon);
m_nodeRepository.append(");\" class=\"knime-node\"><span class=\"childs\"><a href=\"");
m_nodeRepository.append(current.getID());
m_nodeRepository.append(".html\" target=\"Node Description\">");
m_nodeRepository.append(((NodeTemplate) current).getName());
m_nodeRepository.append("</a></span></li>\n");
// create page with node description and return, as no more
// children
// are available
Writer nodeDoc = createDocumentWriter(cleanNodeIdForFileName((NodeTemplate) current) + ".html", directory);
String nodeDescription = NodeFactoryHTMLCreator.instance.readFullDescription(((NodeTemplate) current).createFactoryInstance().getXMLDescription());
// extract the body of the node description html-document
nodeDescription = nodeDescription.substring(nodeDescription.indexOf("<body>") + 6, nodeDescription.indexOf("</body>"));
nodeDescription = m_nodeDescriptionTemplate.replace("[NODE_DESCRIPTION]", nodeDescription);
nodeDoc.write(nodeDescription);
nodeDoc.flush();
nodeDoc.close();
return true;
} else if (current instanceof Category || current instanceof Root) {
System.out.println("Processing category " + getPath(current));
IRepositoryObject[] repoObjs = ((IContainerObject) current).getChildren();
if (current instanceof Category) {
String catIdentifier = getCategoryIdentifier((Category) current);
// write icon to disc and add html-tags
ImageLoader loader = new ImageLoader();
Image catImg = ((Category) current).getIcon();
String catIcon;
if (catImg != null) {
loader.data = new ImageData[] { catImg.getImageData() };
loader.save(directory + File.separator + catIdentifier + ".png", SWT.IMAGE_PNG);
catIcon = catIdentifier + ".png";
} else {
catIcon = "knime_default_icon.png";
}
m_nodeRepository.append("<li class=\"knime-category\">");
m_nodeRepository.append("<img width=\"16px\" src=\"");
m_nodeRepository.append(catIcon);
m_nodeRepository.append("\"/> ");
m_nodeRepository.append(((Category) current).getName());
m_nodeRepository.append("</span><ul>");
}
boolean hasChildren = false;
for (IRepositoryObject repoObj : repoObjs) {
hasChildren = hasChildren | generate(directory, repoObj, current);
}
if (hasChildren) {
m_nodeRepository.append("</ul></li>");
return true;
} else {
// revert all entries done so far
m_nodeRepository.setLength(currentLength);
return false;
}
} else {
// most likely a metanode), we just ignore them for now
return false;
}
}
Aggregations