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.Situation; 30 import org.apache.lenya.workflow.WorkflowException; 31 import org.apache.tools.ant.BuildException; 32 33 34 39 public class InitCopyWorkflowTask extends TwoDocumentsOperationTask { 40 41 private String userId = ""; 42 private String machineIp = ""; 43 44 47 public InitCopyWorkflowTask() { 48 super(); 49 } 50 51 55 public String getMachineIp() { 56 return machineIp; 57 } 58 59 63 public void setMachineIp(String machineIp) { 64 this.machineIp = machineIp; 65 } 66 67 71 public String getUserId() { 72 return userId; 73 } 74 75 79 public void setUserId(String userId) { 80 this.userId = userId; 81 } 82 83 86 public void visitSiteTreeNode(SiteTreeNode node) { 87 Publication publication = getPublication(); 88 DocumentBuilder builder = publication.getDocumentBuilder(); 89 90 Label[] labels = node.getLabels(); 91 for (int i = 0 ; i < labels.length; i++){ 92 String language = labels[i].getLanguage(); 93 94 String srcDocumentid = node.getAbsoluteId(); 95 String destDocumentid = srcDocumentid.replaceFirst(this.getFirstdocumentid(),this.getSecdocumentid()); 96 97 String srcUrl = builder.buildCanonicalUrl(publication, getFirstarea(), srcDocumentid, language); 98 String destUrl = builder.buildCanonicalUrl(publication, getSecarea(), destDocumentid, language); 99 100 101 Document document; 102 Document newdocument; 103 WorkflowFactory factory = WorkflowFactory.newInstance(); 104 105 log("init workflow history"); 106 try { 107 document = builder.buildDocument(publication, srcUrl); 108 newdocument = builder.buildDocument(publication, destUrl); 109 } catch (DocumentBuildException e) { 110 throw new BuildException(e); 111 } 112 try { 113 if (factory.hasWorkflow(document)) { 114 String [] roles = new String [0]; 115 Situation situation = 116 WorkflowFactory.newInstance().buildSituation(roles, getUserId(), getMachineIp()); 117 WorkflowFactory.initHistory(document, newdocument, situation); 118 } 119 } catch (WorkflowException e) { 120 throw new BuildException(e); 121 } 122 } 123 } 124 125 } 126 | Popular Tags |