1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.theme;
16  
17  import com.liferay.portal.kernel.servlet.ServletContextPool;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.servlet.ServletContext;
23  
24  /**
25   * <a href="ThemeLoaderFactory.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class ThemeLoaderFactory {
30  
31      public static void init(
32          String servletContextName, ServletContext servletContext,
33          String[] xmls) {
34  
35          ServletContextPool.put(servletContextName, servletContext);
36  
37          ThemeLoader themeLoader = new ThemeLoader(
38              servletContextName, servletContext, xmls);
39  
40          _themeLoaders.put(servletContextName, themeLoader);
41      }
42  
43      public static boolean destroy(String servletContextName) {
44          ThemeLoader themeLoader = _themeLoaders.remove(servletContextName);
45  
46          if (themeLoader == null) {
47              return false;
48          }
49          else {
50              ServletContextPool.remove(servletContextName);
51  
52              themeLoader.destroy();
53  
54              return true;
55          }
56      }
57  
58      public static ThemeLoader getDefaultThemeLoader() {
59          ThemeLoader themeLoader = null;
60  
61          for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
62              themeLoader = entry.getValue();
63  
64              break;
65          }
66  
67          return themeLoader;
68      }
69  
70      public static ThemeLoader getThemeLoader(String servletContextName) {
71          return _themeLoaders.get(servletContextName);
72      }
73  
74      public static void loadThemes() {
75          for (Map.Entry<String, ThemeLoader> entry : _themeLoaders.entrySet()) {
76              ThemeLoader themeLoader = entry.getValue();
77  
78              themeLoader.loadThemes();
79          }
80      }
81  
82      private static Map<String, ThemeLoader> _themeLoaders =
83          new HashMap<String, ThemeLoader>();
84  
85  }