KickJava   Java API By Example, From Geeks To Geeks.

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


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: InitRCTask.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.lenya.cms.publication.Document;
26 import org.apache.lenya.cms.publication.DocumentBuilder;
27 import org.apache.lenya.cms.publication.Label;
28 import org.apache.lenya.cms.publication.Publication;
29 import org.apache.lenya.cms.publication.SiteTreeNode;
30 import org.apache.lenya.cms.rc.RevisionController;
31 import org.apache.tools.ant.BuildException;
32
33 /**
34  * Ant task, to init the rc files of the destination's documents corresponding to a given source subtree.
35  * Evry destination file is checked in.
36  * (Visitor pattern)
37  */

38 public class InitRCTask extends TwoDocumentsOperationTask {
39     private String JavaDoc rcmlDir = "";
40     private String JavaDoc rcbakDir = "";
41     private String JavaDoc userId = "";
42     private RevisionController rc = null;
43     /**
44      *
45      */

46     public InitRCTask() {
47         super();
48     }
49
50     /**
51      * @return String The backups' directory.
52      */

53     public String JavaDoc getRcbakDir() {
54         return rcbakDir;
55     }
56
57     /**
58      * @return String The rcml-files' directory.
59      */

60     public String JavaDoc getRcmlDir() {
61         return rcmlDir;
62     }
63
64     /**
65      * @param string The backup's directory.
66      */

67     public void setRcbakDir(String JavaDoc string) {
68         rcbakDir = string;
69     }
70
71     /**
72      * @param string The rcml-files' directory.
73      */

74     public void setRcmlDir(String JavaDoc string) {
75         rcmlDir = string;
76     }
77
78     /**
79      * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
80      */

81     public void visitSiteTreeNode(SiteTreeNode node) {
82         try {
83             Publication publication = getPublication();
84             String JavaDoc publicationPath =
85                 this.getPublicationDirectory().getCanonicalPath();
86             DocumentBuilder builder = publication.getDocumentBuilder();
87
88             String JavaDoc srcDocumentid = node.getAbsoluteId();
89             String JavaDoc destDocumentid =
90                 srcDocumentid.replaceFirst(
91                     getFirstdocumentid(),
92                     getSecdocumentid());
93
94             Label[] labels = node.getLabels();
95             for (int i = 0; i < labels.length; i++) {
96                 String JavaDoc language = labels[i].getLanguage();
97                 String JavaDoc destUrl =
98                     builder.buildCanonicalUrl(
99                         publication,
100                         getSecarea(),
101                         destDocumentid,
102                         language);
103                 Document destDoc;
104                 destDoc = builder.buildDocument(publication, destUrl);
105                 String JavaDoc filename = destDoc.getFile().getCanonicalPath();
106                 filename = filename.substring(publicationPath.length());
107                 rc.reservedCheckIn(filename, getUserId(), true);
108             }
109         } catch (Exception JavaDoc e) {
110             throw new BuildException(e);
111         }
112     }
113
114     /**
115      * @see org.apache.tools.ant.Task#execute()
116      **/

117
118     public void execute() throws BuildException {
119         try {
120             log("rcml dir" + this.getRcmlDir());
121             log("rcbak dir" + this.getRcbakDir());
122             log("user" + this.getUserId());
123             String JavaDoc publicationPath =
124                 this.getPublicationDirectory().getCanonicalPath();
125             String JavaDoc rcmlDirectory = new File JavaDoc(publicationPath, this.getRcmlDir()).getCanonicalPath();
126             String JavaDoc rcbakDirectory = new File JavaDoc(publicationPath, this.getRcbakDir()).getCanonicalPath();
127             this.rc =
128                 new RevisionController(
129             rcmlDirectory,
130             rcbakDirectory,
131                     publicationPath);
132         } catch (IOException JavaDoc e) {
133             throw new BuildException(e);
134         }
135         super.execute();
136     }
137
138     /**
139      * @return String The user id.
140      */

141     public String JavaDoc getUserId() {
142         return userId;
143     }
144
145     /**
146      * @param string The user id.
147      */

148     public void setUserId(String JavaDoc string) {
149         userId = string;
150     }
151
152 }
153
Popular Tags