A use case where I find programmatically activate CQ page helpful is when you have user submits content, you store the content in the usergenerated content area (or in the JCR repo), you have an editorial workflow to moderate the reverse replicated content in Author instance. Upon action taken on the Author instance on the reverse replicated content (i.e. CQ page), you want to replicate the content back to Publish instance.

 

package ...

import ...
...

@Component(label = "My Service", immediate = true, metatype = false) @Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "My Service"), @Property(name = Constants.SERVICE_VENDOR, value = "My Company") }) @Service(value = {MyService.class })
public class MyServiceImpl implements MyService
{
...
@Reference
private Replicator replicator
...
public void activate(Session session, String pathToPage) { // isAuthorInstance and LOGGER need to be defined somewhere in your application if (isAuthorInstance) { try { if (replicator != null) { opts.setFilter(new AgentFilter() { public boolean isIncluded(Agent agent) { return agent.getId().equals("publish"); // the name of your reverse replication agent (i.e. publish) } }); replicator.checkPermission(session, ReplicationActionType.ACTIVATE, pathToPage); replicator.replicate(session, ReplicationActionType.ACTIVATE, pathToPage, this.opts);
this.LOGGER.debug(pathToPage + " was activated."); } else { this.LOGGER.error("replicator is null"); } } catch (ReplicationException ex) { this.LOGGER.error(ex.getMessage()); } } }
}