01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: IdentityDocumentIdToPathMapper.java 479620 2006-11-27 14:02:13Z andreas $ */
20:
21: package org.apache.lenya.cms.publication;
22:
23: import java.io.File;
24:
25: /**
26: * Identity Document Id to path mapper
27: */
28: public class IdentityDocumentIdToPathMapper implements
29: DocumentIdToPathMapper {
30:
31: /**
32: * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication,
33: * java.lang.String, java.lang.String, java.lang.String)
34: */
35: public File getFile(Publication publication, String area,
36: String documentId, String language) {
37: File areaDirectory = new File(publication.getDirectory(),
38: Publication.CONTENT_PATH + File.separator + area);
39: File file = new File(areaDirectory, getPath(documentId,
40: language));
41: return file;
42: }
43:
44: /**
45: * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getPath(java.lang.String,
46: * java.lang.String)
47: */
48: public String getPath(String documentId, String language) {
49: assert documentId.startsWith("/");
50: // remove leading slash
51: documentId = documentId.substring(1);
52: return documentId + getSuffix(language);
53: }
54:
55: /**
56: * Constructs the filename for a given language.
57: * @param language The language.
58: * @return A string value.
59: */
60: protected String getSuffix(String language) {
61: String languageSuffix = "";
62: if (language != null && !"".equals(language)) {
63: languageSuffix = "_" + language;
64: }
65: return languageSuffix;
66: }
67:
68: }
|