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.SiteTreeNode; 28 import org.apache.lenya.cms.workflow.WorkflowFactory; 29 import org.apache.lenya.workflow.WorkflowException; 30 import org.apache.tools.ant.BuildException; 31 32 37 public class MoveWorkflowTask extends TwoDocumentsOperationTask { 38 39 42 public MoveWorkflowTask() { 43 super(); 44 } 45 46 49 public void visitSiteTreeNode(SiteTreeNode node) { 50 Publication publication = getPublication(); 51 DocumentBuilder builder = publication.getDocumentBuilder(); 52 53 Label[] labels = node.getLabels(); 54 for (int i=0 ; i<labels.length; i ++){ 55 String language = labels[i].getLanguage(); 56 57 String srcDocumentid = node.getAbsoluteId(); 58 String destDocumentid = srcDocumentid.replaceFirst(this.getFirstdocumentid(),this.getSecdocumentid()); 59 60 String srcUrl = builder.buildCanonicalUrl(publication, getFirstarea(), srcDocumentid, language); 61 String destUrl = builder.buildCanonicalUrl(publication, getSecarea(), destDocumentid, language); 62 63 log("url for the source : "+srcUrl); 64 log("url for the destination : "+destUrl); 65 66 Document srcDoc; 67 Document destDoc; 68 WorkflowFactory factory = WorkflowFactory.newInstance(); 69 70 log("init workflow history"); 71 try { 72 srcDoc = builder.buildDocument(publication, srcUrl); 73 destDoc = builder.buildDocument(publication, destUrl); 74 } catch (DocumentBuildException e) { 75 throw new BuildException(e); 76 } 77 78 log("move workflow history of "+srcDoc.getFile().getAbsolutePath()+" to " + destDoc.getFile().getAbsolutePath()); 79 try { 80 if (factory.hasWorkflow(srcDoc)) { 81 log("has workflow"); 82 WorkflowFactory.moveHistory(srcDoc, destDoc); 83 log("workflow moved"); 84 } 85 } catch (WorkflowException e) { 86 throw new BuildException(e); 87 } 88 } 89 } 90 91 } 92 | Popular Tags |