NodeRef cookbook
From AlfrescoWiki
The NodeRef object is a reference to the base object that represents locations and resources within an Alfresco repository. Custom Actions will provide you with a NodeRef of the resource or space that the action is acting on. Once you have it, though, what do you do with it?
This page is the opening index for a list of things that you can do with a NodeRef. If a question looks like "How do I use a NodeRef to..." then it probably belongs here. Hopefully some kindly developers will stop by and fill in some answers.
[edit] Stepping through child NodeRefs
List<ChildAssociationRef> children = nodeService.getChildAssocs(companyHome);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
System.out.println("Child NodeRef " + childNodeRef.getId());
Serializable nodeName = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
System.out.println("\tChild Name " + nodeName.toString());
// Get the content writer
ContentReader reader = contentService.getReader(childNodeRef, ContentModel.PROP_CONTENT);
// The reader may be null, e.g. for folders and the like
if (reader == null )
{
continue;
}
System.out.println("\tChild Content " + reader.getContentString());
}
[edit] Getting a file name from a NodeRef
Just get the property from NodeRef.
Serializable nodeFileName = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);

