NodeIterator does not return all items

Hi,

I want to iterate over all child nodes of root node. For this i have done below:

Node rNode=requestContent.getSession().getRootNode();
NodeIterator nodeItr= rNode.getNodes();
while(nodeItr.hasNext()) {
Node cNode=nodeItr.nextNode();
}

It only gives me 7 items however the total size is 13.

Can i get some help here?

Hi,
it’s not clear to me what you exactly mean (please be more detailed in your description in the future).

This is just a guess, from my understanding what you are trying to do is to iterate the hst:root node within your (HST?) application. Then you are trying to compare this result (more specifically the number of children of the root node) with the tree you see from the console application [1] : in this case the root node displays more children compared to first result.

If my assumptions are correct, then you are using two different users while performing those two operations. The 1st user - that you are using in your specific application - has less privileges than the 2nd one (that most likely is an admin user). Please have a look at [2] in order to understand how Authorization works in general in the CMS.

HTH,
Giacomo

[1] http://localhost:8080/cms/console/
[2] https://documentation.bloomreach.com/library/concepts/security/repository-authorization-and-permissions.html

Hi Giacomo,

Actually i am trying to get access “hst:hst/hst:sites” node in my rest resource. When i tried to get this node through:

path=“hst:hst/hst:sites”;
requestContent.getSession().getRootNode().getNode(PathUtils.normalizePath(path));

It gave me PathNotFoundException exception.

Then, I tried to iterate the same through the root node(/). and for that i used below:

Node rNode=requestContent.getSession().getRootNode();
NodeIterator nodeItr= rNode.getNodes();
while(nodeItr.hasNext()) {
Node cNode=nodeItr.nextNode();
}

here before iterating through all the child nodes of root node when i check the size through

nodeItr.getSize(), I get size as 13. which are same as when we login to cms/console and check, which are( [collections],[content],[formdata],[hcm:hcm],[hippo:configuration],
[hippo:log],[hippo:namespaces],[hippo:reports],[hippowpm:hippowpm],[hst:hst],[jcr:system],[targeting:targeting], [webfiles]

However when I iterate though it, I only get [content],[hippo:configuration],
[hippo:log],[hippo:namespaces],[hippo:reports],[jcr:system], [webfiles]

Other nodes are missing. while loop runs just 7 times and then it breaks out.why is it happening so?

Please let me know how can i access all sites listed under “hst:hst/hst:sites” and their properties?

Thanks
Rahul

Your session has not enough rights to access those nodes.
see:

Thanks Machak.

Able to access it now.