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.portal.security.permission;
016    
017    import com.liferay.portal.NoSuchResourceActionException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.Portlet;
022    import com.liferay.portal.model.Role;
023    
024    import java.io.InputStream;
025    
026    import java.util.List;
027    import java.util.Locale;
028    
029    import javax.servlet.jsp.PageContext;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Daeyoung Song
034     */
035    public class ResourceActionsUtil {
036    
037            /**
038             * @deprecated As of 6.1.0, replaced by {@link #getActionNamePrefix}
039             */
040            public static final String ACTION_NAME_PREFIX =
041                    ResourceActions.ACTION_NAME_PREFIX;
042    
043            /**
044             * @deprecated As of 6.1.0, replaced by {@link #getModelResourceNamePrefix}
045             */
046            public static final String MODEL_RESOURCE_NAME_PREFIX =
047                    ResourceActions.MODEL_RESOURCE_NAME_PREFIX;
048    
049            /**
050             * @deprecated As of 6.1.0, replaced by {@link
051             *             #getOrganizationModelResources}
052             */
053            public static final String[] ORGANIZATION_MODEL_RESOURCES =
054                    ResourceActions.ORGANIZATION_MODEL_RESOURCES;
055    
056            /**
057             * @deprecated As of 6.1.0, replaced by {@link #getPortalModelResources}
058             */
059            public static final String[] PORTAL_MODEL_RESOURCES =
060                    ResourceActions.PORTAL_MODEL_RESOURCES;
061    
062            public static void checkAction(String name, String actionId)
063                    throws NoSuchResourceActionException {
064    
065                    getResourceActions().checkAction(name, actionId);
066            }
067    
068            public static String getAction(Locale locale, String action) {
069                    return getResourceActions().getAction(locale, action);
070            }
071    
072            public static String getAction(PageContext pageContext, String action) {
073                    return getResourceActions().getAction(pageContext, action);
074            }
075    
076            public static String getActionNamePrefix() {
077                    return getResourceActions().getActionNamePrefix();
078            }
079    
080            public static List<String> getActionsNames(
081                    PageContext pageContext, List<String> actions) {
082    
083                    return getResourceActions().getActionsNames(pageContext, actions);
084            }
085    
086            public static List<String> getActionsNames(
087                    PageContext pageContext, String name, long actionIds) {
088    
089                    return getResourceActions().getActionsNames(
090                            pageContext, name, actionIds);
091            }
092    
093            public static List<String> getModelNames() {
094                    return getResourceActions().getModelNames();
095            }
096    
097            public static List<String> getModelPortletResources(String name) {
098                    return getResourceActions().getModelPortletResources(name);
099            }
100    
101            public static String getModelResource(Locale locale, String name) {
102                    return getResourceActions().getModelResource(locale, name);
103            }
104    
105            public static String getModelResource(
106                    PageContext pageContext, String name) {
107    
108                    return getResourceActions().getModelResource(pageContext, name);
109            }
110    
111            public static List<String> getModelResourceActions(String name) {
112                    return getResourceActions().getModelResourceActions(name);
113            }
114    
115            public static List<String> getModelResourceGroupDefaultActions(
116                    String name) {
117    
118                    return getResourceActions().getModelResourceGroupDefaultActions(name);
119            }
120    
121            public static List<String> getModelResourceGuestDefaultActions(
122                    String name) {
123    
124                    return getResourceActions().getModelResourceGuestDefaultActions(name);
125            }
126    
127            public static List<String> getModelResourceGuestUnsupportedActions(
128                    String name) {
129    
130                    return getResourceActions().getModelResourceGuestUnsupportedActions(
131                            name);
132            }
133    
134            public static String getModelResourceNamePrefix() {
135                    return getResourceActions().getModelResourceNamePrefix();
136            }
137    
138            public static List<String> getModelResourceOwnerDefaultActions(
139                    String name) {
140    
141                    return getResourceActions().getModelResourceOwnerDefaultActions(name);
142            }
143    
144            public static Double getModelResourceWeight(String name) {
145                    return getResourceActions().getModelResourceWeight(name);
146            }
147    
148            public static String[] getOrganizationModelResources() {
149                    return getResourceActions().getOrganizationModelResources();
150            }
151    
152            public static String[] getPortalModelResources() {
153                    return getResourceActions().getPortalModelResources();
154            }
155    
156            public static String getPortletBaseResource(String portletName) {
157                    return getResourceActions().getPortletBaseResource(portletName);
158            }
159    
160            public static List<String> getPortletModelResources(String portletName) {
161                    return getResourceActions().getPortletModelResources(portletName);
162            }
163    
164            public static List<String> getPortletNames() {
165                    return getResourceActions().getPortletNames();
166            }
167    
168            public static List<String> getPortletResourceActions(Portlet portlet) {
169                    return getResourceActions().getPortletResourceActions(portlet);
170            }
171    
172            public static List<String> getPortletResourceActions(String name) {
173                    return getResourceActions().getPortletResourceActions(name);
174            }
175    
176            public static List<String> getPortletResourceGroupDefaultActions(
177                    String name) {
178    
179                    return getResourceActions().getPortletResourceGroupDefaultActions(name);
180            }
181    
182            public static List<String> getPortletResourceGuestDefaultActions(
183                    String name) {
184    
185                    return getResourceActions().getPortletResourceGuestDefaultActions(name);
186            }
187    
188            public static List<String> getPortletResourceGuestUnsupportedActions(
189                    String name) {
190    
191                    return getResourceActions().getPortletResourceGuestUnsupportedActions(
192                            name);
193            }
194    
195            public static List<String> getPortletResourceLayoutManagerActions(
196                    String name) {
197    
198                    return getResourceActions().getPortletResourceLayoutManagerActions(
199                            name);
200            }
201    
202            public static String getPortletRootModelResource(String portletName) {
203                    return getResourceActions().getPortletRootModelResource(portletName);
204            }
205    
206            public static ResourceActions getResourceActions() {
207                    PortalRuntimePermission.checkGetBeanProperty(ResourceActionsUtil.class);
208    
209                    return _resourceActions;
210            }
211    
212            public static List<String> getResourceActions(String name) {
213                    return getResourceActions().getResourceActions(name);
214            }
215    
216            public static List<String> getResourceActions(
217                    String portletResource, String modelResource) {
218    
219                    return getResourceActions().getResourceActions(
220                            portletResource, modelResource);
221            }
222    
223            public static List<String> getResourceGroupDefaultActions(String name) {
224                    return getResourceActions().getResourceGroupDefaultActions(name);
225            }
226    
227            public static List<String> getResourceGuestUnsupportedActions(
228                    String portletResource, String modelResource) {
229    
230                    return getResourceActions().getResourceGuestUnsupportedActions(
231                            portletResource, modelResource);
232            }
233    
234            /**
235             * @deprecated As of 6.1.0, replaced by {@link #getRoles(long, Group,
236             *             String, int[])}
237             */
238            public static List<Role> getRoles(
239                            long companyId, Group group, String modelResource)
240                    throws SystemException {
241    
242                    return getResourceActions().getRoles(companyId, group, modelResource);
243            }
244    
245            public static List<Role> getRoles(
246                            long companyId, Group group, String modelResource, int[] roleTypes)
247                    throws SystemException {
248    
249                    return getResourceActions().getRoles(
250                            companyId, group, modelResource, roleTypes);
251            }
252    
253            public static boolean hasModelResourceActions(String name) {
254                    return getResourceActions().hasModelResourceActions(name);
255            }
256    
257            /**
258             * @deprecated As of 6.1.0
259             */
260            public static void init() {
261            }
262    
263            public static boolean isOrganizationModelResource(String modelResource) {
264                    return getResourceActions().isOrganizationModelResource(modelResource);
265            }
266    
267            public static boolean isPortalModelResource(String modelResource) {
268                    return getResourceActions().isPortalModelResource(modelResource);
269            }
270    
271            public static void read(
272                            String servletContextName, ClassLoader classLoader, String source)
273                    throws Exception {
274    
275                    getResourceActions().read(servletContextName, classLoader, source);
276            }
277    
278            public static void read(String servletContextName, InputStream inputStream)
279                    throws Exception {
280    
281                    getResourceActions().read(servletContextName, inputStream);
282            }
283    
284            public void setResourceActions(ResourceActions resourceActions) {
285                    PortalRuntimePermission.checkSetBeanProperty(getClass());
286    
287                    _resourceActions = resourceActions;
288            }
289    
290            private static ResourceActions _resourceActions;
291    
292    }