如何在AEM中复制节点树? [英] How copy node tree in AEM?

查看:84
本文介绍了如何在AEM中复制节点树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

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

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);

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();
  }
 } 
}

这篇关于如何在AEM中复制节点树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