KickJava   Java API By Example, From Geeks To Geeks.

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


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: ComputeCopyDocumentId.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 /**
26  * Sets the property "newdocumentid" in the project to the value of the computed
27  * unique document id (document id of the parent + last token of the id of
28  * the source)
29  * Used by Copy and Move
30  */

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

36     public ComputeCopyDocumentId() {
37         super();
38     }
39
40     /**
41      * Computes the document id for the destination:
42      * new documentid = document id of the parent + last token of the id
43      * of the source
44      * @param firstdocumentid The document id of the source.
45      * @param secdocumentid The document id of the parent of the destination.
46      * @return String The document id of the destination.
47      */

48     protected String JavaDoc compute(String JavaDoc firstdocumentid, String JavaDoc secdocumentid) {
49         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(firstdocumentid, "/");
50         int l = st.countTokens();
51
52         for (int i = 1; i < l; i++) {
53             st.nextToken();
54         }
55         if (secdocumentid.endsWith("/")) {
56             secdocumentid = secdocumentid + st.nextToken();
57         } else {
58             secdocumentid = secdocumentid + "/" + st.nextToken();
59         }
60         
61         return secdocumentid;
62     }
63
64 }
65
Popular Tags