简体   繁体   中英

Finding resourceDesign and resourcePage in Java for Adobe CQ

I am working on a task that involves creating a servlet to take html requests in Adobe CQ 5.5 . It requires pulling some objects defined by the cq:defineObjects tag. Two of these objects are resourceDesign and resourcePage .

I believe that I may possibly be able to retrieve resourceDesign from resourcePage with the following code:

import org.apache.sling.api.servlets.SlingAllMethodsServlet;
...
@Override
protected void doGet(SlingHttpServletRequest slingRequest, SlingHttpServletResponse      slingResponse) throws ServletException, IOException {
  ResourceResolver resourceResolver = slingRequest.getResourceResolver();
  ...
  Designer designer = resourceResolver.adaptTo(Designer.class);
  Page resourcePage = ...
  Design resourceDesign = designer.getDesign(resourcePage);
}

However I don't quite understand how to retreive the resourcePage and the documentation doesn't give a very clear idea of what it is or how to get its value.

Any insights would be greatly appreciated.

Thanks, Thomas

resourcePage refers to the page containing your resource and is an instance of com.day.cq.wcm.api.Page , and resourceDesign is the design object for the resource page.

The resourcePage can be obtained using PageManager's #getContainingPage() as shown here.

import org.apache.sling.api.servlets.SlingAllMethodsServlet;
...
@Override
protected void doGet(SlingHttpServletRequest slingRequest, 
    SlingHttpServletResponse slingResponse) throws ServletException, IOException {

    ResourceResolver resourceResolver = slingRequest.getResourceResolver();
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);

    Page resourcePage = pageManager.getContainingPage(slingRequest.getResource());

    Designer designer = resourceResolver.adaptTo(Designer.class);
    Design resourceDesign = designer.getDesign(resourcePage);
}

For more info, refer this doc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM