KickJava   Java API By Example, From Geeks To Geeks.

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


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: ComputeArchiveDocumentId.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 ArchivDocument
29  */

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

35     public ComputeArchiveDocumentId() {
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         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(firstdocumentid, "/");
49         int l = st.countTokens();
50         for (int i = 0; i < l-1; i++) {
51             st.nextToken();
52         }
53         secdocumentid = "/" + st.nextToken();
54         return secdocumentid;
55     }
56
57 }
58
Popular Tags