ALF-1589 : ScriptNode API method "childByNamePath(string path)" is no longer implemented for for AVM nodes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20639 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2010-06-14 17:00:00 +00:00
parent dd29c80375
commit 7aeff72605
2 changed files with 57 additions and 6 deletions

View File

@@ -76,7 +76,7 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class AVMNodeService extends AbstractNodeServiceImpl implements NodeService 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. * Flag for whether policy callbacks are made.
@@ -1299,7 +1299,7 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
} }
else else
{ {
fgLogger.error("Invalid Built In Property: " + qName); logger.error("Invalid Built In Property: " + qName);
return null; return null;
} }
} }
@@ -1710,12 +1710,52 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
} }
return result; return result;
} }
/**
* getChildrenByName
*/
public List<ChildAssociationRef> getChildrenByName(NodeRef nodeRef, QName assocTypeQName, Collection<String> childNames) public List<ChildAssociationRef> getChildrenByName(NodeRef nodeRef, QName assocTypeQName, Collection<String> childNames)
{ {
throw new UnsupportedOperationException(); final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(100);
if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
{
throw new UnsupportedOperationException("AVM getChildrenByName only supports ASSOCS_CONTAINS.");
}
Pair<Integer, String> 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. * Get a child NodeRef by name.
* @param nodeRef The parent node. * @param nodeRef The parent node.

View File

@@ -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: * So a valid call might be:
* <code>mynode.childByNamePath("/QA/Testing/Docs");</code> * <code>mynode.childByNamePath("/QA/Testing/Docs");</code>
*
* 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) 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)) 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; NodeRef result = null;
StringTokenizer t = new StringTokenizer(path, "/"); StringTokenizer t = new StringTokenizer(path, "/");
if (t.hasMoreTokens()) if (t.hasMoreTokens())
@@ -420,6 +428,9 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
} }
else else
{ {
/**
* The current node is not a folder. Perhaps it is Company Home ?
*/
// convert the name based path to a valid XPath query // convert the name based path to a valid XPath query
StringBuilder xpath = new StringBuilder(path.length() << 1); StringBuilder xpath = new StringBuilder(path.length() << 1);
StringTokenizer t = new StringTokenizer(path, "/"); StringTokenizer t = new StringTokenizer(path, "/");