I am wondering if there is anything in the CQ API that will allow me to create a node based on cq:component, like what will happen when the author adds the component to parsys.
Since I needed to make a piece, I went ahead and did it manually. I included this solution to find out if anyone can go "about the person there. * A method that you can use to do just that."
This is what I do:
public static Node createFromComponent(Node dstParent, Node srcComponent, String targetName) {
Node newNode = null;
try {
if (srcComponent.hasNode("cq:template")) {
newNode = JcrUtil.copy(srcComponent.getNode("cq:template"), dstParent, targetName);
}
else {
newNode = dstParent.addNode(targetName);
}
newNode.setProperty("sling:resourceType", srcComponent.getPath());
newNode.getSession().save();
}
catch(Exception e) {
LOGGER.error("Error creating node from component: ", e);
}
return newNode;
}
This is pretty straight forward. I watched the JcrUtilclass , but I do not think that he has what I am looking for.
source
share