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 MoveNode extends TwoNodesTask { 33 private String refdocumentid; 34 37 public MoveNode() { 38 super(); 39 } 40 41 50 public void manipulateTree( 51 String firstdocumentid, 52 String secdocumentid, 53 String firstarea, 54 String secarea) 55 throws SiteTreeException { 56 57 Publication publication = getPublication(); 58 SiteTree firsttree = publication.getTree(firstarea); 59 SiteTree sectree = publication.getTree(secarea); 60 61 String parentid = ""; 62 StringTokenizer st = new StringTokenizer (secdocumentid, "/"); 63 int length = st.countTokens(); 64 65 for (int i = 0; i < (length - 1); i++) { 66 parentid = parentid + "/" + st.nextToken(); 67 } 68 String newid = st.nextToken(); 69 70 SiteTreeNode node = firsttree.getNode(firstdocumentid); 71 if (node != null) { 72 SiteTreeNode parentNode = sectree.getNode(parentid); 73 if (parentNode != null) { 74 sectree.move(node, parentNode, newid, this.getRefdocumentid()); 75 } else { 76 throw new SiteTreeException( 77 "The parent node " 78 + parentNode 79 + " where the removed node shall be inserted not found"); 80 } 81 } else { 82 throw new SiteTreeException( 83 "Node " + node + " couldn't be removed"); 84 } 85 86 if (firstarea.equals(secarea)) { 87 firsttree.save(); 88 } else { 89 firsttree.save(); 90 sectree.save(); 91 } 92 } 93 97 public String getRefdocumentid() { 98 return refdocumentid; 99 } 100 101 105 public void setRefdocumentid(String string) { 106 refdocumentid = string; 107 } 108 109 } 110 | Popular Tags |