KickJava   Java API By Example, From Geeks To Geeks.

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


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: MoveWorkflowTask.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.WorkflowException;
30 import org.apache.tools.ant.BuildException;
31
32 /**
33  * Ant task, which implements the SiteTreeNodeVisitor for the operation move the workflow
34  * history files.
35  * (Visitor pattern)
36  */

37 public class MoveWorkflowTask extends TwoDocumentsOperationTask {
38
39     /**
40      *
41      */

42     public MoveWorkflowTask() {
43         super();
44     }
45
46     /** (non-Javadoc)
47      * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
48      */

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 JavaDoc language = labels[i].getLanguage();
56
57             String JavaDoc srcDocumentid = node.getAbsoluteId();
58             String JavaDoc destDocumentid = srcDocumentid.replaceFirst(this.getFirstdocumentid(),this.getSecdocumentid());
59
60             String JavaDoc srcUrl = builder.buildCanonicalUrl(publication, getFirstarea(), srcDocumentid, language);
61             String JavaDoc 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