. Create node from source (i.e. a templated document) WebScripts to support ALF-9710

. Added selectNodes(xpath) to JavaScript Search API (not sure why I never added it before...!)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29789 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2011-08-16 11:05:57 +00:00
parent d0585ff542
commit 43e11b8817

View File

@@ -214,6 +214,63 @@ public class Search extends BaseScopableProcessorExtension
return Context.getCurrentContext().newArray(getScope(), 0); return Context.getCurrentContext().newArray(getScope(), 0);
} }
} }
/**
* Execute a SelectNodes XPath search
*
* @param search SelectNodes XPath search string to execute
*
* @return JavaScript array of Node results from the search - can be empty but not null
*/
public Scriptable selectNodes(String search)
{
return selectNodes(null, search);
}
/**
* Execute a SelectNodes XPath search
*
* @param store Store reference to search against i.e. workspace://SpacesStore
* @param search SelectNodes XPath search string to execute
*
* @return JavaScript array of Node results from the search - can be empty but not null
*/
public Scriptable selectNodes(String store, String search)
{
if (search != null && search.length() != 0)
{
Object[] nodeArray = new Object[0];
if (store == null)
{
store = "workspace://SpacesStore";
}
try
{
NodeService nodeService = this.services.getNodeService();
List<NodeRef> nodes = this.services.getSearchService().selectNodes(
nodeService.getRootNode(new StoreRef(store)), search, null, this.services.getNamespaceService(), false);
if (nodes.size() != 0)
{
int index = 0;
nodeArray = new Object[nodes.size()];
for (NodeRef node: nodes)
{
nodeArray[index++] = new ScriptNode(node, this.services, getScope());
}
}
}
catch (Throwable err)
{
throw new AlfrescoRuntimeException("Failed to execute search: " + search, err);
}
return Context.getCurrentContext().newArray(getScope(), nodeArray);
}
else
{
return Context.getCurrentContext().newArray(getScope(), 0);
}
}
/** /**
* Validation Xpath query * Validation Xpath query