Hi,

Amit Snyderman schrieb:
> On Sep 29, 2009, at 6:41 AM, Felix Meschberger wrote:
> 
>>> Any way to add properties to the `SyntheticResource`?
>>
>> What do you mean by "add properties" ?
>>
>> If you are thinking about supporting the adaptTo method, you might
>> create your own extension of the SyntheticResource:
>>
>>   Resource r = new SyntheticResource(...) {
>>      public <T> T adapTo(Class<T> type) {
>>          if (type == Map.class) {
>>             return ...someMap...
>>          }
>>          return super.adaptTo(type);
>>      }
>>   }
> 
> Interesting. This gets at what I had in mind:
> 
> Resource r = new SyntheticResource(...) {
>     public <T> T adaptTo(Class<T> type) {
>         if (type == ValueMap.class) {
>             ValueMap m = new ValueMapDecorator(new HashMap());
>             m.put("text", "This is <b>the</b> body.");
>             m.put("textIsRich", "true");
>             return (T) m;
>         }
>         return super.adaptTo(type);
>     }
> }

Sounds reasonable. If you intend the textIsRich property to be boolean,
you might even do:

    m.put("textIsRich", true);

> 
> Specifically I'm working with Day's CQ 5. We've got instances where we
> want to reuse a component to render content for a resource that doesn't
> exist in the JCR. There are probably better ways to design the
> circumstances for which we'll be using this but it seems like a handy
> trick for the moment.

AFAICT this is how it is intended to be used. There may be other
solutions (there is more than one solution most of the times ;-) ), but
I think this one is probably as fine as any other.

Regards
Felix

Reply via email to