1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import org.apache.lenya.cms.publication.Document; 23 import org.apache.lenya.cms.publication.DocumentBuildException; 24 import org.apache.lenya.cms.publication.DocumentBuilder; 25 import org.apache.lenya.cms.publication.Label; 26 import org.apache.lenya.cms.publication.Publication; 27 import org.apache.lenya.cms.publication.SiteTree; 28 import org.apache.lenya.cms.publication.SiteTreeNode; 29 import org.apache.lenya.cms.publication.SiteTreeNodeVisitor; 30 import org.apache.lenya.cms.workflow.WorkflowFactory; 31 import org.apache.lenya.workflow.WorkflowException; 32 import org.apache.tools.ant.BuildException; 33 34 38 public class MoveDocumentTask extends PublicationTask implements SiteTreeNodeVisitor { 39 40 private String firstarea; 41 private String firstdocumentid; 42 private String secarea; 43 private String secdocumentid; 44 45 48 public MoveDocumentTask() { 49 super(); 50 } 51 52 55 public String getFirstarea() { 56 return firstarea; 57 } 58 59 62 public String getFirstdocumentid() { 63 return firstdocumentid; 64 } 65 66 69 public String getSecarea() { 70 return secarea; 71 } 72 73 76 public String getSecdocumentid() { 77 return secdocumentid; 78 } 79 80 84 public void setFirstarea(String string) { 85 firstarea = string; 86 } 87 88 92 public void setFirstdocumentid(String string) { 93 firstdocumentid = string; 94 } 95 96 100 public void setSecarea(String string) { 101 secarea = string; 102 } 103 104 108 public void setSecdocumentid(String string) { 109 secdocumentid = string; 110 } 111 112 117 public void visitSiteTreeNode(SiteTreeNode node) { 118 Publication publication = getPublication(); 119 120 Label[] labels = node.getLabels(); 121 for (int i = 0; i < labels.length; i++) { 122 String language = labels[i].getLanguage(); 123 124 String srcDocumentid = node.getAbsoluteId(); 125 String destDocumentid = srcDocumentid.replaceFirst(firstdocumentid, secdocumentid); 126 127 132 DocumentBuilder builder = publication.getDocumentBuilder(); 134 String url = builder.buildCanonicalUrl(publication, firstarea, srcDocumentid, language); 135 String newurl = 136 builder.buildCanonicalUrl(publication, secarea, destDocumentid, language); 137 138 Document document; 139 Document newDocument; 140 WorkflowFactory factory = WorkflowFactory.newInstance(); 141 142 log("move workflow history"); 143 try { 144 document = builder.buildDocument(publication, url); 145 newDocument = builder.buildDocument(publication, newurl); 146 } catch (DocumentBuildException e) { 147 throw new BuildException(e); 148 } 149 try { 150 if (factory.hasWorkflow(document)) { 151 WorkflowFactory.moveHistory(document, newDocument); 152 } 153 } catch (WorkflowException e) { 154 throw new BuildException(e); 155 } 156 157 } 158 } 159 160 163 public void execute() throws BuildException { 164 try { 165 log("document id for the source" + this.getFirstdocumentid()); 166 log("area for the source" + this.getFirstarea()); 167 log("document id for the destination" + this.getSecdocumentid()); 168 log("area for the destination" + this.getSecarea()); 169 170 Publication publication = getPublication(); 171 SiteTree tree = publication.getTree(getFirstarea()); 172 SiteTreeNode node = tree.getNode(getFirstdocumentid()); 173 174 node.acceptSubtree(this); 175 } catch (Exception e) { 176 throw new BuildException(e); 177 } 178 } 179 180 } 181 | Popular Tags |