use of de.philippkatz.knime.jsondocgen.docs.NodeDoc.NodeDocBuilder in project knime-json-node-doc-generator by NodePit.
the class JsonNodeDocuGenerator 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
* @param parentCategory
* The parent category where to insert the JSON entry.
* @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, CategoryDocBuilder parentCategory) throws TransformerException, Exception {
if (current instanceof NodeTemplate) {
// skip node if not part of the specified plugin
if (!m_pluginIds.isEmpty() && !m_pluginIds.contains(current.getContributingPlugin())) {
return false;
}
// as argument
if (m_catPath.length() > 0) {
String catIdentifier = getCategoryIdentifier(parent);
if (!catIdentifier.startsWith(m_catPath)) {
return false;
}
}
NodeTemplate nodeTemplate = (NodeTemplate) current;
NodeFactory<? extends NodeModel> factory = nodeTemplate.createFactoryInstance();
NodeDocBuilder builder = new NodeDocBuilder();
builder.setId(current.getID());
builder.setName(current.getName());
// get additional information from the node XML description
Element xmlDescription = factory.getXMLDescription();
if (xmlDescription != null) {
NodeDocJsonParser.parse(xmlDescription, builder);
}
builder.setContributingPlugin(current.getContributingPlugin());
if (nodeTemplate.getIcon() != null) {
builder.setIconBase64(Utils.getImageBase64(nodeTemplate.getIcon()));
}
builder.setAfterId(Utils.stringOrNull(nodeTemplate.getAfterID()));
boolean deprecated = RepositoryManager.INSTANCE.isDeprecated(current.getID());
boolean hidden = RepositoryManager.INSTANCE.isHidden(current.getID());
builder.setHidden(hidden);
try {
NodeModel nodeModel = createNodeModel(factory);
PortType[] outPorts = getPorts(factory, PortDirection.Out);
builder.setOutPorts(mergePortInfo(builder.build().outPorts, outPorts, current.getID()));
PortType[] inPorts = getPorts(factory, PortDirection.In);
builder.setInPorts(mergePortInfo(builder.build().inPorts, inPorts, current.getID()));
builder.setStreamable(isStreamable(nodeModel));
// merge this “dynamic port” shit here
List<DynamicPortGroup> dynamicInPorts = getDynamicPorts(factory, PortDirection.In);
List<DynamicPortGroup> dynamicOutPorts = getDynamicPorts(factory, PortDirection.Out);
builder.setDynamicInPorts(mergeDynamicPortInfo(builder.build().dynamicInPorts, dynamicInPorts, current.getID()));
builder.setDynamicOutPorts(mergeDynamicPortInfo(builder.build().dynamicOutPorts, dynamicOutPorts, current.getID()));
} catch (Throwable t) {
LOGGER.warn(String.format("Could not create NodeModel for %s", factory.getClass().getName()), t);
}
if (deprecated) {
// there are two locations, where nodes can be set to deprecated:
// so, do not overwrite with false, if already set to true
builder.setDeprecated(true);
}
if ((!deprecated || m_includeDeprecated) && (!hidden || m_includeHidden)) {
parentCategory.addNode(builder.build());
}
return true;
} else if (current instanceof Category || current instanceof Root) {
LOGGER.info("Processing category " + getPath(current));
IRepositoryObject[] repoObjs = ((IContainerObject) current).getChildren();
CategoryDocBuilder newCategory = parentCategory;
if (current instanceof Category) {
Category category = (Category) current;
CategoryDocBuilder builder = new CategoryDocBuilder();
builder.setId(category.getID());
builder.setName(category.getName());
builder.setDescription(category.getDescription());
builder.setContributingPlugin(category.getContributingPlugin());
if (category.getIcon() != null) {
builder.setIconBase64(Utils.getImageBase64(category.getIcon()));
}
builder.setAfterId(Utils.stringOrNull(category.getAfterID()));
newCategory = builder;
}
boolean hasChildren = false;
for (IRepositoryObject repoObj : repoObjs) {
hasChildren = hasChildren | generate(directory, repoObj, current, newCategory);
}
if (hasChildren && current instanceof Category) {
parentCategory.addChild(newCategory.build());
}
return hasChildren;
} else {
// a metanode), we just ignore them for now
return false;
}
}
use of de.philippkatz.knime.jsondocgen.docs.NodeDoc.NodeDocBuilder in project knime-json-node-doc-generator by NodePit.
the class NodeDocJsonParser method parse.
/* package */
static NodeDoc parse(Node domNode) {
Objects.requireNonNull(domNode, "document must not be null");
NodeDocBuilder builder = new NodeDocBuilder();
parse(domNode, builder);
return builder.build();
}
Aggregations