KickJava   Java API By Example, From Geeks To Geeks.

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


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: InsertLabelTask.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.tools.ant.BuildException;
26
27 /**
28  * Ant task to insert a label into an existing node in a tree.
29  */

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

39     public InsertLabelTask() {
40         super();
41     }
42
43     /**
44      * Get the area of the site tree.
45      *
46      * @return the area of the tree.
47      */

48     protected String JavaDoc getArea() {
49         return area;
50     }
51
52     /**
53      * Set the area of the site tree
54      *
55      * @param area the area of the tree.
56      */

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

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

75     public void setDocumentid(String JavaDoc string) {
76         documentid = string;
77     }
78
79     /**
80      * Get the name of the label.
81      *
82      * @return the labelName
83      */

84     public String JavaDoc getLabelName() {
85         return labelName;
86     }
87
88     /**
89      * Set the labelName.
90      *
91      * @param labelName the name of the label
92      */

93     public void setLabelName(String JavaDoc labelName) {
94         this.labelName = labelName;
95     }
96
97     /**
98      * Get the language.
99      *
100      * @return the language
101      */

102     public String JavaDoc getLanguage() {
103         return language;
104     }
105
106     /**
107      * Set the language.
108      *
109      * @param language the language
110      */

111     public void setLanguage(String JavaDoc language) {
112         this.language = language;
113     }
114
115     /**
116      * Insert a label in an existing node in the tree.
117      *
118      * @param documentid the document-id of the document.
119      * @param labelName the name of the label that is to be inserted.
120      * @param language the language of the label that is to be inserted.
121      * @param area determines in which sitetree the label is to be inserted
122      *
123      * @throws SiteTreeException if an error occurs
124      */

125     public void insertLabel(
126         String JavaDoc documentid,
127         String JavaDoc labelName,
128         String JavaDoc language,
129         String JavaDoc area)
130         throws SiteTreeException {
131
132         SiteTree tree = null;
133         Label label = null;
134         try {
135             tree = getPublication().getTree(area);
136             label = new Label(labelName, language);
137             tree.addLabel(documentid, label);
138             tree.save();
139         } catch (Exception JavaDoc e) {
140             throw new SiteTreeException(
141                 "Cannot insert label "
142                     + label
143                     + " into tree "
144                     + area,
145                 e);
146         }
147
148     }
149
150     /** (non-Javadoc)
151      * @see org.apache.tools.ant.Task#execute()
152      */

153     public void execute() throws BuildException {
154         try {
155             log("document-id corresponding to the node: " + getDocumentid());
156             log("label name: " + getLabelName());
157             log("language: " + getLanguage());
158             log("area: " + getArea());
159             insertLabel(
160                 getDocumentid(),
161                 getLabelName(),
162                 getLanguage(),
163                 getArea());
164         } catch (Exception JavaDoc e) {
165             throw new BuildException(e);
166         }
167     }
168 }
169
Popular Tags