1   /**
2    * Copyright (c) 2000-2008 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)
104         throws PortalException, SystemException {
105 
106         return getPortletPreferencesFactory().getPortletSetup(req, portletId);
107     }
108 
109     public static PortletPreferences getPortletSetup(
110             HttpServletRequest req, String portletId, String defaultPreferences)
111         throws PortalException, SystemException {
112 
113         return getPortletPreferencesFactory().getPortletSetup(
114             req, portletId, defaultPreferences);
115     }
116 
117     public static PortletPreferences getPortletSetup(
118             ActionRequest req, String portletId)
119         throws PortalException, SystemException {
120 
121         return getPortletPreferencesFactory().getPortletSetup(req, portletId);
122     }
123 
124     public static PortletPreferences getPortletSetup(
125             RenderRequest req, String portletId)
126         throws PortalException, SystemException {
127 
128         return getPortletPreferencesFactory().getPortletSetup(req, portletId);
129     }
130 
131     public static PortletPreferences getPreferences(HttpServletRequest req) {
132         return getPortletPreferencesFactory().getPreferences(req);
133     }
134 
135     public static PreferencesValidator getPreferencesValidator(
136         Portlet portlet) {
137 
138         return getPortletPreferencesFactory().getPreferencesValidator(portlet);
139     }
140 
141     public void setPortletPreferencesFactory(
142         PortletPreferencesFactory portletPreferencesFactory) {
143 
144         _portletPreferencesFactory = portletPreferencesFactory;
145     }
146 
147     private static PortletPreferencesFactoryUtil _getUtil() {
148         if (_util == null) {
149             _util =
150                 (PortletPreferencesFactoryUtil)BeanLocatorUtil.locate(_UTIL);
151         }
152 
153         return _util;
154     }
155 
156     private static final String _UTIL =
157         PortletPreferencesFactoryUtil.class.getName();
158 
159     private static PortletPreferencesFactoryUtil _util;
160 
161     private PortletPreferencesFactory _portletPreferencesFactory;
162 
163 }