diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 8843f03acf..ac7216114f 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -715,6 +715,28 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol return getChildAssocs(); } + /** + * Return an Array of the associations from this Node that match a specific object type. + * node.getChildAssocsByType("cm:folder")[0] + * + * @return Array of child associations from this Node that match a specific object type. + */ + @SuppressWarnings("unchecked") + public Scriptable getChildAssocsByType(String type) + { + // get the list of child assoc nodes for each association type + Set types = new HashSet(1, 1.0f); + types.add(createQName(type)); + List refs = this.nodeService.getChildAssocs(this.nodeRef, types); + Object[] nodes = new Object[refs.size()]; + for (int i=0; i getChildAssocsByType(String type) + { + Set types = new HashSet(1, 1.0f); + types.add(createQName(type)); + List refs = this.services.getNodeService().getChildAssocs(this.nodeRef, types); + List nodes = new ArrayList(refs.size()); + for (ChildAssociationRef ref : refs) + { + String qname = ref.getTypeQName().toString(); + nodes.add( new TemplateNode(ref.getChildRef(), this.services, this.imageResolver) ); + } + return nodes; + } + /** * @return true if the node is currently locked */ @@ -520,6 +539,27 @@ public class TemplateNode extends BasePermissionsNode implements NamespacePrefix return this.imageResolver; } + /** + * Helper to create a QName from either a fully qualified or short-name QName string + * + * @param s Fully qualified or short-name QName string + * + * @return QName + */ + private QName createQName(String s) + { + QName qname; + if (s.indexOf(NAMESPACE_BEGIN) != -1) + { + qname = QName.createQName(s); + } + else + { + qname = QName.createQName(s, this.services.getNamespaceService()); + } + return qname; + } + // ------------------------------------------------------------------------------ // Inner classes