KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentIdToFile.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.DocumentIdToPathMapper;
23 import org.apache.lenya.cms.publication.Publication;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Target;
27
28 /**
29  * Ant task to get the file from the document-id.
30  *
31  * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(Publication publication, String area, String documentId, String language)
32  */

33 public class DocumentIdToFile extends PublicationTask {
34     private String JavaDoc area;
35     private String JavaDoc documentId;
36     private String JavaDoc language;
37     private String JavaDoc propertyname;
38
39     /**
40      * Creates a new instance of DocumentIdToPath.
41      */

42     public DocumentIdToFile() {
43         super();
44     }
45
46     /**
47      * Get the area.
48      *
49      * @return The directory for the area in the publication.
50      */

51     public String JavaDoc getArea() {
52         return area;
53     }
54
55     /**
56      * Get the document-id.
57      *
58      * @return The document id
59      */

60     protected String JavaDoc getDocumentid() {
61         return documentId;
62     }
63
64     /**
65      * Get the property name.
66      *
67      * @return The name of the property for the path.
68      */

69     public String JavaDoc getPropertyname() {
70         return propertyname;
71     }
72
73     /**
74      * Set the area.
75      *
76      * @param area The area.
77      */

78     public void setArea(String JavaDoc area) {
79         this.area = area;
80     }
81
82     /**
83      * Set the property name
84      *
85      * @param string The name of the property.
86      */

87     public void setPropertyname(String JavaDoc string) {
88         propertyname = string;
89     }
90
91     /**
92      * Set the value of the document id
93      *
94      * @param documentId The document id.
95      */

96     public void setDocumentid(String JavaDoc documentId) {
97         this.documentId = documentId;
98     }
99
100     /**
101      * Get the language
102      *
103      * @return the language
104      */

105     public String JavaDoc getLanguage() {
106         return language;
107     }
108
109     /**
110      * Set the language
111      *
112      * @param language the language
113      */

114     public void setLanguage(String JavaDoc language) {
115         this.language = language;
116     }
117
118     /**
119      * Gets the path from the document id and sets this value in the
120      * property of the project with the name propertyname.
121     
122      * @param area The area (e.g. "authoring")
123      * @param documentid The document id.
124      * @param language the language of the document
125      * @param propertyname The name of the property
126      */

127     public void compute(
128         String JavaDoc area,
129         String JavaDoc documentid,
130         String JavaDoc language,
131         String JavaDoc propertyname) {
132
133         Publication publication = getPublication();
134         DocumentIdToPathMapper pathMapper = publication.getPathMapper();
135         String JavaDoc fileName =
136             pathMapper
137                 .getFile(publication, area, documentid, language)
138                 .getAbsolutePath();
139
140         Target target = getOwningTarget();
141         Project project = target.getProject();
142         project.setProperty(propertyname, fileName);
143     }
144
145     /**
146      * @see org.apache.tools.ant.Task#execute()
147      **/

148     public void execute() throws BuildException {
149         try {
150             log("document-id " + getDocumentid());
151             log("area " + getArea());
152             log("language " + getLanguage());
153             log("property: " + getPropertyname());
154             compute(
155                 getArea(),
156                 getDocumentid(),
157                 getLanguage(),
158                 getPropertyname());
159         } catch (Exception JavaDoc e) {
160             throw new BuildException(e);
161         }
162     }
163 }
164
Popular Tags