[ 
https://issues.apache.org/jira/browse/SLING-3451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13935011#comment-13935011
 ] 

Carsten Ziegeler commented on SLING-3451:
-----------------------------------------

As discussed in the mailing list, this is rather desired as it seems that 
people are using resource.adaptTo(ValueMap.class) and 
ResourceUtil.getValueMap() interchangeably:

The only other option I see is to make ValueMap a first class citizen and:
a) add a getValueMap() method to Resource - default implementation in 
AbstractResource does the same as ResourceUtil does today
b) clearly state that deep gets are allowed for reading from those maps
c) provide utility code in AbstractResource (or maybe somewhere else) so 
implementations do not need to copy the same code over and over again

This would mean:
a) current code does not need to change, regardless whether ResourceUtil or 
adaptTo is used
b) a value map is always provided
c) all value maps support deep reads
d) no code duplication necessary

> Support for deep reads from a value map
> ---------------------------------------
>
>                 Key: SLING-3451
>                 URL: https://issues.apache.org/jira/browse/SLING-3451
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Carsten Ziegeler
>             Fix For: API 2.6.2, Mongo Resource Provider 1.0.0, JMX Resource 
> Provider 1.0.2, Resource Merger 1.1.2
>
>
> When writing rendering code, a commonly used shortcut is to do deep reads to 
> get properties from a child resource, like:
> ValueMap vm = ResourceUtil.getValueMap(resource);
> vm.get("jcr:content/jcr:title", "No title found");
> While this works with jcr backed resources, this doesn't work in the general 
> case and a value map returned by a resource should not support this. In 
> addition, the implementation in the jcr resource bundle is wrong as it 
> bypasses all resource mechanisms, e.g. in the above case 
> resource.getChild("jcr:content") might return a resource from a different 
> resource provider etc.
> Adding the same code over and over again in each ValueMap implementation 
> doesn't look like a good solution either.
> The simplest solution would be to enhance ResourceUtil.getValueMap() to 
> return a wrapper of the value map which allows deep reads.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to