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 PortletPreferences getLayoutPortletSetup(
109                    long companyId, long ownerId, int ownerType, long plid,
110                    String portletId, String defaultPreferences) {
111    
112                    return getPortletPreferencesFactory().getLayoutPortletSetup(
113                            companyId, ownerId, ownerType, plid, portletId, defaultPreferences);
114            }
115    
116            public static PortalPreferences getPortalPreferences(
117                    HttpServletRequest request) {
118    
119                    return getPortletPreferencesFactory().getPortalPreferences(request);
120            }
121    
122            public static PortalPreferences getPortalPreferences(
123                    HttpSession session, long userId, boolean signedIn) {
124    
125                    return getPortletPreferencesFactory().getPortalPreferences(
126                            session, userId, signedIn);
127            }
128    
129            /**
130             * @deprecated As of 6.2.0, replaced by {@link
131             *             #getPortalPreferences(HttpSession, long, boolean)}
132             */
133            @Deprecated
134            public static PortalPreferences getPortalPreferences(
135                    HttpSession session, long companyId, long userId, boolean signedIn) {
136    
137                    return getPortletPreferencesFactory().getPortalPreferences(
138                            session, companyId, userId, signedIn);
139            }
140    
141            public static PortalPreferences getPortalPreferences(
142                    long userId, boolean signedIn) {
143    
144                    return getPortletPreferencesFactory().getPortalPreferences(
145                            userId, signedIn);
146            }
147    
148            /**
149             * @deprecated As of 6.2.0, replaced by {@link #getPortalPreferences(long,
150             *             boolean)}
151             */
152            @Deprecated
153            public static PortalPreferences getPortalPreferences(
154                    long companyId, long userId, boolean signedIn) {
155    
156                    return getPortletPreferencesFactory().getPortalPreferences(
157                            companyId, userId, signedIn);
158            }
159    
160            public static PortalPreferences getPortalPreferences(
161                    PortletRequest portletRequest) {
162    
163                    return getPortletPreferencesFactory().getPortalPreferences(
164                            portletRequest);
165            }
166    
167            public static PortletPreferences getPortletPreferences(
168                            HttpServletRequest request, String portletId)
169                    throws PortalException {
170    
171                    return getPortletPreferencesFactory().getPortletPreferences(
172                            request, portletId);
173            }
174    
175            public static PortletPreferencesFactory getPortletPreferencesFactory() {
176                    PortalRuntimePermission.checkGetBeanProperty(
177                            PortletPreferencesFactoryUtil.class);
178    
179                    return _portletPreferencesFactory;
180            }
181    
182            public static PortletPreferencesIds getPortletPreferencesIds(
183                            HttpServletRequest request, Layout selLayout, String portletId)
184                    throws PortalException {
185    
186                    return getPortletPreferencesFactory().getPortletPreferencesIds(
187                            request, selLayout, portletId);
188            }
189    
190            public static PortletPreferencesIds getPortletPreferencesIds(
191                            HttpServletRequest request, String portletId)
192                    throws PortalException {
193    
194                    return getPortletPreferencesFactory().getPortletPreferencesIds(
195                            request, portletId);
196            }
197    
198            public static PortletPreferencesIds getPortletPreferencesIds(
199                            long siteGroupId, long userId, Layout layout, String portletId,
200                            boolean modeEditGuest)
201                    throws PortalException {
202    
203                    return getPortletPreferencesFactory().getPortletPreferencesIds(
204                            siteGroupId, userId, layout, portletId, modeEditGuest);
205            }
206    
207            public static PortletPreferencesIds getPortletPreferencesIds(
208                    long companyId, long siteGroupId, long plid, String portletId,
209                    String settingsScope) {
210    
211                    return getPortletPreferencesFactory().getPortletPreferencesIds(
212                            companyId, siteGroupId, plid, portletId, settingsScope);
213            }
214    
215            public static PortletPreferences getPortletSetup(
216                            HttpServletRequest request, String portletId)
217                    throws PortalException {
218    
219                    return getPortletPreferencesFactory().getPortletSetup(
220                            request, portletId);
221            }
222    
223            public static PortletPreferences getPortletSetup(
224                            HttpServletRequest request, String portletId,
225                            String defaultPreferences)
226                    throws PortalException {
227    
228                    return getPortletPreferencesFactory().getPortletSetup(
229                            request, portletId, defaultPreferences);
230            }
231    
232            public static PortletPreferences getPortletSetup(
233                    Layout layout, String portletId, String defaultPreferences) {
234    
235                    return getPortletPreferencesFactory().getPortletSetup(
236                            layout, portletId, defaultPreferences);
237            }
238    
239            public static PortletPreferences getPortletSetup(
240                    long siteGroupId, Layout layout, String portletId,
241                    String defaultPreferences) {
242    
243                    return getPortletPreferencesFactory().getPortletSetup(
244                            siteGroupId, layout, portletId, defaultPreferences);
245            }
246    
247            public static PortletPreferences getPortletSetup(
248                            PortletRequest portletRequest)
249                    throws PortalException {
250    
251                    return getPortletPreferencesFactory().getPortletSetup(portletRequest);
252            }
253    
254            public static PortletPreferences getPortletSetup(
255                            PortletRequest portletRequest, String portletId)
256                    throws PortalException {
257    
258                    return getPortletPreferencesFactory().getPortletSetup(
259                            portletRequest, portletId);
260            }
261    
262            public static Map<Long, PortletPreferences> getPortletSetupMap(
263                    long companyId, long groupId, long ownerId, int ownerType,
264                    String portletId, boolean privateLayout) {
265    
266                    return getPortletPreferencesFactory().getPortletSetupMap(
267                            companyId, groupId, ownerId, ownerType, portletId, privateLayout);
268            }
269    
270            public static PortletPreferences getPreferences(
271                    HttpServletRequest request) {
272    
273                    return getPortletPreferencesFactory().getPreferences(request);
274            }
275    
276            public static PreferencesValidator getPreferencesValidator(
277                    Portlet portlet) {
278    
279                    return getPortletPreferencesFactory().getPreferencesValidator(portlet);
280            }
281    
282            public static PortletPreferences getStrictLayoutPortletSetup(
283                    Layout layout, String portletId) {
284    
285                    return getPortletPreferencesFactory().getStrictLayoutPortletSetup(
286                            layout, portletId);
287            }
288    
289            public static PortletPreferences getStrictPortletSetup(
290                    Layout layout, String portletId) {
291    
292                    return getPortletPreferencesFactory().getStrictPortletSetup(
293                            layout, portletId);
294            }
295    
296            public static PortletPreferences getStrictPortletSetup(
297                    long companyId, long groupId, String portletId) {
298    
299                    return getPortletPreferencesFactory().getStrictPortletSetup(
300                            companyId, groupId, portletId);
301            }
302    
303            public static PortletPreferences strictFromXML(
304                    long companyId, long ownerId, int ownerType, long plid,
305                    String portletId, String xml) {
306    
307                    return getPortletPreferencesFactory().strictFromXML(
308                            companyId, ownerId, ownerType, plid, portletId, xml);
309            }
310    
311            public static String toXML(PortalPreferences portalPreferences) {
312                    return getPortletPreferencesFactory().toXML(portalPreferences);
313            }
314    
315            public static String toXML(PortletPreferences portletPreferences) {
316                    return getPortletPreferencesFactory().toXML(portletPreferences);
317            }
318    
319            public void setPortletPreferencesFactory(
320                    PortletPreferencesFactory portletPreferencesFactory) {
321    
322                    PortalRuntimePermission.checkSetBeanProperty(getClass());
323    
324                    _portletPreferencesFactory = portletPreferencesFactory;
325            }
326    
327            private static PortletPreferencesFactory _portletPreferencesFactory;
328    
329    }