如何在AEM中复制节点树?

时间:2016-09-17 12:05:48

标签: java aem

我需要在[etc / mynodes]的[content / dam / img.jpg和子节点[jcr:content and metadata]]中获取复制节点树的java代码

Source path: conten/dam/img.jp
Destin path: etc/mynodes

我想要复制节点:img.jpg> jcr:content>元数据

1 个答案:

答案 0 :(得分:2)

您可以使用JCR API来播放内容节点,这里我使用了 workspace.copy 的示例来移动 / content / dam / geometrixx / portraits 子节点到 / etc / mynodes / test

  

workspace.copy(" / content / dam / geometrixx / portraits"," / etc / mynodes / test");

package com.org.var.test;

import javax.jcr.Repository; 
import javax.jcr.Session; 
import javax.jcr.SimpleCredentials; 
import javax.jcr.Node; 
import javax.jcr.Workspace;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.core.TransientRepository; 

public class WorkspaceCopyTest { 

public static void main(String[] args) throws Exception { 

try { 

//Create a connection to the CQ repository running on local host 
 Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

   //Create a Session
   javax.jcr.Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray())); 

   Workspace workspace = session.getWorkspace();
    System.out.println(workspace.getName()); 
    //make sure you doesn't have test folder in /etc/mynodes/test it will create the test folder
  workspace.copy("/content/dam/geometrixx/portraits", "/etc/mynodes/test");
   System.out.println("workspace copy completed"); 

  session.logout();
  }
 catch(Exception e){
  e.printStackTrace();
  }
 } 
}

workspacecopy