001    /**
002     * Copyright (c) 2000-present 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.security.pacl.permission.PortalRuntimePermission;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.Portlet;
023    import com.liferay.portal.model.PortletPreferencesIds;
024    import com.liferay.portal.theme.ThemeDisplay;
025    
026    import java.util.Map;
027    
028    import javax.portlet.PortletPreferences;
029    import javax.portlet.PortletRequest;
030    import javax.portlet.PreferencesValidator;
031    
032    import javax.servlet.http.HttpServletRequest;
033    import javax.servlet.http.HttpSession;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     */
038    @ProviderType
039    public class PortletPreferencesFactoryUtil {
040    
041            public static void checkControlPanelPortletPreferences(
042                            ThemeDisplay themeDisplay, Portlet portlet)
043                    throws PortalException {
044    
045                    getPortletPreferencesFactory().checkControlPanelPortletPreferences(
046                            themeDisplay, portlet);
047            }
048    
049            public static PortletPreferences fromDefaultXML(String xml) {
050                    return getPortletPreferencesFactory().fromDefaultXML(xml);
051            }
052    
053            public static PortalPreferences fromXML(
054                    long ownerId, int ownerType, String xml) {
055    
056                    return getPortletPreferencesFactory().fromXML(ownerId, ownerType, xml);
057            }
058    
059            public static PortletPreferences fromXML(
060                    long companyId, long ownerId, int ownerType, long plid,
061                    String portletId, String xml) {
062    
063                    return getPortletPreferencesFactory().fromXML(
064                            companyId, ownerId, ownerType, plid, portletId, xml);
065            }
066    
067            /**
068             * @deprecated As of 6.2.0, replaced by {@link #fromXML(long, int, String)}
069             */
070            @Deprecated
071            public static PortalPreferences fromXML(
072                    long companyId, long ownerId, int ownerType, String xml) {
073    
074                    return getPortletPreferencesFactory().fromXML(
075                            companyId, ownerId, ownerType, xml);
076            }
077    
078            public static PortletPreferences getExistingPortletSetup(
079                            Layout layout, String portletId)
080                    throws PortalException {
081    
082                    return getPortletPreferencesFactory().getExistingPortletSetup(
083                            layout, portletId);
084            }
085    
086            public static PortletPreferences getExistingPortletSetup(
087                            PortletRequest portletRequest)
088                    throws PortalException {
089    
090                    return getPortletPreferencesFactory().getExistingPortletSetup(
091                            portletRequest);
092            }
093    
094            public static PortletPreferences getLayoutPortletSetup(
095                    Layout layout, String portletId) {
096    
097                    return getPortletPreferencesFactory().getLayoutPortletSetup(
098                            layout, portletId);
099            }
100    
101            public static PortletPreferences getLayoutPortletSetup(
102                    Layout layout, String portletId, String defaultPreferences) {
103    
104                    return getPortletPreferencesFactory().getLayoutPortletSetup(
105                            layout, portletId, defaultPreferences);
106            }
107    
108            public static PortalPreferences getPortalPreferences(
109                    HttpServletRequest request) {
110    
111                    return getPortletPreferencesFactory().getPortalPreferences(request);
112            }
113    
114            public static PortalPreferences getPortalPreferences(
115                    HttpSession session, long userId, boolean signedIn) {
116    
117                    return getPortletPreferencesFactory().getPortalPreferences(
118                            session, userId, signedIn);
119            }
120    
121            /**
122             * @deprecated As of 6.2.0, replaced by {@link
123             *             #getPortalPreferences(HttpSession, long, boolean)}
124             */
125            @Deprecated
126            public static PortalPreferences getPortalPreferences(
127                    HttpSession session, long companyId, long userId, boolean signedIn) {
128    
129                    return getPortletPreferencesFactory().getPortalPreferences(
130                            session, companyId, userId, signedIn);
131            }
132    
133            public static PortalPreferences getPortalPreferences(
134                    long userId, boolean signedIn) {
135    
136                    return getPortletPreferencesFactory().getPortalPreferences(
137                            userId, signedIn);
138            }
139    
140            /**
141             * @deprecated As of 6.2.0, replaced by {@link #getPortalPreferences(long,
142             *             boolean)}
143             */
144            @Deprecated
145            public static PortalPreferences getPortalPreferences(
146                    long companyId, long userId, boolean signedIn) {
147    
148                    return getPortletPreferencesFactory().getPortalPreferences(
149                            companyId, userId, signedIn);
150            }
151    
152            public static PortalPreferences getPortalPreferences(
153                    PortletRequest portletRequest) {
154    
155                    return getPortletPreferencesFactory().getPortalPreferences(
156                            portletRequest);
157            }
158    
159            public static PortletPreferences getPortletPreferences(
160                            HttpServletRequest request, String portletId)
161                    throws PortalException {
162    
163                    return getPortletPreferencesFactory().getPortletPreferences(
164                            request, portletId);
165            }
166    
167            public static PortletPreferencesFactory getPortletPreferencesFactory() {
168                    PortalRuntimePermission.checkGetBeanProperty(
169                            PortletPreferencesFactoryUtil.class);
170    
171                    return _portletPreferencesFactory;
172            }
173    
174            public static PortletPreferencesIds getPortletPreferencesIds(
175                            HttpServletRequest request, Layout selLayout, String portletId)
176                    throws PortalException {
177    
178                    return getPortletPreferencesFactory().getPortletPreferencesIds(
179                            request, selLayout, portletId);
180            }
181    
182            public static PortletPreferencesIds getPortletPreferencesIds(
183                            HttpServletRequest request, String portletId)
184                    throws PortalException {
185    
186                    return getPortletPreferencesFactory().getPortletPreferencesIds(
187                            request, portletId);
188            }
189    
190            public static PortletPreferencesIds getPortletPreferencesIds(
191                            long siteGroupId, long userId, Layout layout, String portletId,
192                            boolean modeEditGuest)
193                    throws PortalException {
194    
195                    return getPortletPreferencesFactory().getPortletPreferencesIds(
196                            siteGroupId, userId, layout, portletId, modeEditGuest);
197            }
198    
199            public static PortletPreferencesIds getPortletPreferencesIds(
200                    long companyId, long siteGroupId, long plid, String portletId,
201                    String settingsScope) {
202    
203                    return getPortletPreferencesFactory().getPortletPreferencesIds(
204                            companyId, siteGroupId, plid, portletId, settingsScope);
205            }
206    
207            public static PortletPreferences getPortletSetup(
208                            HttpServletRequest request, String portletId)
209                    throws PortalException {
210    
211                    return getPortletPreferencesFactory().getPortletSetup(
212                            request, portletId);
213            }
214    
215            public static PortletPreferences getPortletSetup(
216                            HttpServletRequest request, String portletId,
217                            String defaultPreferences)
218                    throws PortalException {
219    
220                    return getPortletPreferencesFactory().getPortletSetup(
221                            request, portletId, defaultPreferences);
222            }
223    
224            public static PortletPreferences getPortletSetup(
225                    Layout layout, String portletId, String defaultPreferences) {
226    
227                    return getPortletPreferencesFactory().getPortletSetup(
228                            layout, portletId, defaultPreferences);
229            }
230    
231            public static PortletPreferences getPortletSetup(
232                    long siteGroupId, Layout layout, String portletId,
233                    String defaultPreferences) {
234    
235                    return getPortletPreferencesFactory().getPortletSetup(
236                            siteGroupId, layout, portletId, defaultPreferences);
237            }
238    
239            public static PortletPreferences getPortletSetup(
240                            PortletRequest portletRequest)
241                    throws PortalException {
242    
243                    return getPortletPreferencesFactory().getPortletSetup(portletRequest);
244            }
245    
246            public static PortletPreferences getPortletSetup(
247                            PortletRequest portletRequest, String portletId)
248                    throws PortalException {
249    
250                    return getPortletPreferencesFactory().getPortletSetup(
251                            portletRequest, portletId);
252            }
253    
254            public static Map<Long, PortletPreferences> getPortletSetupMap(
255                    long companyId, long groupId, long ownerId, int ownerType,
256                    String portletId, boolean privateLayout) {
257    
258                    return getPortletPreferencesFactory().getPortletSetupMap(
259                            companyId, groupId, ownerId, ownerType, portletId, privateLayout);
260            }
261    
262            public static PortletPreferences getPreferences(
263                    HttpServletRequest request) {
264    
265                    return getPortletPreferencesFactory().getPreferences(request);
266            }
267    
268            public static PreferencesValidator getPreferencesValidator(
269                    Portlet portlet) {
270    
271                    return getPortletPreferencesFactory().getPreferencesValidator(portlet);
272            }
273    
274            public static PortletPreferences getStrictLayoutPortletSetup(
275                    Layout layout, String portletId) {
276    
277                    return getPortletPreferencesFactory().getStrictLayoutPortletSetup(
278                            layout, portletId);
279            }
280    
281            public static PortletPreferences getStrictPortletSetup(
282                    Layout layout, String portletId) {
283    
284                    return getPortletPreferencesFactory().getStrictPortletSetup(
285                            layout, portletId);
286            }
287    
288            public static PortletPreferences strictFromXML(
289                    long companyId, long ownerId, int ownerType, long plid,
290                    String portletId, String xml) {
291    
292                    return getPortletPreferencesFactory().strictFromXML(
293                            companyId, ownerId, ownerType, plid, portletId, xml);
294            }
295    
296            public static String toXML(PortalPreferences portalPreferences) {
297                    return getPortletPreferencesFactory().toXML(portalPreferences);
298            }
299    
300            public static String toXML(PortletPreferences portletPreferences) {
301                    return getPortletPreferencesFactory().toXML(portletPreferences);
302            }
303    
304            public void setPortletPreferencesFactory(
305                    PortletPreferencesFactory portletPreferencesFactory) {
306    
307                    PortalRuntimePermission.checkSetBeanProperty(getClass());
308    
309                    _portletPreferencesFactory = portletPreferencesFactory;
310            }
311    
312            private static PortletPreferencesFactory _portletPreferencesFactory;
313    
314    }