KickJava   Java API By Example, From Geeks To Geeks.

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


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: DeleteResourcesTask.java 160149 2005-04-05 09:51:54Z michi $ */
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.ResourcesManager;
28 import org.apache.lenya.cms.publication.SiteTree;
29 import org.apache.lenya.cms.publication.SiteTreeNode;
30 import org.apache.tools.ant.BuildException;
31
32 /**
33  * Ant task to delete the resources of documents corresponding to a defined subtree
34  * (Visitor pattern) Visitor of the subtree. The subtree is reverse visited.
35  */

36 public class DeleteResourcesTask extends TwoDocumentsOperationTask {
37
38     /**
39      *
40      */

41     public DeleteResourcesTask() {
42         super();
43     }
44
45     /**
46      * Delete the resources of the documents corresponding to this node
47      *
48      * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
49      */

50     public void visitSiteTreeNode(SiteTreeNode node) {
51         Publication publication = getPublication();
52         DocumentBuilder builder = publication.getDocumentBuilder();
53
54         String JavaDoc destDocumentid = node.getAbsoluteId();
55         String JavaDoc srcDocumentid =
56             destDocumentid.replaceFirst(
57                 getSecdocumentid(),
58                 getFirstdocumentid());
59
60         Label[] labels = node.getLabels();
61         for (int i = 0; i < labels.length; i++) {
62             String JavaDoc language = labels[i].getLanguage();
63             String JavaDoc url =
64                 builder.buildCanonicalUrl(
65                     publication,
66                     getFirstarea(),
67                     srcDocumentid,
68                     language);
69             Document srcDoc;
70             try {
71                 srcDoc = builder.buildDocument(publication, url);
72             } catch (DocumentBuildException e) {
73                 throw new BuildException(e);
74             }
75
76             ResourcesManager resourcesMgr = new ResourcesManager(srcDoc);
77             resourcesMgr.deleteResources();
78         }
79     }
80
81     /**
82      * @see org.apache.tools.ant.Task#execute()
83      **/

84     public void execute() throws BuildException {
85         try {
86             log("document-id for the source :" + this.getFirstdocumentid());
87             log("area for the source :" + this.getFirstarea());
88             log("document-id for the destination :" + this.getSecdocumentid());
89             log("area for the destination :" + this.getSecarea());
90
91             Publication publication = getPublication();
92             SiteTree tree = publication.getTree(this.getSecarea());
93             SiteTreeNode node = tree.getNode(this.getSecdocumentid());
94             node.acceptReverseSubtree(this);
95         } catch (Exception JavaDoc e) {
96             throw new BuildException(e);
97         }
98     }
99
100 }
101
Popular Tags