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.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                    else {
036                            ServletContextPool.remove(servletContextName);
037    
038                            themeLoader.destroy();
039    
040                            return true;
041                    }
042            }
043    
044            public static ThemeLoader getDefaultThemeLoader() {
045                    ThemeLoader themeLoader = null;
046    
047                    for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
048                            themeLoader = entry.getValue();
049    
050                            break;
051                    }
052    
053                    return themeLoader;
054            }
055    
056            public static ThemeLoader getThemeLoader(String servletContextName) {
057                    return _themeLoaders.get(servletContextName);
058            }
059    
060            public static void init(
061                    String servletContextName, ServletContext servletContext,
062                    String[] xmls) {
063    
064                    ServletContextPool.put(servletContextName, servletContext);
065    
066                    ThemeLoader themeLoader = new ThemeLoader(
067                            servletContextName, servletContext, xmls);
068    
069                    _themeLoaders.put(servletContextName, themeLoader);
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    }