KickJava   Java API By Example, From Geeks To Geeks.

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


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: WriteDCParametersTask.java 42616 2004-03-03 12:56:33Z gregor $ */
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.DocumentException;
26 import org.apache.lenya.cms.publication.DublinCore;
27 import org.apache.tools.ant.BuildException;
28
29 /**
30  * Ant task to insert a label into an existing node in a tree.
31  */

32 public class WriteDCParametersTask extends PublicationTask {
33     private String JavaDoc documentId = null;
34     private String JavaDoc area = null;
35     private String JavaDoc creator = null;
36     private String JavaDoc title = null;
37     private String JavaDoc description = null;
38     private String JavaDoc subject = null;
39     private String JavaDoc language = null;
40     private String JavaDoc publisher = null;
41     private String JavaDoc rights = null;
42  
43     /**
44      * Creates a new instance of InsertLabelTask
45      */

46     public WriteDCParametersTask() {
47         super();
48     }
49
50     /**
51      * Get the creator
52      *
53      * @return the creator
54      */

55     public String JavaDoc getCreator() {
56         return creator;
57     }
58
59     /**
60      * Get the description
61      *
62      * @return the description
63      */

64     public String JavaDoc getDescription() {
65         return description;
66     }
67
68     /**
69      * Get the publisher
70      *
71      * @return the publisher
72      */

73     public String JavaDoc getPublisher() {
74         return publisher;
75     }
76
77     /**
78      * Get the rights
79      *
80      * @return the rights
81      */

82     public String JavaDoc getRights() {
83         return rights;
84     }
85
86     /**
87      * Get the subject
88      *
89      * @return the subject
90      */

91     public String JavaDoc getSubject() {
92         return subject;
93     }
94
95     /**
96      * Get the title
97      *
98      * @return the title
99      */

100     public String JavaDoc getTitle() {
101         return title;
102     }
103
104     /**
105      * Set the creator.
106      *
107      * @param string the creator
108      */

109     public void setCreator(String JavaDoc string) {
110         creator = string;
111     }
112
113     /**
114      * Set the description
115      *
116      * @param string the description
117      */

118     public void setDescription(String JavaDoc string) {
119         description = string;
120     }
121
122     /**
123      * Set the publisher.
124      *
125      * @param string the publisher
126      */

127     public void setPublisher(String JavaDoc string) {
128         publisher = string;
129     }
130
131     /**
132      * Set the rights
133      *
134      * @param string the rights
135      */

136     public void setRights(String JavaDoc string) {
137         rights = string;
138     }
139
140     /**
141      * Set the subject
142      *
143      * @param string the subject
144      */

145     public void setSubject(String JavaDoc string) {
146         subject = string;
147     }
148
149     /**
150      * Set the title
151      *
152      * @param string the title
153      */

154     public void setTitle(String JavaDoc string) {
155         title = string;
156     }
157
158     /**
159      * Get the area
160      *
161      * @return the area
162      */

163     public String JavaDoc getArea() {
164         return area;
165     }
166
167     /**
168      * Set the area
169      *
170      * @param string the area
171      */

172     public void setArea(String JavaDoc string) {
173         area = string;
174     }
175
176     /**
177      * Get the document-id
178      *
179      * @return the document-id
180      */

181     public String JavaDoc getDocumentId() {
182         return documentId;
183     }
184
185     /**
186      * Set the document-id
187      *
188      * @param string the document-id
189      */

190     public void setDocumentId(String JavaDoc string) {
191         documentId = string;
192     }
193
194     /**
195      * Get the language
196      *
197      * @return the language
198      */

199     public String JavaDoc getLanguage() {
200         return language;
201     }
202
203     /**
204      * Set the language.
205      *
206      * @param string the language
207      */

208     public void setLanguage(String JavaDoc string) {
209         language = string;
210     }
211
212     /**
213      * Write the dublin core params.
214      *
215      * @param documentId the document-id
216      * @param area the area
217      * @param lang the language
218      * @param creator the creator.
219      * @param title the title
220      * @param description the description
221      * @param subject the subject
222      * @param publisher the publisher
223      * @param rights the rights
224      *
225      * @throws BuildException if an error occurs
226      * @throws DocumentBuildException if an error occurs
227      * @throws DocumentException if an error occurs
228      */

229     public void writeDublinCoreParameters(
230         String JavaDoc documentId,
231         String JavaDoc area,
232         String JavaDoc lang,
233         String JavaDoc creator,
234         String JavaDoc title,
235         String JavaDoc description,
236         String JavaDoc subject,
237         String JavaDoc publisher,
238         String JavaDoc rights)
239         throws BuildException, DocumentBuildException, DocumentException {
240
241         DocumentBuilder builder = getPublication().getDocumentBuilder();
242         String JavaDoc url = builder.buildCanonicalUrl(getPublication(), area, documentId, lang);
243         Document doc = builder.buildDocument(getPublication(), url);
244         DublinCore dc = doc.getDublinCore();
245         dc.setValue(DublinCore.ELEMENT_CREATOR, creator);
246         dc.setValue(DublinCore.ELEMENT_TITLE, title);
247         dc.setValue(DublinCore.ELEMENT_DESCRIPTION, description);
248         dc.setValue(DublinCore.ELEMENT_SUBJECT, subject);
249         dc.setValue(DublinCore.ELEMENT_PUBLISHER, publisher);
250         dc.setValue(DublinCore.ELEMENT_RIGHTS, rights);
251         dc.save();
252     }
253
254     /** (non-Javadoc)
255      * @see org.apache.tools.ant.Task#execute()
256      */

257     public void execute() throws BuildException {
258         try {
259             writeDublinCoreParameters(
260                 getDocumentId(),
261                 getArea(),
262                 getLanguage(),
263                 getCreator(),
264                 getTitle(),
265                 getDescription(),
266                 getSubject(),
267                 getPublisher(),
268                 getRights());
269             } catch (
270                 Exception JavaDoc e) {
271             throw new BuildException(e);
272         }
273     }
274
275 }
276
Popular Tags