how to publish a page programmatically in cq5 | Community
Skip to main content
October 16, 2015
Solved

how to publish a page programmatically in cq5

  • October 16, 2015
  • 3 replies
  • 1863 views

how to publish a page programmatically in cq5

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ojjis

Hi.
It is possible form a servlet to get hold of a replicator by using the @Reference annotation. 
(more info about that here http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/replication/Replicator.html)

To get hold of a replicator you can use the following code:

@Reference private Replicator replicator;


Then you can use the following code to replicate a page to a publish instance:
 

String path = "PATH OF THE RESOURCE HERE"; Session session = //Get the session fro eg. a the request try { replicator.replicate(session, "ACTIVATE", path); } catch(ReplicationException replicationException) { //Handle the replication exception }

The same goes for any deactivation of a resource.
Hope that will help you.

/Johan

3 replies

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015
Ojjis
OjjisAccepted solution
Level 7
October 16, 2015

Hi.
It is possible form a servlet to get hold of a replicator by using the @Reference annotation. 
(more info about that here http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/replication/Replicator.html)

To get hold of a replicator you can use the following code:

@Reference private Replicator replicator;


Then you can use the following code to replicate a page to a publish instance:
 

String path = "PATH OF THE RESOURCE HERE"; Session session = //Get the session fro eg. a the request try { replicator.replicate(session, "ACTIVATE", path); } catch(ReplicationException replicationException) { //Handle the replication exception }

The same goes for any deactivation of a resource.
Hope that will help you.

/Johan

Lokesh_Shivalingaiah
Level 10
October 16, 2015

I would like to just add the below point with Johan

You can use ReplicationActionType to get the different events like ACTIVATE, DEACTIVATE, DELETE, REVERSE (for reverse replicate)

replicator.replicate(session, ReplicationActionType.ACTIVATE, path);

 

~Loki