1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet;
21  
22  import com.liferay.portal.model.PortletApp;
23  
24  import java.util.Map;
25  import java.util.concurrent.ConcurrentHashMap;
26  
27  import javax.portlet.PortletContext;
28  import javax.portlet.filter.FilterConfig;
29  
30  /**
31   * <a href="FilterConfigFactory.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   *
35   */
36  public class FilterConfigFactory {
37  
38      public static FilterConfig create(
39          com.liferay.portal.model.PortletFilter portletFilter,
40          PortletContext ctx) {
41  
42          return _instance._create(portletFilter, ctx);
43      }
44  
45      public static void destroy(
46          com.liferay.portal.model.PortletFilter portletFilter) {
47  
48          _instance._destroy(portletFilter);
49      }
50  
51      private FilterConfigFactory() {
52          _pool = new ConcurrentHashMap<String, Map<String, FilterConfig>>();
53      }
54  
55      private FilterConfig _create(
56          com.liferay.portal.model.PortletFilter portletFilter,
57          PortletContext ctx) {
58  
59          PortletApp portletApp = portletFilter.getPortletApp();
60  
61          Map<String, FilterConfig> filterConfigs =
62              _pool.get(portletApp.getServletContextName());
63  
64          if (filterConfigs == null) {
65              filterConfigs = new ConcurrentHashMap<String, FilterConfig>();
66  
67              _pool.put(portletApp.getServletContextName(), filterConfigs);
68          }
69  
70          FilterConfig filterConfig = filterConfigs.get(
71              portletFilter.getFilterName());
72  
73          if (filterConfig == null) {
74              filterConfig = new FilterConfigImpl(
75                  portletFilter.getFilterName(), ctx,
76                  portletFilter.getInitParams());
77  
78              filterConfigs.put(portletFilter.getFilterName(), filterConfig);
79          }
80  
81          return filterConfig;
82      }
83  
84      private void _destroy(
85          com.liferay.portal.model.PortletFilter portletFilter) {
86  
87          PortletApp portletApp = portletFilter.getPortletApp();
88  
89          _pool.remove(portletApp.getServletContextName());
90      }
91  
92      private static FilterConfigFactory _instance = new FilterConfigFactory();
93  
94      private Map<String, Map<String, FilterConfig>> _pool;
95  
96  }