cq5 - livecopy - how to tell when a page is a live copy and finding the children of its parents

自闭症网瘾萝莉.ら 提交于 2019-12-07 06:43:08

问题


Our setup has various websites and some of which are livecopies from the main site. We are trying to determine if the page we are on is a livecopy. If so try and get its parent and the children of the parents. This allows us to determine each pages siblings to then use how we want.

Is this easily achievable using cq?


回答1:


Checking if the page is a live copy

You can use LiveRelationshipManager, adaptable from resource resolver:

resourceResolver.adaptTo(LiveRelationshipManager.class)

It has method hasLiveRelationship which will return true if passed resource is a live copy of something other. You can invoke this method passing current component resource.

Parent and siblings

Use PageManager and Page methods:

// resource - current component resource
ResourceResolver resolver = resource.getResourceResolver();
PageManager pageManager = resolver.adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(resource);
Page parentPage = currentPage.getParent();
Iterator<Page> siblings = parentPage.listChildren();


来源:https://stackoverflow.com/questions/18871093/cq5-livecopy-how-to-tell-when-a-page-is-a-live-copy-and-finding-the-children

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!