KickJava   Java API By Example, From Geeks To Geeks.

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


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: ComputeRenameDocumentId.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.util.StringTokenizer JavaDoc;
23
24 /**
25  * Sets the property "newdocumentid" in the project to the value of the computed
26  * unique document id (document id of the source with the latest token
27  * replaced by the new name
28  * Used by Rename
29  */

30 public class ComputeRenameDocumentId extends ComputeNewDocumentId {
31
32     /**
33      * Creates a new instance of ComputeRenameDocumentId
34      */

35     public ComputeRenameDocumentId() {
36         super();
37     }
38
39     /**
40      * Computes the document id for the destination (renamed file):
41      * new documentid = document id of the source, with the latest token
42      * replaced by the new name
43      * @param firstdocumentid The document id of the source.
44      * @param secdocumentid The new name.
45      * @return String The document id of the destination.
46      */

47     protected String JavaDoc compute(String JavaDoc firstdocumentid, String JavaDoc secdocumentid) {
48         String JavaDoc documentid= "";
49         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(firstdocumentid, "/");
50         int l = st.countTokens();
51         for (int i = 0; i < l-1; i++) {
52             documentid = documentid + "/" + st.nextToken();
53         }
54         secdocumentid = documentid + "/" + secdocumentid;
55         return secdocumentid;
56     }
57
58 }
59
Popular Tags