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.portlet;
16  
17  import com.liferay.portal.model.PortletApp;
18  
19  import java.util.Map;
20  import java.util.concurrent.ConcurrentHashMap;
21  
22  import javax.portlet.PortletContext;
23  import javax.portlet.filter.FilterConfig;
24  
25  /**
26   * <a href="FilterConfigFactory.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class FilterConfigFactory {
31  
32      public static FilterConfig create(
33          com.liferay.portal.model.PortletFilter portletFilter,
34          PortletContext ctx) {
35  
36          return _instance._create(portletFilter, ctx);
37      }
38  
39      public static void destroy(
40          com.liferay.portal.model.PortletFilter portletFilter) {
41  
42          _instance._destroy(portletFilter);
43      }
44  
45      private FilterConfigFactory() {
46          _pool = new ConcurrentHashMap<String, Map<String, FilterConfig>>();
47      }
48  
49      private FilterConfig _create(
50          com.liferay.portal.model.PortletFilter portletFilter,
51          PortletContext ctx) {
52  
53          PortletApp portletApp = portletFilter.getPortletApp();
54  
55          Map<String, FilterConfig> filterConfigs =
56              _pool.get(portletApp.getServletContextName());
57  
58          if (filterConfigs == null) {
59              filterConfigs = new ConcurrentHashMap<String, FilterConfig>();
60  
61              _pool.put(portletApp.getServletContextName(), filterConfigs);
62          }
63  
64          FilterConfig filterConfig = filterConfigs.get(
65              portletFilter.getFilterName());
66  
67          if (filterConfig == null) {
68              filterConfig = new FilterConfigImpl(
69                  portletFilter.getFilterName(), ctx,
70                  portletFilter.getInitParams());
71  
72              filterConfigs.put(portletFilter.getFilterName(), filterConfig);
73          }
74  
75          return filterConfig;
76      }
77  
78      private void _destroy(
79          com.liferay.portal.model.PortletFilter portletFilter) {
80  
81          PortletApp portletApp = portletFilter.getPortletApp();
82  
83          _pool.remove(portletApp.getServletContextName());
84      }
85  
86      private static FilterConfigFactory _instance = new FilterConfigFactory();
87  
88      private Map<String, Map<String, FilterConfig>> _pool;
89  
90  }