AEM 6.3 - Check if page is published or not


If you want to know if the page is published or not you can use the below utility method to know if the page is published or not.
Steps -
  1. Take Resource Object.
  2. Adapt it to Page
  3. Adapt page to ReplicationStatus, you will get the status

Here is the code -

public static Boolean isPublished(Resource resource) {
Boolean activated;
ReplicationStatus status = null;
activated = false;
if (resource != null) {
try {
Page page = resource.adaptTo(Page.class);
status = page.adaptTo(ReplicationStatus.class);
} catch (Exception e) {
LOG.debug(e.getMessage(), e);
}
if (status != null) {
activated = status.isActivated();
}
}
return activated;
}

Comments

Popular

Sample CQ Filter

Search engine optimization in CQ