Magnolia 5.4 reached end of life on November 15, 2018. This branch is no longer supported, see End-of-life policy.
Generally accessing a workspace with the JCR session 'javax.jcr.Session'
Session session = MgnlContext.getJCRSession( "workspaceName" ); Session session = someNode.getSession(); |
A specific Node or Property can be accessed by the JCR Session
Node foundNode = session.getNodeByIdentifier( "identifier" ); Node foundNode = session.getNode( "absolutePath" ); Property foundProperty = session.getProperty( "absolutePath" ); Node foundNode = NodeUtil.getNodeByIdentifier( "workspaceName" , "identifier" ); |
Get a node's name
String name = someNode.getName(); String name = NodeUtil.getName(someNode); |
Get all child nodes as a collection
NodeIterator childrenIterator = someNode.getNodes(); Iterable<Node> childrenIterable = NodeUtil.asIterable(childrenIterator); List<Node> childrenList = NodeUtil.asList(childrenIterable); Iterable<Node> childrenIterable = NodeUtil.collectAllChildren(someNode); List<Node> childrenList = NodeUtil.asList(childrenIterable); |
Get a specific child node by name
Node childNode = someNode.getNode( "relativePath" ); |
Get a node property by name
Property nodeProperty = someNode.getProperty( "relativePath" ); Property foundProperty = PropertyUtil.getProperty(someNode, "relativePath" ); |
Get a node's path
String pathToNode = someNode.getPath(); String pathToNode = NodeUtil.getNodePathIfPossible(someNode); |
Create and set a Property value to a specific node property
someNode.setProperty( "propertyName" , "propertyValue" ); PropertyUtil.setProperty(someNode, "propertyName" , "propertyValue" ); |
Create a sub node
someNode.addNode( "relativePath" , primaryNodeTypeName); NodeUtil.createPath(parent, "relativePath" , primaryNodeTypeName) |
Save the node with its changes
//Get Session form Node and save. someNode.getSession().save(); //I have the session session.save() |
Some examples on content node MetaData with NodeTypes
NodeTypes.Activatable.getActivationStatus(node); NodeTypes.Activatable.update(node, "username" , isActivated); NodeTypes.Renderable.getTemplate(node); NodeTypes.Renderable.set(node, "template id" ); NodeTypes.LastModified.getLastModified(node); NodeTypes.LastModified.update(node); NodeTypes.LastModified.update(node, "username" , date); |
Get a property's name
String name = nodeProperty.getName(); |
Get a property's path
String pathToProperty = nodeProperty.getPath(); |
Get the property's parent node
Node parentNode = nodeProperty.getParent(); |
Get value from the property
String stringValue = nodeProperty.getString() Calendar dateValue = nodeProperty.getDate(); Double doubleValue = nodeProperty.getDouble(); Long longValue = nodeProperty.getLong(); Binary forBinaryNodeData = nodeProperty.getBinary(); PropertyUtil.getString(someNode, propertyName); PropertyUtil.getDate(someNode, propertyName); PropertyUtil.getBoolean(someNode, propertyName, defaultValue) |
Set the value of the property
nodeProperty.setValue(booleanValue); nodeProperty.setValue(calendarObject); nodeProperty.setValue(longValue); nodeProperty.setValue(doubleValue); nodeProperty.setValue(intValueWillBeStoredAsLong); nodeProperty.setValue(booleanValue); nodeProperty.setValue(inputStreamForBinary); |
@nodeType
ContentMap nodeAsContentMap = new ContentMap(someNode); Node backToNode = nodeAsContentMap.getJCRNode(); |
${cmsfn.asJCRNode(aContentMap)} ${cmsfn.asContentMap(aJCRNode)} |
See cmsfn for more templating functions operating on the JCR API.