2016-09-17 3 views
-1

Ich muss innerhalb von Java-Code für die Kopie Knotenstruktur erhalten [content/dam/img.jpg und untergeordneten Knoten [jcr: Inhalte und Metadaten]] um [etc/mynodes]Wie kopieren Knotenbaum in AEM?

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

i Knoten wollen kopieren: img.jpg> jcr: content> Metadaten

Antwort

1

können Sie die JCR API verwenden, um mit Inhalt Knoten zu spielen, hier habe ich ein Beispiel mit workspace.copy verwendeten /content/Damm zu bewegen/geometrixx/Portrait Kindknoten zu /etc/mynodes/test

workspace.copy ("/ content/dam/geometrixx/Porträts", "/ 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

+0

seine Arbeiten dank :-) –

+0

@Hanin Jazi, nehmen Sie bitte die Antwort, wenn es funktioniert. Herzlich willkommen – VAr