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.theme;
016    
017    import com.liferay.portal.kernel.servlet.ServletContextPool;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import javax.servlet.ServletContext;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class ThemeLoaderFactory {
028    
029            public static boolean destroy(String servletContextName) {
030                    ThemeLoader themeLoader = _themeLoaders.remove(servletContextName);
031    
032                    if (themeLoader == null) {
033                            return false;
034                    }
035    
036                    ServletContextPool.remove(servletContextName);
037    
038                    themeLoader.destroy();
039    
040                    return true;
041            }
042    
043            public static ThemeLoader getDefaultThemeLoader() {
044                    ThemeLoader themeLoader = null;
045    
046                    for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
047                            themeLoader = entry.getValue();
048    
049                            break;
050                    }
051    
052                    return themeLoader;
053            }
054    
055            public static ThemeLoader getThemeLoader(String servletContextName) {
056                    return _themeLoaders.get(servletContextName);
057            }
058    
059            public static void init(
060                    String servletContextName, ServletContext servletContext,
061                    String[] xmls) {
062    
063                    ServletContextPool.put(servletContextName, servletContext);
064    
065                    ThemeLoader themeLoader = new ThemeLoader(
066                            servletContextName, servletContext, xmls);
067    
068                    _themeLoaders.put(servletContextName, themeLoader);
069            }
070    
071            public static void loadThemes() {
072                    for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
073                            ThemeLoader themeLoader = entry.getValue();
074    
075                            themeLoader.loadThemes();
076                    }
077            }
078    
079            private static Map<String, ThemeLoader> _themeLoaders =
080                    new HashMap<String, ThemeLoader>();
081    
082    }