Hi, I want a list of published pages so that I can use them further,
Currently, I am using page.listChildren() it fulfill my purpose other but I only want the pages that are unpublished
Can anyone help me out, please
It can be done with below ways.
1. Sling API (com.day.cq.wcm.api.Page)
You can filter Iterator<Page> you are getting from page.listChildren() for unpublished pages, using existence of 'cq:lastReplicated' property on page. If this property exists it means page is published authorwise un-publised.
ValueMap pageProperties = page.getProperties().
//Check the existence of 'cq:lastReplicated' and maitain collenction accordingly.
Please refer Page API - Page (The Adobe AEM Quickstart and Web Application.)
2. Using QueryBuilder API.
Create a query to filter the pages for non-existence of 'cq:lastReplicated' property and then iterate over the result.
Please refer (mainly Java snippet) - Query Builder API | Adobe Experience Manager
Hope this helps
That's correct, it will be more optimal to use property cq:replicationAction (a small correction to check property value as 'Activate' for published page.)
hi @Chandra_Hire the fix is working fine when I "view it as published" but it breaks when viewed on published page.
The value cq:lastReplicationAction gives null value and hence I am not able to proceed
Hi @rahul234dabas ,
If page is not activated (or not done any other replication activity to this page so far e.g. deactivation), cq:lastReplicationAction property will be null. You need to handle null while getting this property from ValueMap (please check API below) and if property exists, it returns ReplicationActionType based on the status. Hence, you need to check if its null then ignore it and if exists then need to check its value and it should be ReplicationActionType.ACTIVATE (You can use String type also for actual value 'Activate') for published pages.