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);
}
}
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.
thanks,
Amit