001    /**
002     * Copyright (c) 2000-2012 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.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    }