CRUD operations for Nodes.
I need to create, update, delete nodes programmatically by adapting resource to a node. If anyone can provide any code samples for the same.
I need to create, update, delete nodes programmatically by adapting resource to a node. If anyone can provide any code samples for the same.
You need to adapt the resource to a Node.class
Node node = resource.adaptTo(Node.class);
to create a child node you can use the "addNode" methods which returns the new created node
Node childNode = node.addNode("newNode");
to read it from its parent you can do the following
Node childNode = node.getNode("newNode");
to update its properties you can use the methods "setProperty", but you can add or remove mixin types and more with other methods if I remember properly
Property property = childNode.setProperty("propertyName", "itsValue")
to remove a node (or a property) you can use the remove method of the superclass Item
childNode.getProperty("propertyName").remove();
childNode.remove();
The same operations, with the absolute paths can be done with the java.jcr.Session instance, which in any case it's necessary to commit or discard the changes. With the JCR API you have to use the save() and the refresh(boolean keepChanges) methods.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.