jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Florent Guillaume ...@nuxeo.com>
Subject Re: How to get children (direct descendants of the given node)
Date Sat, 17 Mar 2007 02:10:42 GMT
Node.getNodes() does what you want.

Florent

Lubos and Alena Pochman wrote:
> It is Friday, and I probably have brain lock (bigger than usual 8-).
> But I cannot find easy way to get children (direct descendants of the given
> node).
> The best thing I came up with is (for nt:folder traversal):
> 
>            ArrayList<String> subFolderNames = new ArrayList<String>();
>            Workspace workspace = this.session.getWorkspace();
>            QueryManager queryMan = workspace.getQueryManager();
>            String qstr = "/jcr:root" + path + "//element(*, nt:folder)";
>            Query q = queryMan.createQuery(qstr, Query.XPATH);
>            QueryResult results = q.execute();
>            NodeIterator it = results.getNodes();
>            while (it.hasNext()) {
>                Node n = it.nextNode();
>                if (parentFolder.getDepth() + 1 == n.getDepth())
>                    subFolderNames.add(n.getName());
>            }
> 
> There must be a better way (I just do not see it 8-).
> 
> Lubos
> 


Mime
View raw message