001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.util;
016    
017    import com.liferay.portal.kernel.util.CharPool;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.StringPool;
020    
021    import java.util.Map;
022    import java.util.Set;
023    import java.util.concurrent.ConcurrentHashMap;
024    
025    /**
026     * @author Ryan Park
027     * @author Brian Wing Shun Chan
028     */
029    public class CustomJspRegistryImpl implements CustomJspRegistry {
030    
031            public CustomJspRegistryImpl() {
032                    _servletContextNames = new ConcurrentHashMap<String, String>();
033            }
034    
035            public String getCustomJspFileName(
036                    String servletContextName, String fileName) {
037    
038                    int pos = fileName.lastIndexOf(CharPool.PERIOD);
039    
040                    if (pos == -1) {
041                            return fileName.concat(StringPool.PERIOD).concat(
042                                    servletContextName);
043                    }
044    
045                    StringBundler sb = new StringBundler(4);
046    
047                    sb.append(fileName.substring(0, pos));
048                    sb.append(CharPool.PERIOD);
049                    sb.append(servletContextName);
050                    sb.append(fileName.substring(pos));
051    
052                    return sb.toString();
053            }
054    
055            public String getDisplayName(String servletContextName) {
056                    return _servletContextNames.get(servletContextName);
057            }
058    
059            public Set<String> getServletContextNames() {
060                    return _servletContextNames.keySet();
061            }
062    
063            public void registerServletContextName(
064                    String servletContextName, String displayName) {
065    
066                    _servletContextNames.put(servletContextName, displayName);
067            }
068    
069            public void unregisterServletContextName(String servletContextName) {
070                    _servletContextNames.remove(servletContextName);
071            }
072    
073            private Map<String, String> _servletContextNames;
074    
075    }