public class MgnlGroovyJCRNode
extends info.magnolia.jcr.wrapper.DelegateNodeWrapper
. (dot)
notation and access their properties with .
or .@
notation
much like it happens when using the result of parsing an xml with groovy's XmlSlurper.XmlSlurper(javax.xml.parsers.SAXParser)
.
For example, here is how, in a groovy script, one could navigate to and print the node data named abstract:
session = ctx.getJCRSession('website') node = session.getNode('/demo-project') println node.about.history.abstractThe above example can also be made more groovy-like by using the
@
notation to access the property
node.about.history.@abstractAs
node
is also a Node
, you can call any of its
methods. E.g.
println node.metaData.template println node.about.title println node.about.parent (this can return null)
node.about.properties.each {println it.name}It is also possible to assign values to properties or create new ones. E.g.
node.foo = 3.14d node.bar = true node.baz = 'some text' node.qux = 100will assign the values on the right hand side to the node data on left hand side. Should those not exist, they will be automatically created. Furthermore, the correct type will be detected based on the value assigned (i.e. Boolean, String, Calendar, Long or Double).
save()
on a parent node.Modifier and Type | Class and Description |
---|---|
protected class |
MgnlGroovyJCRNode.MgnlGroovyWrappingNodeIterator
MgnlGroovyWrappingNodeIterator.
|
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
log |
Constructor and Description |
---|
MgnlGroovyJCRNode(javax.jcr.Node node) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Object |
get(String key)
Provides lookup of elements by non-namespaced name.
|
protected Object |
getPropertyValue(javax.jcr.Property property)
Returns the value for the given property.
|
int |
hashCode() |
String |
name() |
String |
print() |
protected static void |
setMetaClass(groovy.lang.MetaClass metaClass,
Class nodeClass) |
protected boolean |
showNode(javax.jcr.Node node) |
protected boolean |
showProperty(javax.jcr.Property property) |
accept, addMixin, addNode, addNode, canAddMixin, cancelMerge, checkin, checkout, clone, deepUnwrap, doneMerge, followLifecycleTransition, getAllowedLifecycleTransistions, getAncestor, getBaseVersion, getCorrespondingNodePath, getDefinition, getDepth, getIdentifier, getIndex, getLock, getMixinNodeTypes, getName, getNode, getNodes, getNodes, getNodes, getParent, getPath, getPrimaryItem, getPrimaryNodeType, getProperties, getProperties, getProperties, getProperty, getReferences, getReferences, getSession, getSharedSet, getUUID, getVersionHistory, getWeakReferences, getWeakReferences, getWrappedNode, hasNode, hasNodes, hasProperties, hasProperty, holdsLock, initClone, isCheckedOut, isLocked, isModified, isNew, isNode, isNodeType, isSame, isWrapping, lock, merge, orderBefore, refresh, remove, removeMixin, removeShare, removeSharedSet, restore, restore, restore, restoreByLabel, save, setPrimaryType, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setWrappedNode, toString, unlock, update
protected static void setMetaClass(groovy.lang.MetaClass metaClass, Class nodeClass)
public String name()
public Object get(String key) throws javax.jcr.ValueFormatException, javax.jcr.RepositoryException
key
- the name (or shortcut key) of the node(s) of interestjavax.jcr.RepositoryException
javax.jcr.ValueFormatException
protected Object getPropertyValue(javax.jcr.Property property) throws javax.jcr.RepositoryException, javax.jcr.ValueFormatException
PropertyType
.
PropertyType.STRING
returns a String
PropertyType.DATE
returns a Calendar
PropertyType.DOUBLE
returns a BigDecimal
PropertyType.LONG
returns a BigDecimal
PropertyType.BINARY
returns the InputStream
value.
String
(s)
javax.jcr.RepositoryException
javax.jcr.ValueFormatException
public String print()
protected boolean showNode(javax.jcr.Node node)
protected boolean showProperty(javax.jcr.Property property)
Copyright © 2017 Magnolia International Ltd.. All rights reserved.