KickJava   Java API By Example, From Geeks To Geeks.

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


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: DeleteRCTask.java 160149 2005-04-05 09:51:54Z michi $ */
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.avalon.excalibur.io.FileUtil;
26 import org.apache.lenya.cms.publication.Publication;
27 import org.apache.lenya.cms.publication.SiteTree;
28 import org.apache.lenya.cms.publication.SiteTreeNode;
29 import org.apache.tools.ant.BuildException;
30
31 /**
32  * Ant task to delete the rcml- and backup files of documents corresponding to a defined subtree
33  * (Visitor pattern) Visitor of the subtree. The subtree is reverse visited.
34  */

35 public class DeleteRCTask extends TwoDocumentsOperationTask {
36     private String JavaDoc rcmldir = "";
37     private String JavaDoc rcbakdir = "";
38     private String JavaDoc srcareadir = "";
39
40     /**
41      *
42      */

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

50     public void visitSiteTreeNode(SiteTreeNode node) {
51         String JavaDoc publicationPath;
52         String JavaDoc rcmlDirectory;
53         String JavaDoc rcbakDirectory;
54         try {
55             publicationPath = this.getPublicationDirectory().getCanonicalPath();
56             rcmlDirectory =
57                 new File JavaDoc(publicationPath, this.getRcmldir()).getCanonicalPath();
58             rcbakDirectory =
59                 new File JavaDoc(publicationPath, this.getRcbakdir())
60                     .getCanonicalPath();
61         } catch (IOException JavaDoc e) {
62             throw new BuildException(e);
63         }
64
65         String JavaDoc destDocumentid = node.getAbsoluteId();
66         String JavaDoc srcDocumentid =
67             destDocumentid.replaceFirst(
68                 getSecdocumentid(),
69                 getFirstdocumentid());
70
71         File JavaDoc srcRcmlDir =
72             new File JavaDoc(
73                 rcmlDirectory,
74                 this.getSrcareadir() + File.separator + srcDocumentid);
75
76         if (srcRcmlDir.exists()) {
77             try {
78                 FileUtil.forceDelete(srcRcmlDir);
79             } catch (IOException JavaDoc e) {
80                 //FIXME: catch Exception because of window's delete problem
81
log("exception " + e);
82             }
83         }
84
85         File JavaDoc srcRcbakDir =
86             new File JavaDoc(
87                 rcbakDirectory,
88                 this.getSrcareadir() + File.separator + srcDocumentid);
89
90         if (srcRcbakDir.exists()) {
91             try {
92                 FileUtil.forceDelete(srcRcbakDir);
93             } catch (IOException JavaDoc e) {
94                 //FIXME: catch Exception because of window's delete problem
95
log("exception " + e);
96             }
97             log("delete rcbak directory " + srcRcbakDir.getAbsolutePath());
98         }
99
100     }
101
102     /**
103      * @see org.apache.tools.ant.Task#execute()
104      **/

105     public void execute() throws BuildException {
106         try {
107             log("document-id for the source :" + this.getFirstdocumentid());
108             log("document-id for the destination :" + this.getSecdocumentid());
109             log("area for the destination :" + this.getSecarea());
110             log("rcml dir" + this.getRcmldir());
111             log("rcbak dir" + this.getRcbakdir());
112             log("src area dir" + this.getSrcareadir());
113
114             //visit the destination tree
115
Publication publication = getPublication();
116             SiteTree tree = publication.getTree(this.getSecarea());
117             SiteTreeNode node = tree.getNode(this.getSecdocumentid());
118             node.acceptReverseSubtree(this);
119
120         } catch (Exception JavaDoc e) {
121             throw new BuildException(e);
122         }
123     }
124     /**
125      * @return The backup directory.
126      */

127     public String JavaDoc getRcbakdir() {
128         return rcbakdir;
129     }
130
131     /**
132      * @return The rcml directory.
133      */

134     public String JavaDoc getRcmldir() {
135         return rcmldir;
136     }
137
138     /**
139      * @return The path of the area from the publication.
140      */

141     public String JavaDoc getSrcareadir() {
142         return srcareadir;
143     }
144
145     /**
146      * @param string The backup directory.
147      */

148     public void setRcbakdir(String JavaDoc string) {
149         rcbakdir = string;
150     }
151
152     /**
153      * @param string The rcml directory.
154      */

155     public void setRcmldir(String JavaDoc string) {
156         rcmldir = string;
157     }
158
159     /**
160      * @param string The path of the area from the publication.
161      */

162     public void setSrcareadir(String JavaDoc string) {
163         srcareadir = string;
164     }
165
166 }
167
Popular Tags