KickJava   Java API By Example, From Geeks To Geeks.

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


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: DeleteNodeTask.java 160543 2005-04-08 11:30:01Z andreas $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import org.apache.lenya.cms.publication.SiteTree;
23 import org.apache.lenya.cms.publication.SiteTreeException;
24 import org.apache.lenya.cms.publication.SiteTreeNode;
25 import org.apache.tools.ant.BuildException;
26
27
28 /**
29  * Ant task to delete a node of a tree.
30  */

31 public class DeleteNodeTask extends PublicationTask {
32     private String JavaDoc area;
33     private String JavaDoc documentid;
34
35     /**
36      * Creates a new instance of DeleteNodeTask
37      */

38     public DeleteNodeTask() {
39         super();
40     }
41
42     /**
43      * Get the area.
44      *
45      * @return the area.
46      */

47     public String JavaDoc getArea() {
48         return area;
49     }
50
51     /**
52      * Set the area.
53      *
54      * @param area the area
55      */

56     public void setArea(String JavaDoc area) {
57         this.area = area;
58     }
59
60     /**
61      * return the document-id corresponding to the node to delete
62      * @return string The document-id.
63      */

64     protected String JavaDoc getDocumentid() {
65         return documentid;
66     }
67
68     /**
69      * Set the value of the document-id corresponding to the node to delete
70      *
71      * @param string The document-id.
72      */

73     public void setDocumentid(String JavaDoc string) {
74         documentid = string;
75     }
76
77     /**
78      * Delete a node of a tree.
79      *
80      * @param documentid The id of the document corresponding to the node to delete.
81      * @param area the areaof the tree
82      *
83      * @throws SiteTreeException if an error occurs
84      */

85     public void deleteNode(String JavaDoc documentid, String JavaDoc area)
86         throws SiteTreeException {
87         SiteTree tree = null;
88
89         try {
90             tree = getPublication().getTree(area);
91             tree.deleteNode(documentid);
92             tree.save();
93         } catch (Exception JavaDoc e) {
94             throw new SiteTreeException(e);
95         }
96     }
97     /** (non-Javadoc)
98      * @see org.apache.tools.ant.Task#execute()
99      */

100     public void execute() throws BuildException {
101         try {
102             log("document-id corresponding to the node: " + getDocumentid());
103             log("area: " + getArea());
104             deleteNode(getDocumentid(), getArea());
105         } catch (Exception JavaDoc e) {
106             throw new BuildException(e);
107         }
108     }
109 }
110
Popular Tags