1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.theme;
16  
17  import com.liferay.portal.velocity.VelocityContextPool;
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          VelocityContextPool.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              VelocityContextPool.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  }