KickJava   Java API By Example, From Geeks To Geeks.

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


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: ComputeNewDocumentId.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.Publication;
23 import org.apache.lenya.cms.publication.UniqueDocumentId;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Target;
27
28
29 /**
30  * Ant task to set the property "newdocumentid" in the project with the
31  * value of computed unique document id, needed for the destination file
32  * Overriden for copy/move/rename.
33  * @param area The area in which is the sitetree.
34  * @param firstdocumentid The document id of the source
35  * @param secdocumentid The document id of the parent of the destination
36  * or in case of rename the new name
37  */

38 public class ComputeNewDocumentId extends PublicationTask{
39     private String JavaDoc area;
40     private String JavaDoc firstdocumentid;
41     private String JavaDoc secdocumentid;
42
43     /**
44      * Creates a new instance of ComputeNewDocumentId
45      */

46     public ComputeNewDocumentId() {
47         super();
48     }
49
50     /**
51      * @return string The area in which is the sitetree.
52      */

53     public String JavaDoc getArea() {
54         return area;
55     }
56
57     /**
58      * set the value of the area in which is the sitetree
59      * @param string The area of the sitetree.
60      */

61     public void setArea(String JavaDoc string) {
62         area = string;
63     }
64
65     /**
66      * @return string The document id of the source
67      */

68     protected String JavaDoc getFirstdocumentid() {
69         return firstdocumentid;
70     }
71
72     /**
73      * set the value of the document id of the source
74      * @param string The document id of the source
75      */

76     public void setFirstdocumentid(String JavaDoc string) {
77         firstdocumentid = string;
78     }
79
80     /**
81      * @return string The document id of the parent of the destination
82      * or the new name in case of rename
83      */

84     protected String JavaDoc getSecdocumentid() {
85         return secdocumentid;
86     }
87
88     /**
89      * @param string The document id of the parent of the destination
90      * or the new name in case of rename
91      */

92     public void setSecdocumentid(String JavaDoc string) {
93         secdocumentid = string;
94     }
95
96     /**
97      * Method to be overriden to compute the document id of the destination.
98      * @param firstdocumentid The document id of the source.
99      * @param secdocumentid Some string to characterize the destination (ex
100      * document id of parent, new name).
101      * @return string. The new document id
102      */

103     protected String JavaDoc compute(String JavaDoc firstdocumentid, String JavaDoc secdocumentid) {
104         return secdocumentid;
105     }
106
107     /**
108      * Compute the unique document id: append a "_version number" to the id,
109      * if there is already a node in the sitetree with this id.
110      * @param documentid The document id.
111      * @param area The area in which is the sitetree.
112      * @return newdocumentid The unique document id.
113      */

114     protected String JavaDoc computeUniqueId(String JavaDoc documentid, String JavaDoc area) {
115
116         Publication publication = getPublication();
117
118         UniqueDocumentId uniqueDocumentId = new UniqueDocumentId();
119         String JavaDoc newdocumentid = uniqueDocumentId.computeUniqueDocumentId(publication, area, documentid);
120         return newdocumentid;
121
122     }
123
124     /**
125      * Set the property node.newdocumentid for the project
126      * @param documentid The new document id.
127      */

128     protected void setNewProperty(String JavaDoc documentid) {
129         Target target = getOwningTarget();
130         Project project = target.getProject();
131         project.setProperty("node.newdocumentid", documentid);
132     }
133
134     /**
135      * @see org.apache.tools.ant.Task#execute()
136      **/

137     public void execute() throws BuildException {
138         try {
139             log("document id of the source" + getFirstdocumentid());
140             log("document id of the destination" + getSecdocumentid());
141             log("area: " + getArea());
142             String JavaDoc documentId = compute(getFirstdocumentid(), getSecdocumentid());
143             String JavaDoc uniqueId = computeUniqueId(documentId, getArea());
144             setNewProperty(uniqueId);
145         } catch (Exception JavaDoc e) {
146             throw new BuildException(e);
147         }
148     }
149 }
150
Popular Tags