KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentIdToPath.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 directory path of the xml files of a document with document id.
30  * The path is given from the {area} directory.
31  */

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

40     public DocumentIdToPath() {
41         super();
42     }
43
44     /**
45      * @return Sting The area.
46      */

47     public String JavaDoc getArea() {
48         return area;
49     }
50
51     /**
52      * @return string The document id
53      */

54     protected String JavaDoc getDocumentid() {
55         return documentid;
56     }
57
58     /**
59      * @return propertyname. The name of the property for the directory path.
60      */

61     public String JavaDoc getPropertyname() {
62         return propertyname;
63     }
64
65     /**
66      * @param string The area.
67      */

68     public void setArea(String JavaDoc string) {
69         area = string;
70     }
71
72     /**
73      * @param string The name of the property.
74      */

75     public void setPropertyname(String JavaDoc string) {
76         propertyname = string;
77     }
78
79     /**
80      * Set the value of the document id.
81      *
82      * @param string The document id.
83      */

84     public void setDocumentid(String JavaDoc string) {
85         documentid = string;
86     }
87
88     /**
89      * Gets the directory path from the document id and sets this value in the
90      * property of the project with the name propertyname.
91     
92      * @param area The area (ex authoring)
93      * @param documentid The document id.
94      * @param propertyname The name of the property
95      */

96     public void compute(String JavaDoc area, String JavaDoc documentid, String JavaDoc propertyname) {
97
98         Publication publication = getPublication();
99         DocumentIdToPathMapper pathMapper = publication.getPathMapper();
100         String JavaDoc path = pathMapper.getPath(documentid, "");
101         log("path " + path);
102
103         int index = path.lastIndexOf("/");
104         String JavaDoc dir = path.substring(0, index);
105         log("dir " + dir);
106
107         Target target = getOwningTarget();
108         Project project = target.getProject();
109         project.setProperty(propertyname, dir);
110     }
111
112     /**
113      * @see org.apache.tools.ant.Task#execute()
114      **/

115     public void execute() throws BuildException {
116         log("document-id " + getDocumentid());
117         log("area " + getArea());
118         log("property: " + getPropertyname());
119         compute(getArea(), getDocumentid(), getPropertyname());
120     }
121
122 }
123
Popular Tags