diff --git a/source/java/org/alfresco/repo/avm/AVMNodeService.java b/source/java/org/alfresco/repo/avm/AVMNodeService.java index b4ef0d866c..bef59e088d 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeService.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeService.java @@ -76,7 +76,7 @@ import org.apache.commons.logging.LogFactory; */ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeService { - private static Log fgLogger = LogFactory.getLog(AVMNodeService.class); + private static Log logger = LogFactory.getLog(AVMNodeService.class); /** * Flag for whether policy callbacks are made. @@ -1299,7 +1299,7 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi } else { - fgLogger.error("Invalid Built In Property: " + qName); + logger.error("Invalid Built In Property: " + qName); return null; } } @@ -1710,12 +1710,52 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi } return result; } - + + /** + * getChildrenByName + */ public List getChildrenByName(NodeRef nodeRef, QName assocTypeQName, Collection childNames) { - throw new UnsupportedOperationException(); + final List results = new ArrayList(100); + + if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS)) + { + throw new UnsupportedOperationException("AVM getChildrenByName only supports ASSOCS_CONTAINS."); + } + + Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef); + try + { + for(String childName : childNames) + { + AVMNodeDescriptor child = fAVMService.lookup(avmVersionPath.getFirst(), + AVMUtil.extendAVMPath(avmVersionPath.getSecond(), childName)); + + if (child != null) + { + NodeRef childRef = AVMNodeConverter.ToNodeRef(avmVersionPath.getFirst(), + child.getPath()); + QName childQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, + childName); + ChildAssociationRef ref = new ChildAssociationRef(assocTypeQName, nodeRef, childQName, childRef); + + if(logger.isDebugEnabled()) + { + logger.debug("got a child node :" + ref); + } + results.add(ref); + } + } + return results; + } + catch (AVMException e) + { + logger.debug("exception in getChildrenByName ", e); + return results; + } } + /** * Get a child NodeRef by name. * @param nodeRef The parent node. diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index fdf9d56772..d82dbb3d80 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -391,9 +391,14 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol } /** - * @return Returns the Node at the specified 'cm:name' based Path walking the children of this Node. + * childByNamePath returns the Node at the specified 'cm:name' based Path walking the children of this Node. * So a valid call might be: * mynode.childByNamePath("/QA/Testing/Docs"); + * + * is a leading / required? No, but it can be specified. + * are wild-cards supported? Does not seem to be used anywhere + * + * @return The ScriptNode or null if the node is not found. */ public ScriptNode childByNamePath(String path) { @@ -401,7 +406,10 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol if (this.services.getDictionaryService().isSubClass(getQNameType(), ContentModel.TYPE_FOLDER)) { - // optimized code path for cm:folder and sub-types supporting getChildrenByName() method + /** + * The current node is a folder. + * optimized code path for cm:folder and sub-types supporting getChildrenByName() method + */ NodeRef result = null; StringTokenizer t = new StringTokenizer(path, "/"); if (t.hasMoreTokens()) @@ -420,6 +428,9 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol } else { + /** + * The current node is not a folder. Perhaps it is Company Home ? + */ // convert the name based path to a valid XPath query StringBuilder xpath = new StringBuilder(path.length() << 1); StringTokenizer t = new StringTokenizer(path, "/");