info.magnolia.module.groovy.support.nodes
Class MgnlGroovyJCRNode

java.lang.Object
  extended by info.magnolia.jcr.wrapper.DelegateNodeWrapper
      extended by info.magnolia.module.groovy.support.nodes.MgnlGroovyJCRNode
All Implemented Interfaces:
Cloneable, javax.jcr.Item, javax.jcr.Node

public class MgnlGroovyJCRNode
extends info.magnolia.jcr.wrapper.DelegateNodeWrapper

Implementation of wrapped Node object used in Groovy console context. 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:

 session = ctx.getJCRSession('website')
 node = session.getNode('/demo-project')
 println node.about.history.abstract
 
The above example can also be made more groovy-like by using the @ notation to access the property
 node.about.history.@abstract
 
As 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)
 

If you want to iterate over properties for a certain node you can do for instance
 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 = 100
 
will 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).

IMPORTANT: All the above assignments will be in-memory only unless explicitly persisted via a call to save() on a parent node.


Nested Class Summary
protected  class MgnlGroovyJCRNode.MgnlGroovyWrappingNodeIterator
          MgnlGroovyWrappingNodeIterator.
 
Field Summary
protected static org.slf4j.Logger log
           
 
Fields inherited from class info.magnolia.jcr.wrapper.DelegateNodeWrapper
wrapped
 
Fields inherited from interface javax.jcr.Node
JCR_CHILD_NODE_DEFINITION, JCR_CONTENT, JCR_FROZEN_NODE, JCR_PROPERTY_DEFINITION, JCR_ROOT_VERSION, JCR_VERSION_LABELS
 
Constructor Summary
MgnlGroovyJCRNode(javax.jcr.Node node)
           
 
Method Summary
 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)
           
 
Methods inherited from class info.magnolia.jcr.wrapper.DelegateNodeWrapper
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, 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
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log
Constructor Detail

MgnlGroovyJCRNode

public MgnlGroovyJCRNode(javax.jcr.Node node)
Method Detail

setMetaClass

protected static void setMetaClass(groovy.lang.MetaClass metaClass,
                                   Class nodeClass)

name

public String name()

get

public Object get(String key)
           throws javax.jcr.ValueFormatException,
                  javax.jcr.RepositoryException
Provides lookup of elements by non-namespaced name.

Parameters:
key - the name (or shortcut key) of the node(s) of interest
Returns:
the nodes which match key
Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

getPropertyValue

protected Object getPropertyValue(javax.jcr.Property property)
                           throws javax.jcr.RepositoryException,
                                  javax.jcr.ValueFormatException
Returns the value for the given property. The Java types returned vary according to the underlying PropertyType.

Throws:
javax.jcr.RepositoryException
javax.jcr.ValueFormatException

print

public String print()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

showNode

protected boolean showNode(javax.jcr.Node node)

showProperty

protected boolean showProperty(javax.jcr.Property property)


Copyright © 2013 Magnolia International Ltd.. All Rights Reserved.