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.plugin;
16  
17  import com.liferay.portal.SystemException;
18  import com.liferay.portal.model.Plugin;
19  import com.liferay.portal.model.PluginSetting;
20  import com.liferay.portal.model.User;
21  import com.liferay.portal.service.PluginSettingLocalServiceUtil;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * <a href="PluginUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class PluginUtil {
32  
33      public static List<? extends Plugin> restrictPlugins(
34              List<? extends Plugin> plugins, long companyId, long userId)
35          throws SystemException {
36  
37          List<Plugin> visiblePlugins = new ArrayList<Plugin>(plugins.size());
38  
39          for (Plugin plugin : plugins) {
40              PluginSetting pluginSetting =
41                  PluginSettingLocalServiceUtil.getPluginSetting(
42                      companyId, plugin.getPluginId(), plugin.getPluginType());
43  
44              if (pluginSetting.isActive() &&
45                  pluginSetting.hasPermission(userId)) {
46  
47                  visiblePlugins.add(plugin);
48              }
49          }
50  
51          return visiblePlugins;
52      }
53  
54      public static List<? extends Plugin> restrictPlugins(
55              List<? extends Plugin> plugins, User user)
56          throws SystemException {
57  
58          return restrictPlugins(plugins, user.getCompanyId(), user.getUserId());
59      }
60  
61  }