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 PortletPreferences fromXML(
045                            long companyId, long ownerId, int ownerType, long plid,
046                            String portletId, String xml)
047                    throws SystemException {
048    
049                    return getPortletPreferencesFactory().fromXML(
050                            companyId, ownerId, ownerType, plid, portletId, xml);
051            }
052    
053            public static PortalPreferences fromXML(
054                            long companyId, long ownerId, int ownerType, String xml)
055                    throws SystemException {
056    
057                    return getPortletPreferencesFactory().fromXML(
058                            companyId, ownerId, ownerType, xml);
059            }
060    
061            public static PortletPreferences getLayoutPortletSetup(
062                            Layout layout, String portletId)
063                    throws SystemException {
064    
065                    return getPortletPreferencesFactory().getLayoutPortletSetup(
066                            layout, portletId);
067            }
068    
069            public static PortalPreferences getPortalPreferences(
070                            HttpServletRequest request)
071                    throws SystemException {
072    
073                    return getPortletPreferencesFactory().getPortalPreferences(request);
074            }
075    
076            public static PortalPreferences getPortalPreferences(
077                            HttpSession session, long companyId, long userId, boolean signedIn)
078                    throws SystemException {
079    
080                    return getPortletPreferencesFactory().getPortalPreferences(
081                            session, companyId, userId, signedIn);
082            }
083    
084            public static PortalPreferences getPortalPreferences(
085                            long companyId, long userId, boolean signedIn)
086                    throws SystemException {
087    
088                    return getPortletPreferencesFactory().getPortalPreferences(
089                            companyId, userId, signedIn);
090            }
091    
092            public static PortalPreferences getPortalPreferences(
093                            PortletRequest portletRequest)
094                    throws SystemException {
095    
096                    return getPortletPreferencesFactory().getPortalPreferences(
097                            portletRequest);
098            }
099    
100            public static PortletPreferences getPortletPreferences(
101                            HttpServletRequest request, String portletId)
102                    throws PortalException, SystemException {
103    
104                    return getPortletPreferencesFactory().getPortletPreferences(
105                            request, portletId);
106            }
107    
108            public static PortletPreferencesFactory getPortletPreferencesFactory() {
109                    PortalRuntimePermission.checkGetBeanProperty(
110                            PortletPreferencesFactoryUtil.class);
111    
112                    return _portletPreferencesFactory;
113            }
114    
115            public static PortletPreferencesIds getPortletPreferencesIds(
116                            HttpServletRequest request, Layout selLayout, String portletId)
117                    throws PortalException, SystemException {
118    
119                    return getPortletPreferencesFactory().getPortletPreferencesIds(
120                            request, selLayout, portletId);
121            }
122    
123            public static PortletPreferencesIds getPortletPreferencesIds(
124                            HttpServletRequest request, String portletId)
125                    throws PortalException, SystemException {
126    
127                    return getPortletPreferencesFactory().getPortletPreferencesIds(
128                            request, portletId);
129            }
130    
131            public static PortletPreferencesIds getPortletPreferencesIds(
132                            long scopeGroupId, long userId, Layout layout, String portletId,
133                            boolean modeEditGuest)
134                    throws PortalException, SystemException {
135    
136                    return getPortletPreferencesFactory().getPortletPreferencesIds(
137                            scopeGroupId, userId, layout, portletId, modeEditGuest);
138            }
139    
140            public static PortletPreferences getPortletSetup(
141                            HttpServletRequest request, String portletId)
142                    throws PortalException, SystemException {
143    
144                    return getPortletPreferencesFactory().getPortletSetup(
145                            request, portletId);
146            }
147    
148            public static PortletPreferences getPortletSetup(
149                            HttpServletRequest request, String portletId,
150                            String defaultPreferences)
151                    throws PortalException, SystemException {
152    
153                    return getPortletPreferencesFactory().getPortletSetup(
154                            request, portletId, defaultPreferences);
155            }
156    
157            public static PortletPreferences getPortletSetup(
158                            Layout layout, String portletId, String defaultPreferences)
159                    throws SystemException {
160    
161                    return getPortletPreferencesFactory().getPortletSetup(
162                            layout, portletId, defaultPreferences);
163            }
164    
165            public static PortletPreferences getPortletSetup(
166                            long scopeGroupId, Layout layout, String portletId,
167                            String defaultPreferences)
168                    throws SystemException {
169    
170                    return getPortletPreferencesFactory().getPortletSetup(
171                            scopeGroupId, layout, portletId, defaultPreferences);
172            }
173    
174            public static PortletPreferences getPortletSetup(
175                            PortletRequest portletRequest)
176                    throws PortalException, SystemException {
177    
178                    return getPortletPreferencesFactory().getPortletSetup(portletRequest);
179            }
180    
181            public static PortletPreferences getPortletSetup(
182                            PortletRequest portletRequest, String portletId)
183                    throws PortalException, SystemException {
184    
185                    return getPortletPreferencesFactory().getPortletSetup(
186                            portletRequest, portletId);
187            }
188    
189            public static Map<Long, PortletPreferences> getPortletSetupMap(
190                            long companyId, long groupId, long ownerId, int ownerType,
191                            String portletId, boolean privateLayout)
192                    throws SystemException {
193    
194                    return getPortletPreferencesFactory().getPortletSetupMap(
195                            companyId, groupId, ownerId, ownerType, portletId, privateLayout);
196            }
197    
198            public static PortletPreferences getPreferences(
199                    HttpServletRequest request) {
200    
201                    return getPortletPreferencesFactory().getPreferences(request);
202            }
203    
204            public static PreferencesValidator getPreferencesValidator(
205                    Portlet portlet) {
206    
207                    return getPortletPreferencesFactory().getPreferencesValidator(portlet);
208            }
209    
210            public static PortletPreferences getStrictLayoutPortletSetup(
211                            Layout layout, String portletId)
212                    throws SystemException {
213    
214                    return getPortletPreferencesFactory().getStrictLayoutPortletSetup(
215                            layout, portletId);
216            }
217    
218            public static PortletPreferences getStrictPortletSetup(
219                            Layout layout, String portletId)
220                    throws SystemException {
221    
222                    return getPortletPreferencesFactory().getStrictPortletSetup(
223                            layout, portletId);
224            }
225    
226            public static String toXML(PortalPreferences portalPreferences) {
227                    return getPortletPreferencesFactory().toXML(portalPreferences);
228            }
229    
230            public static String toXML(PortletPreferences portletPreferences) {
231                    return getPortletPreferencesFactory().toXML(portletPreferences);
232            }
233    
234            public void setPortletPreferencesFactory(
235                    PortletPreferencesFactory portletPreferencesFactory) {
236    
237                    PortalRuntimePermission.checkSetBeanProperty(getClass());
238    
239                    _portletPreferencesFactory = portletPreferencesFactory;
240            }
241    
242            private static PortletPreferencesFactory _portletPreferencesFactory;
243    
244    }