001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.model.Portlet;
024    import com.liferay.portal.model.PortletPreferencesIds;
025    import com.liferay.portal.theme.ThemeDisplay;
026    
027    import java.util.Map;
028    
029    import javax.portlet.PortletPreferences;
030    import javax.portlet.PortletRequest;
031    import javax.portlet.PreferencesValidator;
032    
033    import javax.servlet.http.HttpServletRequest;
034    import javax.servlet.http.HttpSession;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    @ProviderType
040    public class PortletPreferencesFactoryUtil {
041    
042            public static void checkControlPanelPortletPreferences(
043                            ThemeDisplay themeDisplay, Portlet portlet)
044                    throws PortalException, SystemException {
045    
046                    getPortletPreferencesFactory().checkControlPanelPortletPreferences(
047                            themeDisplay, portlet);
048            }
049    
050            public static PortletPreferences fromDefaultXML(String xml)
051                    throws SystemException {
052    
053                    return getPortletPreferencesFactory().fromDefaultXML(xml);
054            }
055    
056            public static PortalPreferences fromXML(
057                            long ownerId, int ownerType, String xml)
058                    throws SystemException {
059    
060                    return getPortletPreferencesFactory().fromXML(ownerId, ownerType, xml);
061            }
062    
063            public static PortletPreferences fromXML(
064                            long companyId, long ownerId, int ownerType, long plid,
065                            String portletId, String xml)
066                    throws SystemException {
067    
068                    return getPortletPreferencesFactory().fromXML(
069                            companyId, ownerId, ownerType, plid, portletId, xml);
070            }
071    
072            /**
073             * @deprecated As of 6.2.0, replaced by {@link #fromXML(long, int, String)}
074             */
075            public static PortalPreferences fromXML(
076                            long companyId, long ownerId, int ownerType, String xml)
077                    throws SystemException {
078    
079                    return getPortletPreferencesFactory().fromXML(
080                            companyId, ownerId, ownerType, xml);
081            }
082    
083            public static PortletPreferences getLayoutPortletSetup(
084                            Layout layout, String portletId)
085                    throws SystemException {
086    
087                    return getPortletPreferencesFactory().getLayoutPortletSetup(
088                            layout, portletId);
089            }
090    
091            public static PortalPreferences getPortalPreferences(
092                            HttpServletRequest request)
093                    throws SystemException {
094    
095                    return getPortletPreferencesFactory().getPortalPreferences(request);
096            }
097    
098            public static PortalPreferences getPortalPreferences(
099                            HttpSession session, long userId, boolean signedIn)
100                    throws SystemException {
101    
102                    return getPortletPreferencesFactory().getPortalPreferences(
103                            session, userId, signedIn);
104            }
105    
106            /**
107             * @deprecated As of 6.2.0, replaced by {@link
108             *             #getPortalPreferences(HttpSession, long, boolean)}
109             */
110            public static PortalPreferences getPortalPreferences(
111                            HttpSession session, long companyId, long userId, boolean signedIn)
112                    throws SystemException {
113    
114                    return getPortletPreferencesFactory().getPortalPreferences(
115                            session, companyId, userId, signedIn);
116            }
117    
118            public static PortalPreferences getPortalPreferences(
119                            long userId, boolean signedIn)
120                    throws SystemException {
121    
122                    return getPortletPreferencesFactory().getPortalPreferences(
123                            userId, signedIn);
124            }
125    
126            /**
127             * @deprecated As of 6.2.0, replaced by {@link #getPortalPreferences(long,
128             *             boolean)}
129             */
130            public static PortalPreferences getPortalPreferences(
131                            long companyId, long userId, boolean signedIn)
132                    throws SystemException {
133    
134                    return getPortletPreferencesFactory().getPortalPreferences(
135                            companyId, userId, signedIn);
136            }
137    
138            public static PortalPreferences getPortalPreferences(
139                            PortletRequest portletRequest)
140                    throws SystemException {
141    
142                    return getPortletPreferencesFactory().getPortalPreferences(
143                            portletRequest);
144            }
145    
146            public static PortletPreferences getPortletPreferences(
147                            HttpServletRequest request, String portletId)
148                    throws PortalException, SystemException {
149    
150                    return getPortletPreferencesFactory().getPortletPreferences(
151                            request, portletId);
152            }
153    
154            public static PortletPreferencesFactory getPortletPreferencesFactory() {
155                    PortalRuntimePermission.checkGetBeanProperty(
156                            PortletPreferencesFactoryUtil.class);
157    
158                    return _portletPreferencesFactory;
159            }
160    
161            public static PortletPreferencesIds getPortletPreferencesIds(
162                            HttpServletRequest request, Layout selLayout, String portletId)
163                    throws PortalException, SystemException {
164    
165                    return getPortletPreferencesFactory().getPortletPreferencesIds(
166                            request, selLayout, portletId);
167            }
168    
169            public static PortletPreferencesIds getPortletPreferencesIds(
170                            HttpServletRequest request, String portletId)
171                    throws PortalException, SystemException {
172    
173                    return getPortletPreferencesFactory().getPortletPreferencesIds(
174                            request, portletId);
175            }
176    
177            public static PortletPreferencesIds getPortletPreferencesIds(
178                            long scopeGroupId, long userId, Layout layout, String portletId,
179                            boolean modeEditGuest)
180                    throws PortalException, SystemException {
181    
182                    return getPortletPreferencesFactory().getPortletPreferencesIds(
183                            scopeGroupId, userId, layout, portletId, modeEditGuest);
184            }
185    
186            public static PortletPreferences getPortletSetup(
187                            HttpServletRequest request, String portletId)
188                    throws PortalException, SystemException {
189    
190                    return getPortletPreferencesFactory().getPortletSetup(
191                            request, portletId);
192            }
193    
194            public static PortletPreferences getPortletSetup(
195                            HttpServletRequest request, String portletId,
196                            String defaultPreferences)
197                    throws PortalException, SystemException {
198    
199                    return getPortletPreferencesFactory().getPortletSetup(
200                            request, portletId, defaultPreferences);
201            }
202    
203            public static PortletPreferences getPortletSetup(
204                            Layout layout, String portletId, String defaultPreferences)
205                    throws SystemException {
206    
207                    return getPortletPreferencesFactory().getPortletSetup(
208                            layout, portletId, defaultPreferences);
209            }
210    
211            public static PortletPreferences getPortletSetup(
212                            long scopeGroupId, Layout layout, String portletId,
213                            String defaultPreferences)
214                    throws SystemException {
215    
216                    return getPortletPreferencesFactory().getPortletSetup(
217                            scopeGroupId, layout, portletId, defaultPreferences);
218            }
219    
220            public static PortletPreferences getPortletSetup(
221                            PortletRequest portletRequest)
222                    throws PortalException, SystemException {
223    
224                    return getPortletPreferencesFactory().getPortletSetup(portletRequest);
225            }
226    
227            public static PortletPreferences getPortletSetup(
228                            PortletRequest portletRequest, String portletId)
229                    throws PortalException, SystemException {
230    
231                    return getPortletPreferencesFactory().getPortletSetup(
232                            portletRequest, portletId);
233            }
234    
235            public static Map<Long, PortletPreferences> getPortletSetupMap(
236                            long companyId, long groupId, long ownerId, int ownerType,
237                            String portletId, boolean privateLayout)
238                    throws SystemException {
239    
240                    return getPortletPreferencesFactory().getPortletSetupMap(
241                            companyId, groupId, ownerId, ownerType, portletId, privateLayout);
242            }
243    
244            public static PortletPreferences getPreferences(
245                    HttpServletRequest request) {
246    
247                    return getPortletPreferencesFactory().getPreferences(request);
248            }
249    
250            public static PreferencesValidator getPreferencesValidator(
251                    Portlet portlet) {
252    
253                    return getPortletPreferencesFactory().getPreferencesValidator(portlet);
254            }
255    
256            public static PortletPreferences getStrictLayoutPortletSetup(
257                            Layout layout, String portletId)
258                    throws SystemException {
259    
260                    return getPortletPreferencesFactory().getStrictLayoutPortletSetup(
261                            layout, portletId);
262            }
263    
264            public static PortletPreferences getStrictPortletSetup(
265                            Layout layout, String portletId)
266                    throws SystemException {
267    
268                    return getPortletPreferencesFactory().getStrictPortletSetup(
269                            layout, portletId);
270            }
271    
272            public static PortletPreferences strictFromXML(
273                            long companyId, long ownerId, int ownerType, long plid,
274                            String portletId, String xml)
275                    throws SystemException {
276    
277                    return getPortletPreferencesFactory().strictFromXML(
278                            companyId, ownerId, ownerType, plid, portletId, xml);
279            }
280    
281            public static String toXML(PortalPreferences portalPreferences) {
282                    return getPortletPreferencesFactory().toXML(portalPreferences);
283            }
284    
285            public static String toXML(PortletPreferences portletPreferences) {
286                    return getPortletPreferencesFactory().toXML(portletPreferences);
287            }
288    
289            public void setPortletPreferencesFactory(
290                    PortletPreferencesFactory portletPreferencesFactory) {
291    
292                    PortalRuntimePermission.checkSetBeanProperty(getClass());
293    
294                    _portletPreferencesFactory = portletPreferencesFactory;
295            }
296    
297            private static PortletPreferencesFactory _portletPreferencesFactory;
298    
299    }