Source Code Cross Referenced for DefaultDocumentIdToPathMapper.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » publication » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.lenya.cms.publication 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.lenya.cms.publication;
020:
021:        import java.io.File;
022:
023:        /**
024:         * Default DocumentIdToPathMapper implementation.
025:         * 
026:         * @version $Id: DefaultDocumentIdToPathMapper.java 473861 2006-11-12 03:51:14Z gregor $
027:         */
028:        public class DefaultDocumentIdToPathMapper implements 
029:                DocumentIdToPathMapper, PathToDocumentIdMapper {
030:
031:            /**
032:             * The file name.
033:             */
034:            public static final String BASE_FILENAME_PREFIX = "index";
035:
036:            /**
037:             * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication,
038:             *      java.lang.String, java.lang.String, java.lang.String)
039:             */
040:            public File getFile(Publication publication, String area,
041:                    String uuid, String language) {
042:                File file = new File(getDirectory(publication, area), getPath(
043:                        uuid, language));
044:                return file;
045:            }
046:
047:            protected File getDirectory(Publication publication, String area) {
048:
049:                File file = new File(publication.getDirectory(),
050:                        Publication.CONTENT_PATH + File.separator + area);
051:
052:                return file;
053:            }
054:
055:            /**
056:             * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getPath(java.lang.String,
057:             *      java.lang.String)
058:             */
059:            public String getPath(String uuid, String language) {
060:                if (uuid.startsWith("/")) {
061:                    return uuid.substring(1) + "/" + getFilename(language);
062:                } else {
063:                    return uuid + "/" + language;
064:                }
065:            }
066:
067:            /**
068:             * Constructs the filename for a given language.
069:             * 
070:             * @param language The language.
071:             * @return A string value.
072:             */
073:            protected String getFilename(String language) {
074:                String languageSuffix = "";
075:                if (language != null && !"".equals(language)) {
076:                    languageSuffix = "_" + language;
077:                }
078:                return BASE_FILENAME_PREFIX + languageSuffix;
079:            }
080:
081:            /**
082:             * Returns the document ID for a certain file.
083:             * @param publication The publication.
084:             * @param area The area.
085:             * @param file The file representing the document.
086:             * @return A string.
087:             * @throws DocumentDoesNotExistException when the document referenced by the file does not
088:             *             exist.
089:             */
090:            public String getDocumentId(Publication publication, String area,
091:                    File file) throws DocumentDoesNotExistException {
092:
093:                String fileName = file.getAbsolutePath();
094:                String contentDirName = publication.getContentDirectory(area)
095:                        .getAbsolutePath();
096:                if (fileName.startsWith(contentDirName)) {
097:                    // trim everything up to the documentId
098:                    String relativeFileName = fileName.substring(contentDirName
099:                            .length());
100:                    // trim everything after the documentId
101:                    relativeFileName = relativeFileName.substring(0,
102:                            relativeFileName.lastIndexOf(File.separator));
103:                    // and replace the os specific separator by '/'
104:                    return relativeFileName.replace(File.separatorChar, '/');
105:                }
106:                // Document does not seem to exist
107:                throw new DocumentDoesNotExistException(
108:                        "No document associated with file" + fileName);
109:            }
110:
111:            /**
112:             * Returns the language for a certain file
113:             * 
114:             * @param file the document file
115:             * 
116:             * @return the language for the given document file or null if the file has no language.
117:             */
118:            public String getLanguage(File file) {
119:                String fileName = file.getName();
120:                String language = null;
121:
122:                int lastDotIndex = fileName.lastIndexOf(".");
123:                String suffix = fileName.substring(lastDotIndex);
124:
125:                // check if the file is of the form index.html or index_en.html
126:
127:                if (fileName.startsWith(BASE_FILENAME_PREFIX)
128:                        && fileName.endsWith(suffix)) {
129:                    String languageSuffix = fileName.substring(
130:                            BASE_FILENAME_PREFIX.length(), fileName
131:                                    .indexOf(suffix));
132:                    if (languageSuffix.length() > 0) {
133:                        // trim the leading '_'
134:                        language = languageSuffix.substring(1);
135:                    }
136:                }
137:                return language;
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.