001    /**
002     * Copyright (c) 2000-2010 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 void init(
030                    String servletContextName, ServletContext servletContext,
031                    String[] xmls) {
032    
033                    ServletContextPool.put(servletContextName, servletContext);
034    
035                    ThemeLoader themeLoader = new ThemeLoader(
036                            servletContextName, servletContext, xmls);
037    
038                    _themeLoaders.put(servletContextName, themeLoader);
039            }
040    
041            public static boolean destroy(String servletContextName) {
042                    ThemeLoader themeLoader = _themeLoaders.remove(servletContextName);
043    
044                    if (themeLoader == null) {
045                            return false;
046                    }
047                    else {
048                            ServletContextPool.remove(servletContextName);
049    
050                            themeLoader.destroy();
051    
052                            return true;
053                    }
054            }
055    
056            public static ThemeLoader getDefaultThemeLoader() {
057                    ThemeLoader themeLoader = null;
058    
059                    for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
060                            themeLoader = entry.getValue();
061    
062                            break;
063                    }
064    
065                    return themeLoader;
066            }
067    
068            public static ThemeLoader getThemeLoader(String servletContextName) {
069                    return _themeLoaders.get(servletContextName);
070            }
071    
072            public static void loadThemes() {
073                    for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
074                            ThemeLoader themeLoader = entry.getValue();
075    
076                            themeLoader.loadThemes();
077                    }
078            }
079    
080            private static Map<String, ThemeLoader> _themeLoaders =
081                    new HashMap<String, ThemeLoader>();
082    
083    }