001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            public String getCustomJspFileName(
038                    String servletContextName, String fileName) {
039    
040                    int pos = fileName.lastIndexOf(CharPool.PERIOD);
041    
042                    if (pos == -1) {
043                            return fileName.concat(StringPool.PERIOD).concat(
044                                    servletContextName);
045                    }
046    
047                    StringBundler sb = new StringBundler(4);
048    
049                    sb.append(fileName.substring(0, pos));
050                    sb.append(CharPool.PERIOD);
051                    sb.append(servletContextName);
052                    sb.append(fileName.substring(pos));
053    
054                    return sb.toString();
055            }
056    
057            public String getDisplayName(String servletContextName) {
058                    return _servletContextNames.get(servletContextName);
059            }
060    
061            public Set<String> getServletContextNames() {
062                    return _servletContextNames.keySet();
063            }
064    
065            public void registerServletContextName(
066                    String servletContextName, String displayName) {
067    
068                    _servletContextNames.put(servletContextName, displayName);
069            }
070    
071            public void unregisterServletContextName(String servletContextName) {
072                    _servletContextNames.remove(servletContextName);
073            }
074    
075            private Map<String, String> _servletContextNames;
076    
077    }