001    /**
002     * Copyright (c) 2000-2013 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.security.pacl.DoPrivileged;
018    import com.liferay.portal.kernel.util.CharPool;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    
022    import java.util.Map;
023    import java.util.Set;
024    import java.util.concurrent.ConcurrentHashMap;
025    
026    /**
027     * @author Ryan Park
028     * @author Brian Wing Shun Chan
029     */
030    @DoPrivileged
031    public class CustomJspRegistryImpl implements CustomJspRegistry {
032    
033            public CustomJspRegistryImpl() {
034                    _servletContextNames = new ConcurrentHashMap<String, String>();
035            }
036    
037            @Override
038            public String getCustomJspFileName(
039                    String servletContextName, String fileName) {
040    
041                    int pos = fileName.lastIndexOf(CharPool.PERIOD);
042    
043                    if (pos == -1) {
044                            return fileName.concat(StringPool.PERIOD).concat(
045                                    servletContextName);
046                    }
047    
048                    StringBundler sb = new StringBundler(4);
049    
050                    sb.append(fileName.substring(0, pos));
051                    sb.append(CharPool.PERIOD);
052                    sb.append(servletContextName);
053                    sb.append(fileName.substring(pos));
054    
055                    return sb.toString();
056            }
057    
058            @Override
059            public String getDisplayName(String servletContextName) {
060                    return _servletContextNames.get(servletContextName);
061            }
062    
063            @Override
064            public Set<String> getServletContextNames() {
065                    return _servletContextNames.keySet();
066            }
067    
068            @Override
069            public void registerServletContextName(
070                    String servletContextName, String displayName) {
071    
072                    _servletContextNames.put(servletContextName, displayName);
073            }
074    
075            @Override
076            public void unregisterServletContextName(String servletContextName) {
077                    _servletContextNames.remove(servletContextName);
078            }
079    
080            private Map<String, String> _servletContextNames;
081    
082    }