1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.util.StringTokenizer ; 23 24 import org.apache.lenya.cms.publication.Publication; 25 import org.apache.lenya.cms.publication.SiteTree; 26 import org.apache.lenya.cms.publication.SiteTreeException; 27 import org.apache.lenya.cms.publication.SiteTreeNode; 28 29 32 public class InsertCopyNode extends TwoNodesTask { 33 36 public InsertCopyNode() { 37 super(); 38 } 39 40 49 public void manipulateTree(String firstdocumentid, String secdocumentid, String firstarea, 50 String secarea) throws SiteTreeException { 51 52 Publication publication = getPublication(); 53 SiteTree firsttree = publication.getTree(firstarea); 54 SiteTree sectree = publication.getTree(secarea); 55 56 String parentid = ""; 57 StringTokenizer st = new StringTokenizer (secdocumentid, "/"); 58 int length = st.countTokens(); 59 60 for (int i = 0; i < (length - 1); i++) { 61 parentid = parentid + "/" + st.nextToken(); 62 } 63 String newid = st.nextToken(); 64 65 SiteTreeNode node = firsttree.getNode(firstdocumentid); 66 67 if (node != null) { 68 SiteTreeNode parentNode = sectree.getNode(parentid); 69 if (parentNode != null) { 70 sectree.copy(node, parentNode, newid, null); 71 } else { 72 throw new SiteTreeException("The parent node " + parentNode 73 + " where the copied node shall be inserted not found"); 74 } 75 } else { 76 throw new SiteTreeException("Node " + node + " couldn't be found"); 77 } 78 if (firstarea.equals(secarea)) { 79 firsttree.save(); 80 } else { 81 firsttree.save(); 82 sectree.save(); 83 } 84 } 85 } | Popular Tags |