KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > InitCopyWorkflowTask


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: InitCopyWorkflowTask.java 42616 2004-03-03 12:56:33Z gregor $ */
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 /**
35  * Ant task, which implements the SiteTreeNodeVisitor for the operation init the workflow history files
36  * when copying documents
37  * (Visitor pattern)
38  */

39 public class InitCopyWorkflowTask extends TwoDocumentsOperationTask {
40
41     private String JavaDoc userId = "";
42     private String JavaDoc machineIp = "";
43
44     /**
45      *
46      */

47     public InitCopyWorkflowTask() {
48         super();
49     }
50
51     /**
52      * Returns the machine IP address from which the history was initialized.
53      * @return A string.
54      */

55     public String JavaDoc getMachineIp() {
56         return machineIp;
57     }
58
59     /**
60      * Sets the machine IP address from which the history was initialized.
61      * @param machineIp A string.
62      */

63     public void setMachineIp(String JavaDoc machineIp) {
64         this.machineIp = machineIp;
65     }
66
67     /**
68      * Returns the ID of the user who initialized the history.
69      * @return A string.
70      */

71     public String JavaDoc getUserId() {
72         return userId;
73     }
74
75     /**
76      * Sets the ID of the user who initialized the history.
77      * @param userId A string.
78      */

79     public void setUserId(String JavaDoc userId) {
80         this.userId = userId;
81     }
82
83     /** (non-Javadoc)
84      * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
85      */

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 JavaDoc language = labels[i].getLanguage();
93
94             String JavaDoc srcDocumentid = node.getAbsoluteId();
95             String JavaDoc destDocumentid = srcDocumentid.replaceFirst(this.getFirstdocumentid(),this.getSecdocumentid());
96
97             String JavaDoc srcUrl = builder.buildCanonicalUrl(publication, getFirstarea(), srcDocumentid, language);
98             String JavaDoc 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 JavaDoc[] roles = new String JavaDoc[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