Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

I want page.listChildren() to return only published pages

Avatar

Level 5

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

Thank you

6 Replies

Avatar

Level 5

Hi @rahul234dabas,

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

Avatar

Level 7

Another option is looking for property cq:replicationAction with value 'replicated'.

Avatar

Level 5

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.)

Chandra_Hire_0-1666723481411.png

 

Avatar

Level 5

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

Avatar

Level 5

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.

Please have a look on the APIs

ValueMap (The Adobe AEM Quickstart and Web Application.)

ReplicationActionType (The Adobe AEM Quickstart and Web Application.)

Avatar

Level 7

When an existing page has been deactivated, the property value is "deactivated".