How copy node tree in AEM?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 07:01:28

问题


I need to get java code for copy node tree inside [content/dam/img.jpg and subnodes[jcr:content and metadata]] in to [etc/mynodes]

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

i want copy nodes :img.jpg>jcr:content>metadata


回答1:


You can use the JCR API to play with content nodes, here I have used an example with workspace.copy to move the /content/dam/geometrixx/portraits child nodes to /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();
  }
 } 
}



来源:https://stackoverflow.com/questions/39546610/how-copy-node-tree-in-aem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!