KickJava   Java API By Example, From Geeks To Geeks.

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


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: InitWorkflowHistoryTask.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.DocumentType;
26 import org.apache.lenya.cms.publication.DocumentTypeBuilder;
27 import org.apache.lenya.cms.publication.Publication;
28 import org.apache.lenya.cms.workflow.WorkflowFactory;
29 import org.apache.lenya.workflow.Situation;
30 import org.apache.tools.ant.BuildException;
31
32 public class InitWorkflowHistoryTask extends PublicationTask {
33     private String JavaDoc documentId;
34     private String JavaDoc documentType;
35     private String JavaDoc language;
36
37     /**
38      * Returns the machine IP address from which the history was initialized.
39      * @return A string.
40      */

41     public String JavaDoc getMachineIp() {
42         return machineIp;
43     }
44
45     /**
46      * Sets the machine IP address from which the history was initialized.
47      * @param machineIp A string.
48      */

49     public void setMachineIp(String JavaDoc machineIp) {
50         this.machineIp = machineIp;
51     }
52
53     /**
54      * Returns the ID of the user who initialized the history.
55      * @return A string.
56      */

57     public String JavaDoc getUserId() {
58         return userId;
59     }
60
61     /**
62      * Sets the ID of the user who initialized the history.
63      * @param userId A string.
64      */

65     public void setUserId(String JavaDoc userId) {
66         this.userId = userId;
67     }
68
69     /**
70      * @see org.apache.tools.ant.Task#execute()
71      */

72     public void execute() throws BuildException {
73         String JavaDoc language = getLanguage();
74
75         if (language == null) {
76             language = getPublication().getDefaultLanguage();
77         }
78         DocumentBuilder builder = getPublication().getDocumentBuilder();
79         String JavaDoc url = builder.buildCanonicalUrl(getPublication(), Publication.AUTHORING_AREA, getDocumentId(), language);
80         Document document;
81         try {
82             document = builder.buildDocument(getPublication(), url);
83             log(".execute(): " + document.getLanguage());
84         } catch (DocumentBuildException e) {
85             throw new BuildException(e);
86         }
87
88         try {
89             String JavaDoc[] roles = new String JavaDoc[0];
90             Situation situation =
91                 WorkflowFactory.newInstance().buildSituation(roles, getUserId(), getMachineIp());
92             DocumentType type =
93                 DocumentTypeBuilder.buildDocumentType(getDocumentType(), getPublication());
94             WorkflowFactory.initHistory(document, type.getWorkflowFileName(), situation);
95         } catch (Exception JavaDoc e) {
96             throw new BuildException(e);
97         }
98     }
99
100     /**
101      * Get the document-id.
102      *
103      * @return the document-id
104      */

105     public String JavaDoc getDocumentId() {
106         assertString(documentId);
107
108         return documentId;
109     }
110
111     /**
112      * Set the document-id.
113      *
114      * @param aDocumentId the document-id
115      */

116     public void setDocumentId(String JavaDoc aDocumentId) {
117         assertString(aDocumentId);
118         documentId = aDocumentId;
119     }
120
121     /**
122      * Get the document type.
123      *
124      * @return the document type
125      */

126     public String JavaDoc getDocumentType() {
127         assertString(documentType);
128
129         return documentType;
130     }
131
132     /**
133      * Set the document type.
134      *
135      * @param aDocumentType the document type
136      */

137     public void setDocumentType(String JavaDoc aDocumentType) {
138         assertString(aDocumentType);
139         documentType = aDocumentType;
140     }
141
142     /**
143      * Get the language.
144      *
145      * @return the language
146      */

147     public String JavaDoc getLanguage() {
148         return language;
149     }
150
151     /**
152      * Set the language.
153      *
154      * @param string the language
155      */

156     public void setLanguage(String JavaDoc string) {
157         language = string;
158     }
159
160     private String JavaDoc userId = "";
161     private String JavaDoc machineIp = "";
162
163 }
164
Popular Tags