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