how to iterate on sling folders? | Community
Skip to main content
New Participant
May 17, 2018 8:02 PM UTC
Solved

how to iterate on sling folders?

I want to iterate on the sling folder and get the information on it in java.

"SELECT * FROM [nt:base] AS s WHERE [jcr:primaryType]=\"sling:Folder\" AND ISDESCENDANTNODE([/etc/foldername]) and ...."

In java,

Iterator<Resource> queryResult = resolver.findResources("SELECT * FROM [nt:base] AS s WHERE [jcr:primaryType]=\"sling:Folder\" AND ISDESCENDANTNODE([/etc/foldername]) and ....", Query.JCR_SQL2);

while (queryResult.hasNext()) {

Resource res = queryResult.next();

//but here how to get the information stored on the sling folder

}

how to read the name and ID property values?

Please help me with this issue in accessing the ID and name stored in the sling folder.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
May 17, 2018 8:30 PM UTC

Do not use queries for that! Way too much overhead. Instead iterate directly the children list:

Resource folder = resourceResolver.getResource("/path/to/the/folder");

Iterator<Resource> children = folder.listChildren();

children.forEach (c ->

  ValueMap vm = c.adaptTo(ValueMap.class);

  String prop1 = vm.get("name", String.class);

  ...

);

2 replies

New Participant
May 17, 2018 8:51 PM UTC

Thank you, it works!

Translate
joerghoh
joerghohAccepted solution
Employee
May 17, 2018 8:30 PM UTC

Do not use queries for that! Way too much overhead. Instead iterate directly the children list:

Resource folder = resourceResolver.getResource("/path/to/the/folder");

Iterator<Resource> children = folder.listChildren();

children.forEach (c ->

  ValueMap vm = c.adaptTo(ValueMap.class);

  String prop1 = vm.get("name", String.class);

  ...

);

Translate