You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Lubos and Alena Pochman <po...@gmail.com> on 2007/03/16 21:02:16 UTC
How to get children (direct descendants of the given node)
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
Re: How to get children (direct descendants of the given node)
Posted by Lubos and Alena Pochman <po...@gmail.com>.
Cedric,
I know it is Friday, but I can't find getChildren() anywhere in the JSR-170
spec or in javadoc for Node or superclass Item.
Where do you see getChildren()?
On 3/16/07, Cédric Damioli <ce...@anyware-tech.com> wrote:
>
> Why parentFolder.getChildren() doesn't fit your needs ?
>
> Lubos and Alena Pochman a écrit :
> > 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
> >
>
> --
> Cédric Damioli
> Directeur de projets
> Solutions CMS
> ANYWARE TECHNOLOGIES
> Tel : +33 (0)5 61 00 73 47
> Fax : +33 (0)5 61 00 51 46
> http://www.anyware-tech.com
>
>
Re: How to get children (direct descendants of the given node)
Posted by Cédric Damioli <ce...@anyware-tech.com>.
Why parentFolder.getChildren() doesn't fit your needs ?
Lubos and Alena Pochman a écrit :
> 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
>
--
Cédric Damioli
Directeur de projets
Solutions CMS
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 73 47
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com
Re: How to get children (direct descendants of the given node)
Posted by Lubos and Alena Pochman <po...@gmail.com>.
Thanks Florent,
as I said, it was Friday. getNodes() does it, but you have to exclude
"jcr:..." nodes then invoking on the root node.
For some reason it add jcr:system and your top nodes when calling on root
node.
On 3/16/07, Florent Guillaume <fg...@nuxeo.com> wrote:
>
> 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
> >
>
>
Re: How to get children (direct descendants of the given node)
Posted by Florent Guillaume <fg...@nuxeo.com>.
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
>