如何复制AEM中的节点树?
问题描述:
我需要获得一份内部节点树java代码[内容/大坝/ img.jpg和子节点[JCR:内容和元数据]中[ETC/mynodes]如何复制AEM中的节点树?
Source path: conten/dam/img.jp
Destin path: etc/mynodes
我想复制节点: img.jpg> JCR:内容>元
答
您可以使用JCR API与内容节点玩,在这里我用一个例子与workspace.copy移动/内容/大坝/ geometrixx /人像子节点到/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();
}
}
}
其工作的感谢:-) –
@Hanin Jazi,请接受的答案,如果它的工作原理。欢迎 – VAr