0

I'm used to using nodes in sling and accustomed to looping through nodes with something like:

NodeIterator headerNode = currentNode.getNodes();
//loop through and do something

But how would I do this if I'm trying to loop through all the properties of a resource. I'm really lost here. So currently I'm simply grabbing a single property of a resource. But what if I want to grab all the properties of said resource how would I do that?

Resource getResource = resourceResolver.getResource("/content/AboutPage/jcr:content/list");
ValueMap property = getResource.adaptTo(ValueMap.class);
String title = property.get("jcr:lastEdited", String.class);

Any help is greatly appreciated!

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
Delmon Young
  • 2,013
  • 5
  • 39
  • 51

1 Answers1

2

As ValueMap extends java.util.Map you can use the entrySet() method:

Resource getResource = resourceResolver.getResource("/content/AboutPage/jcr:content/list");
ValueMap property = getResource.adaptTo(ValueMap.class);
for(Entry<String, Object> e : property.entrySet()) {
    String key = e.getKey();
    Object value = e.getValue();
    //use the key and value here
}
Aleksander Blomskøld
  • 18,374
  • 9
  • 76
  • 82
  • Thanks for replying @Aleksander I'm kind of confused though I haven't used key value pairs in java much. If I'm just looping through properties would I need to use a key value pair. If so what is suppose to be the key? Thanks for the help. – Delmon Young May 20 '13 at 18:49