Pages

Tuesday, June 4, 2013

CQ5/AEM What possibilities exist with adaptTo?

The Problem

You want to find out what you can adapt a particular object to, using the adaptTo(Object.class) method.

The Solution

Go to http://localhost:4502/system/console/adapters and have a look for the class in the first column, Adaptable Class.

The next column provides all of the classes that you can adapt the originating class to, any conditions that may be imposed, and the bundle that provides the information.

So for example, if you look up org.apache.sling.api.resource.Resource you will see that one of the listed adaptable classes is com.day.cq.wcm.api.Page

Thus, if you start with a Resource resource, you can do:
Page page = resource.adaptTo(Page.class)

You could even create an adaption of your own. For example, if you have a Node object, you can create an AdaptTo mapping to map to MyCustomNode.

Further items of interest

How to create your own sling adapter.

1 comment:

  1. Casinos with Slot Machines: Play for Real Money - Dr.MD
    Casinos 강원도 출장안마 with Slot Machines: Play for 제주 출장샵 Real Money · Jackpot 전주 출장마사지 City Casino · Microgaming Casino · 888Casino.ag · Royal Ace 광주 출장안마 Casino 순천 출장안마 · Play'n GO

    ReplyDelete