3 Replies Latest reply on Jul 10, 2013 9:01 AM by Yogesh Upadhyay

    How to replicate contents of a folder


      We have a folder(nt:folder) containing images. We would like to replicate all the images to the publish environment. I have tried the following implementation but it only replicates the folder  without the content. Is there any way to replicate the content at the same time without iterating through each node?


      Currently using CQ5.4


      Thank you.

              String agentId="someAgent";
              String folderPath="/content/dam/images/someFolder"; 
              ReplicationOptions opts = new ReplicationOptions();
              AgentIdFilter filter = new AgentIdFilter(agentId);
              Replicator replicator = sling.getService(Replicator.class);
              replicator.replicate(mySession, ReplicationActionType.ACTIVATE, folderPath, opts);
        • 1. Re: How to replicate contents of a folder
          sivaprasadreddys Level 1




              You need to repicate notes recursively instead of just root path. Can you try something like this:



          public void recursiveReplication(Session session, String path, BufferedWriter out,

                      WorkItem workItem) throws IOException,Exception{ 



                  doReplicate(session, path,out,workItem);           // Calling method to replicate


                  Resource res = resolver.getResource(path);


                  Iterator<Resource> iter = resolver.listChildren(res);

                  while (iter.hasNext()) {

                      Resource tempResource=iter.next();

                      String temp=tempResource.getPath();

                      //checking for hierarchyNode


                      Node node = tempResource.adaptTo(Node.class);

                            if (!node.isNodeType("nt:hierarchyNode")){




                               recursiveReplication(session, temp,out,workItem);






              }// end of recursiveReplication()mthd





              public void doReplicate(Session session, String path,BufferedWriter out,

                      WorkItem workItem) throws IOException,Exception{


                  try {          

                      //Code related to the replicate...           


                  } catch (ReplicationException e) {




              }// end of doReplicate()mthd



          Hope it helps..







          1 person found this helpful
          • 2. Re: How to replicate contents of a folder
            MGEB Level 1

            Thanks sivaprasadreddys, I guess there is no other way where we can give the replicator the list of nodes to be replicated and call it once.

            • 3. Re: How to replicate contents of a folder
              Yogesh Upadhyay Level 4

              Check code for tree activation in CQ. It is under /libs/cq/replication/components/treeactivation




              1 person found this helpful