2014-05-19 4 views
0

저는 이것이 매우 구체적인 질문이라는 것을 알고 있습니다. 그래서 약 1 년 전쯤에 약 50 페이지가 생성되었습니다. 우리는 머리말과 꼬리말에 특별히 새로운 구성 요소가있는 페이지를 개편하려고합니다. 메인 콘텐츠의 콘텐츠를 제외하고 동일하게 유지됩니다. 그래서 이전 페이지에서 새 페이지로 모든 것을 옮기려고하지만 주 내용 영역 만 유지하려고합니다. 문제는 콘텐츠가 다르기 때문에 이전 페이지의 리소스 유형을 새 페이지 구성 요소를 가리 키도록 변경할 수 없다는 것과 내가 원하지 않는 머리글과 바닥 글에 많은 노드를 갖게된다는 것입니다. 예를 들어 여기에 내 현재 콘텐츠 구조 :CQ - 한 페이지에서 다른 페이지로 콘텐츠 이동

올드 내용

star-trek 
    jcr:content 
     header 
      nav 
      social 
      chat 
     main-content 
      column-one 
      column-two 
     footer 
      sign-up 
      mega-menu 

새로운 콘텐츠

star-wars 
    jcr:content 
     masthead 
      mega-menu         
     main-content 
      column-one 
      column-two 
     bottom-footer 
      left-links 
      right-links 

누구는 메인에서 바로 컨텐츠를 이동하는 방법에 어떤 아이디어가 있습니까 - 콘텐트 노드와 어떻게 든 다른 노드를 제거합니다. 어떻게 든이 프로그래밍 방식으로 내가 처음부터 50 페이지를 만들고 싶지 않아 원인을 찾으려고 노력하고있어. 어떤 도움을 주셔서 감사합니다!

답변

1

JCR API를 사용하여 주변을 자유롭게 이동할 수 있습니다. 내가 하겠어

  1. 사용자가 해당 콘텐츠에 액세스하지 못하도록 차단합니다. 가능한 경우 임시 ACL을 사용하거나 프론트 엔드에서 액세스를 종료하여 수행 할 수 있습니다.
  2. 하는 사용자가 내가 한 페이지를 수정하는 스크립트를 제안 내용 수정 스크립트의 내용을 다시

