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 getLayoutPortletSetup(
079                    Layout layout, String portletId) {
080    
081                    return getPortletPreferencesFactory().getLayoutPortletSetup(
082                            layout, portletId);
083            }
084    
085            public static PortalPreferences getPortalPreferences(
086                    HttpServletRequest request) {
087    
088                    return getPortletPreferencesFactory().getPortalPreferences(request);
089            }
090    
091            public static PortalPreferences getPortalPreferences(
092                    HttpSession session, long userId, boolean signedIn) {
093    
094                    return getPortletPreferencesFactory().getPortalPreferences(
095                            session, userId, signedIn);
096            }
097    
098            /**
099             * @deprecated As of 6.2.0, replaced by {@link
100             *             #getPortalPreferences(HttpSession, long, boolean)}
101             */
102            @Deprecated
103            public static PortalPreferences getPortalPreferences(
104                    HttpSession session, long companyId, long userId, boolean signedIn) {
105    
106                    return getPortletPreferencesFactory().getPortalPreferences(
107                            session, companyId, userId, signedIn);
108            }
109    
110            public static PortalPreferences getPortalPreferences(
111                    long userId, boolean signedIn) {
112    
113                    return getPortletPreferencesFactory().getPortalPreferences(
114                            userId, signedIn);
115            }
116    
117            /**
118             * @deprecated As of 6.2.0, replaced by {@link #getPortalPreferences(long,
119             *             boolean)}
120             */
121            @Deprecated
122            public static PortalPreferences getPortalPreferences(
123                    long companyId, long userId, boolean signedIn) {
124    
125                    return getPortletPreferencesFactory().getPortalPreferences(
126                            companyId, userId, signedIn);
127            }
128    
129            public static PortalPreferences getPortalPreferences(
130                    PortletRequest portletRequest) {
131    
132                    return getPortletPreferencesFactory().getPortalPreferences(
133                            portletRequest);
134            }
135    
136            public static PortletPreferences getPortletPreferences(
137                            HttpServletRequest request, String portletId)
138                    throws PortalException {
139    
140                    return getPortletPreferencesFactory().getPortletPreferences(
141                            request, portletId);
142            }
143    
144            public static PortletPreferencesFactory getPortletPreferencesFactory() {
145                    PortalRuntimePermission.checkGetBeanProperty(
146                            PortletPreferencesFactoryUtil.class);
147    
148                    return _portletPreferencesFactory;
149            }
150    
151            public static PortletPreferencesIds getPortletPreferencesIds(
152                            HttpServletRequest request, Layout selLayout, String portletId)
153                    throws PortalException {
154    
155                    return getPortletPreferencesFactory().getPortletPreferencesIds(
156                            request, selLayout, portletId);
157            }
158    
159            public static PortletPreferencesIds getPortletPreferencesIds(
160                            HttpServletRequest request, String portletId)
161                    throws PortalException {
162    
163                    return getPortletPreferencesFactory().getPortletPreferencesIds(
164                            request, portletId);
165            }
166    
167            public static PortletPreferencesIds getPortletPreferencesIds(
168                            long scopeGroupId, long userId, Layout layout, String portletId,
169                            boolean modeEditGuest)
170                    throws PortalException {
171    
172                    return getPortletPreferencesFactory().getPortletPreferencesIds(
173                            scopeGroupId, userId, layout, portletId, modeEditGuest);
174            }
175    
176            public static PortletPreferences getPortletSetup(
177                            HttpServletRequest request, String portletId)
178                    throws PortalException {
179    
180                    return getPortletPreferencesFactory().getPortletSetup(
181                            request, portletId);
182            }
183    
184            public static PortletPreferences getPortletSetup(
185                            HttpServletRequest request, String portletId,
186                            String defaultPreferences)
187                    throws PortalException {
188    
189                    return getPortletPreferencesFactory().getPortletSetup(
190                            request, portletId, defaultPreferences);
191            }
192    
193            public static PortletPreferences getPortletSetup(
194                    Layout layout, String portletId, String defaultPreferences) {
195    
196                    return getPortletPreferencesFactory().getPortletSetup(
197                            layout, portletId, defaultPreferences);
198            }
199    
200            public static PortletPreferences getPortletSetup(
201                    long scopeGroupId, Layout layout, String portletId,
202                    String defaultPreferences) {
203    
204                    return getPortletPreferencesFactory().getPortletSetup(
205                            scopeGroupId, layout, portletId, defaultPreferences);
206            }
207    
208            public static PortletPreferences getPortletSetup(
209                            PortletRequest portletRequest)
210                    throws PortalException {
211    
212                    return getPortletPreferencesFactory().getPortletSetup(portletRequest);
213            }
214    
215            public static PortletPreferences getPortletSetup(
216                            PortletRequest portletRequest, String portletId)
217                    throws PortalException {
218    
219                    return getPortletPreferencesFactory().getPortletSetup(
220                            portletRequest, portletId);
221            }
222    
223            public static Map<Long, PortletPreferences> getPortletSetupMap(
224                    long companyId, long groupId, long ownerId, int ownerType,
225                    String portletId, boolean privateLayout) {
226    
227                    return getPortletPreferencesFactory().getPortletSetupMap(
228                            companyId, groupId, ownerId, ownerType, portletId, privateLayout);
229            }
230    
231            public static PortletPreferences getPreferences(
232                    HttpServletRequest request) {
233    
234                    return getPortletPreferencesFactory().getPreferences(request);
235            }
236    
237            public static PreferencesValidator getPreferencesValidator(
238                    Portlet portlet) {
239    
240                    return getPortletPreferencesFactory().getPreferencesValidator(portlet);
241            }
242    
243            public static PortletPreferences getStrictLayoutPortletSetup(
244                    Layout layout, String portletId) {
245    
246                    return getPortletPreferencesFactory().getStrictLayoutPortletSetup(
247                            layout, portletId);
248            }
249    
250            public static PortletPreferences getStrictPortletSetup(
251                    Layout layout, String portletId) {
252    
253                    return getPortletPreferencesFactory().getStrictPortletSetup(
254                            layout, portletId);
255            }
256    
257            public static String toXML(PortalPreferences portalPreferences) {
258                    return getPortletPreferencesFactory().toXML(portalPreferences);
259            }
260    
261            public static String toXML(PortletPreferences portletPreferences) {
262                    return getPortletPreferencesFactory().toXML(portletPreferences);
263            }
264    
265            public void setPortletPreferencesFactory(
266                    PortletPreferencesFactory portletPreferencesFactory) {
267    
268                    PortalRuntimePermission.checkSetBeanProperty(getClass());
269    
270                    _portletPreferencesFactory = portletPreferencesFactory;
271            }
272    
273            private static PortletPreferencesFactory _portletPreferencesFactory;
274    
275    }