KickJava   Java API By Example, From Geeks To Geeks.

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


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: DeleteLanguageNodeTask.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.SiteTree;
23 import org.apache.lenya.cms.publication.Label;
24 import org.apache.lenya.cms.publication.SiteTreeException;
25 import org.apache.lenya.cms.publication.SiteTreeNode;
26 import org.apache.tools.ant.BuildException;
27
28 /**
29  * Ant task to remove the language from the node corresponding to the document
30  * with document id <documentid> and area <area>. The node is also deleted if no
31  * other language is available.
32  */

33 public class DeleteLanguageNodeTask extends DeleteNodeTask {
34     private String JavaDoc language;
35
36     /**
37      * Creates a new instance of DeleteLanguageNodeTask
38      */

39     public DeleteLanguageNodeTask() {
40         super();
41     }
42
43     /**
44      * Remove the language from the node corresponding to the document
45      * with document id <documentid> and area <area>. When no more language
46      * is available, then the node will be deleted fom the tree.
47      *
48      * @param language The language of the document.
49      * @param documentid The id of the document.
50      * @param area The area of the document.
51      *
52      * @throws SiteTreeException if an error occurs
53      */

54     public void deleteLanguageNode(String JavaDoc language, String JavaDoc documentid, String JavaDoc area)
55         throws SiteTreeException {
56         SiteTree tree = null;
57
58         try {
59             tree = getPublication().getTree(area);
60             SiteTreeNode node = tree.getNode(documentid);
61             node.removeLabel(node.getLabel(language));
62             Label[] labels = node.getLabels();
63             if (labels.length < 1 ){
64                 deleteNode(documentid,area);
65             } else {
66                 tree.save();
67             }
68         } catch (Exception JavaDoc e) {
69             throw new SiteTreeException(e);
70         }
71     }
72     /** (non-Javadoc)
73      * @see org.apache.tools.ant.Task#execute()
74      */

75     public void execute() throws BuildException {
76         try {
77             log("document-id : " + getDocumentid());
78             log("area: " + getArea());
79             log("language : " + getLanguage());
80             deleteLanguageNode(getLanguage(), getDocumentid(), getArea());
81         } catch (Exception JavaDoc e) {
82             throw new BuildException(e);
83         }
84     }
85
86     /**
87      * Get the value of the language to be removed.
88      *
89      * @return The language
90      */

91     public String JavaDoc getLanguage() {
92         return language;
93     }
94
95     /**
96      * Set the value of the language to be removed.
97      *
98      * @param string The language.
99      */

100     public void setLanguage(String JavaDoc string) {
101         language = string;
102     }
103
104 }
105
Popular Tags