1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.bean.BeanLocatorUtil;
28  import com.liferay.portal.model.Layout;
29  import com.liferay.portal.model.Portlet;
30  import com.liferay.portal.model.PortletPreferencesIds;
31  
32  import javax.portlet.ActionRequest;
33  import javax.portlet.PortletPreferences;
34  import javax.portlet.PreferencesValidator;
35  import javax.portlet.RenderRequest;
36  
37  import javax.servlet.http.HttpServletRequest;
38  
39  /**
40   * <a href="PortletPreferencesFactoryUtil.java.html"><b><i>View Source</i></b>
41   * </a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class PortletPreferencesFactoryUtil {
47  
48      public static PortalPreferences getPortalPreferences(HttpServletRequest req)
49          throws PortalException, SystemException {
50  
51          return getPortletPreferencesFactory().getPortalPreferences(req);
52      }
53  
54      public static PortalPreferences getPortalPreferences(ActionRequest req)
55          throws PortalException, SystemException {
56  
57          return getPortletPreferencesFactory().getPortalPreferences(req);
58      }
59  
60      public static PortalPreferences getPortalPreferences(RenderRequest req)
61          throws PortalException, SystemException {
62  
63          return getPortletPreferencesFactory().getPortalPreferences(req);
64      }
65  
66      public static PortletPreferences getPortletPreferences(
67              HttpServletRequest req, String portletId)
68          throws PortalException, SystemException {
69  
70          return getPortletPreferencesFactory().getPortletPreferences(
71              req, portletId);
72      }
73  
74      public static PortletPreferencesFactory getPortletPreferencesFactory() {
75          return _getUtil()._portletPreferencesFactory;
76      }
77  
78      public static PortletPreferencesIds getPortletPreferencesIds(
79              HttpServletRequest req, String portletId)
80          throws PortalException, SystemException {
81  
82          return getPortletPreferencesFactory().getPortletPreferencesIds(
83              req, portletId);
84      }
85  
86      public static PortletPreferencesIds getPortletPreferencesIds(
87              HttpServletRequest req, Layout selLayout, String portletId)
88          throws PortalException, SystemException {
89  
90          return getPortletPreferencesFactory().getPortletPreferencesIds(
91              req, selLayout, portletId);
92      }
93  
94      public static PortletPreferences getPortletSetup(
95              Layout layout, String portletId)
96          throws PortalException, SystemException {
97  
98          return getPortletPreferencesFactory().getPortletSetup(
99              layout, portletId);
100     }
101 
102     public static PortletPreferences getPortletSetup(
103             HttpServletRequest req, String portletId, boolean uniquePerLayout,
104             boolean uniquePerGroup)
105         throws PortalException, SystemException {
106 
107         return getPortletPreferencesFactory().getPortletSetup(
108             req, portletId, uniquePerLayout, uniquePerGroup);
109     }
110 
111     public static PortletPreferences getPortletSetup(
112             HttpServletRequest req, String portletId, boolean uniquePerLayout,
113             boolean uniquePerGroup, String defaultPreferences)
114         throws PortalException, SystemException {
115 
116         return getPortletPreferencesFactory().getPortletSetup(
117             req, portletId, uniquePerLayout, uniquePerGroup,
118             defaultPreferences);
119     }
120 
121     public static PortletPreferences getPortletSetup(
122             Layout layout, String portletId, boolean uniquePerLayout,
123             boolean uniquePerGroup, String defaultPreferences)
124         throws PortalException, SystemException {
125 
126         return getPortletPreferencesFactory().getPortletSetup(
127             layout, portletId, uniquePerLayout, uniquePerGroup,
128             defaultPreferences);
129     }
130 
131     public static PortletPreferences getPortletSetup(
132             ActionRequest req, String portletId, boolean uniquePerLayout,
133             boolean uniquePerGroup)
134         throws PortalException, SystemException {
135 
136         return getPortletPreferencesFactory().getPortletSetup(
137             req, portletId, uniquePerLayout, uniquePerGroup);
138     }
139 
140     public static PortletPreferences getPortletSetup(
141             RenderRequest req, String portletId, boolean uniquePerLayout,
142             boolean uniquePerGroup)
143         throws PortalException, SystemException {
144 
145         return getPortletPreferencesFactory().getPortletSetup(
146             req, portletId, uniquePerLayout, uniquePerGroup);
147     }
148 
149     public static PortletPreferences getPreferences(HttpServletRequest req) {
150         return getPortletPreferencesFactory().getPreferences(req);
151     }
152 
153     public static PreferencesValidator getPreferencesValidator(
154         Portlet portlet) {
155 
156         return getPortletPreferencesFactory().getPreferencesValidator(portlet);
157     }
158 
159     public void setPortletPreferencesFactory(
160         PortletPreferencesFactory portletPreferencesFactory) {
161 
162         _portletPreferencesFactory = portletPreferencesFactory;
163     }
164 
165     private static PortletPreferencesFactoryUtil _getUtil() {
166         if (_util == null) {
167             _util =
168                 (PortletPreferencesFactoryUtil)BeanLocatorUtil.locate(_UTIL);
169         }
170 
171         return _util;
172     }
173 
174     private static final String _UTIL =
175         PortletPreferencesFactoryUtil.class.getName();
176 
177     private static PortletPreferencesFactoryUtil _util;
178 
179     private PortletPreferencesFactory _portletPreferencesFactory;
180 
181 }