에 액세스 할 수 있도록 결과를 확인 JCR API를

  • 를 사용하여 콘텐츠를 변경하는 스크립트 나 서블릿을 실행 (예 : /content/star-trek.modify.txt로 끝나는 HTTP 요청으로 호출) 테스트를 위해 단일 페이지, 테스트 또는 좋은 페이지 그룹에서 실행할 수 있습니다.

    스크립트는 현재 노드의 양식에서 시작하여 수정하는 방법을 알고있는 노드 (sling : resourceType)를 기반으로 노드를 찾아 수정하고 로그 또는 출력에서 ​​수행 한 내용을보고합니다.

    노드를 수정하기 위해 스크립트는 JCR 노드 API를 사용하여 주변을 이동합니다 (Worskpace.move 일 수도 있음).

  • 1

    당신이 필요로 수행하는 코드를 작성하는 참으로 가능하다 :

    package com.test; 
    
    import java.io.File; 
    import java.io.IOException; 
    
    import javax.jcr.ItemExistsException; 
    import javax.jcr.Repository; 
    import javax.jcr.RepositoryException; 
    import javax.jcr.Session; 
    import javax.jcr.SimpleCredentials; 
    import javax.jcr.Node; 
    
    import org.apache.jackrabbit.commons.JcrUtils; 
    import org.apache.jackrabbit.core.TransientRepository; 
    import org.xml.sax.SAXException; 
    
    public class test { 
    
        public void test(Document doc) throws RepositoryException { 
         try { 
    
          // Create a connection to the CQ repository running on local host 
    
          Repository repository = JcrUtils 
            .getRepository("http://localhost:4502/crx/server"); 
          System.out.println("rep is created"); 
    
          // Create a Session 
          javax.jcr.Session session = repository.login(new SimpleCredentials(
            "admin", "admin".toCharArray())); 
          System.out.println("session is created"); 
    
          String starTrekNodePath = "/content/path/"; 
          String starWarsNodePath = "/content/anotherPath" 
    
          Node starTrekpageJcrNode = null; 
          Node starWarstext = null; 
    
          setProperty(java.lang.String name, Node value) 
    
          boolean starTrekNodeFlag = session.nodeExists(starTrekNodePath); 
          boolean starWarsNodeFlag = session.nodeExists(starWarsNodePath); 
          if (starTrekNodeFlag && starWarsNodeFlag) { 
           System.out.println("to infinity and beyond"); 
           Node starTrekNode = session.getNode(starTrekNodePath); 
           Node starWarsNodeFlag = session.getNode(starWarsNodePath); 
    
           //apply nested looping logic here; to loop through all pages under this node 
           //assumption is that you have similar page titles or something 
    
           //on these lines to determine target and destination nodes 
              //2nd assumption is that destination pages exist with the component structures in q 
           //once we have the target nodes, the following segment should be all you need 
    
           Node starTrekChildNode = iterator.next();//assuming you use some form of iterator for looping logic 
           Node starWarsChildNode = iterator1.next();//assuming you use some form of iterator for looping logic 
    
           //next we get the jcr:content node of the target and child nodes 
    
           Node starTrekChildJcrNode = starTrekChildNode.getNode("jcr:content"); 
           Node starWarsChildJcrNode = starWarsChildNode.getNode("jcr:content"); 
    
           // now we fetch the main-component nodes. 
    
           Node starTrekChildMCNode = starTrekChildJcrNode.getNode("main-content"); 
           Node starWarsChildMCNode = starWarsChildJcrNode.getNode("main-content"); 
    
           //now we fetch each component node 
    
           Node starTrekChildC1Node = starTrekChildMCNode.getNode("column-one"); 
           Node starTrekChildC2Node = starTrekChildMCNode.getNode("column-two"); 
    
           Node starWarsChildC1Node = starWarsChildMCNode.getNode("column-one"); 
           Node starWarsChildC2Node = starWarsChildMCNode.getNode("column-two"); 
    
           // fetch the properties for each node of column-one and column-two from target 
           String prop1; 
           String prop2; 
           PropertyIterator iterator = starTrekChildC1Node.getProperties(propName); 
           while (iterator.hasNext()) { 
            Property prop = iterator.nextProperty(); 
            prop1 = prop.getString(); 
           } 
    
           PropertyIterator iterator = starTrekChildC2Node.getProperties(propName); 
           while (iterator.hasNext()) { 
            Property prop = iterator.nextProperty(); 
            prop2 = prop.getString(); 
           } 
    
    
    
           // and now we set the values 
    
           starWarsChildC1Node.setProperty("property-name",prop1); 
           starWarsChildC2Node.setProperty("property-name",prop2); 
    
           //end loops as appropriate 
    } 
    

    는 희망이 곧 정상 궤도에 당신을 설정해야합니다. 폴더 구조에 따라 /content의 폴더 구조를 기반으로 대상 페이지와 대상 페이지를 식별하는 방법을 알아야하지만 핵심 로직은 동일해야합니다.

    +0

    답장을 보내 주셔서 감사 드리며 코드 샘플을 제공해주십시오. 매우 감사. –

    0

    여기서 볼 수있는 결과에 대한 문제점은 JCR 조작을 실행하는 서블릿을 작성하여 주위를 이동시키는 것입니다. 기술적으로는 효과가 있지만 실제로 확장 가능하거나 재사용 할 수있는 방법은 아닙니다. 매우 구체적인 코드를 작성하고 배포하고 실행 한 다음 삭제해야합니다 (또는 영원히 존재합니다). 그것은 비현실적이며 완전히 RESTful이 아닙니다.

    동료의

    하나는 당신에게 스크립트 그루비 저장소로 변경 사용할 수있는 기능을 제공하는 CQ 그루비 콘솔을 썼다 :

    여기에 두 더 나은 옵션입니다. 설명 된 것처럼 콘텐츠 변환에 자주 사용합니다. Groovy 사용의 장점은 스크립트 (컴파일/전개 된 코드가 아님)입니다. 필요한 경우 JCR API에 여전히 액세스 할 수 있지만 콘솔에는 작업을 훨씬 쉽게 해주는 여러 가지 도우미 메서드가 있습니다. 이 방법을 적극 권장합니다.

    https://github.com/Citytechinc/cq-groovy-console

    다른 방법은 AEM에서 대량 편집기 도구를 사용하는 것입니다. 콘텐츠의 TSV를 내보내고 변경 한 다음 다시 가져올 수 있습니다. 관리 기능을 사용하여 가져 오기 기능을 켜야하지만이 기능을 일부 성공과 함께 사용했습니다. 주의 할 것은 배열 값 속성을 사용하면 약간 버그가있는 것입니다.