|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object info.magnolia.cms.core.ContentHandler info.magnolia.cms.core.AbstractContent info.magnolia.cms.util.ContentWrapper info.magnolia.module.groovy.support.nodes.MgnlGroovyNode
public class MgnlGroovyNode
A special groovish implementation of Magnolia's ContentWrapper
.
This makes it possible, for example, navigating the nodes in a Magnolia repository
with a . (dot)
notation and access their properties with .
or .@
notation much like it happens when using the result of parsing an xml with groovy's groovy.util.XmlSlurper.XmlSlurper
. For example, here is how, in a groovy
script, one could navigate to and print the node data named abstract:
hm = ctx.getHierarchyManager('website') node = hm.getContent(hm, '/demo-project') println node.about.history.abstractThe above example can also be made more groovy-like by using the
@
notation to access the attribute
node.about.history.@abstractAs
node
is also a Content
, you can call any of its
methods. E.g.
println node.metaData.template println node.about.children.title println node.about.parent (this can return null)IMPORTANT: The
.children
shortcut, unlikely Content.getChildren()
, always returns ItemType.CONTENT
s AND ItemType.CONTENTNODE
s .
If you only need either type, then call directly one of the Content.getChildren()
methods on the parent node. println node.about.nodeDataIt is also possible to assign values to node data or create new ones. E.g.
node.boo = 3.14d node.coo = true node.foo = 'some text' node.doo = 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, Long or Double).
save()
on a parent node.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface info.magnolia.cms.core.Content |
---|
info.magnolia.cms.core.Content.ContentFilter |
Field Summary | |
---|---|
protected static org.slf4j.Logger |
log
|
Constructor Summary | |
---|---|
MgnlGroovyNode(info.magnolia.cms.core.Content content)
|
Method Summary | |
---|---|
boolean |
equals(Object obj)
|
Object |
get(String key)
Provides lookup of elements by non-namespaced name. |
List<info.magnolia.cms.core.Content> |
getAt(groovy.xml.QName name)
Deprecated. This method is wrong and luckily unused by this module. Use getByName(String) instead. |
protected info.magnolia.cms.core.Content |
getByName(String name)
Provides lookup of elements by name. |
protected Object |
getNodeDataValue(String attributeName)
Returns the value for the given attribute (nodeData). |
int |
hashCode()
|
Iterator<info.magnolia.cms.core.Content> |
iterator()
|
String |
name()
|
protected static void |
setMetaClass(groovy.lang.MetaClass metaClass,
Class nodeClass)
|
String |
toString()
|
protected info.magnolia.cms.core.Content |
wrap(info.magnolia.cms.core.Content node)
|
Methods inherited from class info.magnolia.cms.util.ContentWrapper |
---|
addMixin, addVersion, addVersion, createContent, delete, deleteNodeData, getAllVersions, getAncestor, getAncestors, getBaseVersion, getChildByName, getChildren, getContent, getHandle, getHierarchyManager, getIndex, getItemType, getJCRNode, getLevel, getLock, getMetaData, getMixinNodeTypes, getName, getNodeDataCollection, getNodeType, getNodeTypeName, getParent, getTemplate, getTitle, getUUID, getVersionedContent, getVersionedContent, getVersionHistory, getWorkspace, getWrappedContent, hasContent, hasMetaData, hasMixin, holdsLock, isGranted, isLocked, isModified, isNodeData, isNodeType, lock, lock, newNodeDataInstance, orderBefore, refresh, removeMixin, removeVersionHistory, restore, restore, restore, restoreByLabel, save, setWrappedContent, unlock, updateMetaData, wrap, wrapContentNodes, wrapNodeDatas |
Methods inherited from class info.magnolia.cms.core.AbstractContent |
---|
createContent, createContent, createNodeData, createNodeData, createNodeData, createNodeData, createNodeData, delete, getBinaryNodeDatas, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getNodeData, getNodeDataCollection, hasChildren, hasChildren, hasNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData, setNodeData |
Methods inherited from class info.magnolia.cms.core.ContentHandler |
---|
clone, getAccessManager, setAccessManager |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface info.magnolia.cms.core.Content |
---|
getAccessManager |
Field Detail |
---|
protected static final org.slf4j.Logger log
Constructor Detail |
---|
public MgnlGroovyNode(info.magnolia.cms.core.Content content)
Method Detail |
---|
protected static void setMetaClass(groovy.lang.MetaClass metaClass, Class nodeClass)
public Iterator<info.magnolia.cms.core.Content> iterator()
public String name()
public Object get(String key)
key
- the name (or shortcut key) of the node(s) of interest
protected info.magnolia.cms.core.Content wrap(info.magnolia.cms.core.Content node)
wrap
in class info.magnolia.cms.util.ContentWrapper
protected Object getNodeDataValue(String attributeName)
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 BinaryNodeData
value.
String
(s)
@Deprecated public List<info.magnolia.cms.core.Content> getAt(groovy.xml.QName name)
getByName(String)
instead.
name
- the QName of interest
protected info.magnolia.cms.core.Content getByName(String name)
name
- the name of interest
public String toString()
toString
in class info.magnolia.cms.util.ContentWrapper
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |