KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > IdentityDocumentIdToPathMapper


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: IdentityDocumentIdToPathMapper.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import java.io.File JavaDoc;
23
24 public class IdentityDocumentIdToPathMapper implements DocumentIdToPathMapper {
25
26     /**
27      * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String, java.lang.String)
28      */

29     public File JavaDoc getFile(Publication publication, String JavaDoc area, String JavaDoc documentId, String JavaDoc language) {
30         File JavaDoc areaDirectory =
31             new File JavaDoc(publication.getDirectory(), Publication.CONTENT_PATH + File.separator + area);
32         File JavaDoc file = new File JavaDoc(areaDirectory, getPath(documentId, language));
33         return file;
34     }
35
36     /**
37      * (non-Javadoc)
38      * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String)
39      */

40     public File JavaDoc getDirectory(Publication publication, String JavaDoc area, String JavaDoc documentId) {
41         return getFile(publication, area, documentId, null).getParentFile();
42     }
43
44     /**
45      * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getPath(java.lang.String, java.lang.String)
46      */

47     public String JavaDoc getPath(String JavaDoc documentId, String JavaDoc language) {
48         assert documentId.startsWith("/");
49         // remove leading slash
50
documentId = documentId.substring(1);
51         return documentId + getSuffix(language);
52     }
53
54     /**
55      * Constructs the filename for a given language.
56      * @param language The language.
57      * @return A string value.
58      */

59     protected String JavaDoc getSuffix(String JavaDoc language) {
60         String JavaDoc languageSuffix = "";
61         if (language != null && !"".equals(language)) {
62             languageSuffix = "_" + language;
63         }
64         return languageSuffix + ".xml";
65     }
66
67 }
68
Popular Tags