001    /**
002     * Copyright (c) 2000-2012 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.model.Group;
020    import com.liferay.portal.model.Organization;
021    import com.liferay.portal.model.PasswordPolicy;
022    import com.liferay.portal.model.Permission;
023    import com.liferay.portal.model.Portlet;
024    import com.liferay.portal.model.Role;
025    import com.liferay.portal.model.User;
026    import com.liferay.portal.model.UserGroup;
027    import com.liferay.portlet.expando.model.ExpandoColumn;
028    
029    import java.io.InputStream;
030    
031    import java.util.List;
032    import java.util.Locale;
033    
034    import javax.servlet.jsp.PageContext;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     * @author Daeyoung Song
039     */
040    public class ResourceActionsUtil {
041    
042            /**
043             * @deprecated {@link #getActionNamePrefix}
044             */
045            public static final String ACTION_NAME_PREFIX = "action.";
046    
047            /**
048             * @deprecated {@link #getModelResourceNamePrefix}
049             */
050            public static final String MODEL_RESOURCE_NAME_PREFIX = "model.resource.";
051    
052            /**
053             * @deprecated {@link #getOrganizationModelResources}
054             */
055            public static final String[] ORGANIZATION_MODEL_RESOURCES = {
056                    Organization.class.getName(), PasswordPolicy.class.getName(),
057                    User.class.getName()
058            };
059    
060            /**
061             * @deprecated {@link #getPortalModelResources}
062             */
063            public static final String[] PORTAL_MODEL_RESOURCES = {
064                    ExpandoColumn.class.getName(), Organization.class.getName(),
065                    PasswordPolicy.class.getName(), Role.class.getName(),
066                    User.class.getName(), UserGroup.class.getName()
067            };
068    
069            public static void checkAction(String name, String actionId)
070                    throws NoSuchResourceActionException {
071    
072                    getResourceActions().checkAction(name, actionId);
073            }
074    
075            public static String getAction(Locale locale, String action) {
076                    return getResourceActions().getAction(locale, action);
077            }
078    
079            public static String getAction(PageContext pageContext, String action) {
080                    return getResourceActions().getAction(pageContext, action);
081            }
082    
083            public static String getActionNamePrefix() {
084                    return getResourceActions().getActionNamePrefix();
085            }
086    
087            public static List<String> getActions(List<Permission> permissions) {
088                    return getResourceActions().getActions(permissions);
089            }
090    
091            public static List<String> getActionsNames(
092                    PageContext pageContext, List<String> actions) {
093    
094                    return getResourceActions().getActionsNames(pageContext, actions);
095            }
096    
097            public static List<String> getActionsNames(
098                    PageContext pageContext, String name, long actionIds) {
099    
100                    return getResourceActions().getActionsNames(
101                            pageContext, name, actionIds);
102            }
103    
104            public static List<String> getModelNames() {
105                    return getResourceActions().getModelNames();
106            }
107    
108            public static List<String> getModelPortletResources(String name) {
109                    return getResourceActions().getModelPortletResources(name);
110            }
111    
112            public static String getModelResource(Locale locale, String name) {
113                    return getResourceActions().getModelResource(locale, name);
114            }
115    
116            public static String getModelResource(
117                    PageContext pageContext, String name) {
118    
119                    return getResourceActions().getModelResource(pageContext, name);
120            }
121    
122            public static List<String> getModelResourceActions(String name) {
123                    return getResourceActions().getModelResourceActions(name);
124            }
125    
126            public static List<String> getModelResourceGroupDefaultActions(
127                    String name) {
128    
129                    return getResourceActions().getModelResourceGroupDefaultActions(name);
130            }
131    
132            public static List<String> getModelResourceGuestDefaultActions(
133                    String name) {
134    
135                    return getResourceActions().getModelResourceGuestDefaultActions(name);
136            }
137    
138            public static List<String> getModelResourceGuestUnsupportedActions(
139                    String name) {
140    
141                    return getResourceActions().getModelResourceGuestUnsupportedActions(
142                            name);
143            }
144    
145            public static String getModelResourceNamePrefix() {
146                    return getResourceActions().getModelResourceNamePrefix();
147            }
148    
149            public static List<String> getModelResourceOwnerDefaultActions(
150                    String name) {
151    
152                    return getResourceActions().getModelResourceOwnerDefaultActions(name);
153            }
154    
155            public static String[] getOrganizationModelResources() {
156                    return getResourceActions().getOrganizationModelResources();
157            }
158    
159            public static String[] getPortalModelResources() {
160                    return getResourceActions().getPortalModelResources();
161            }
162    
163            public static String getPortletBaseResource(String portletName) {
164                    return getResourceActions().getPortletBaseResource(portletName);
165            }
166    
167            public static List<String> getPortletModelResources(String portletName) {
168                    return getResourceActions().getPortletModelResources(portletName);
169            }
170    
171            public static List<String> getPortletNames() {
172                    return getResourceActions().getPortletNames();
173            }
174    
175            public static List<String> getPortletResourceActions(Portlet portlet) {
176                    return getResourceActions().getPortletResourceActions(portlet);
177            }
178    
179            public static List<String> getPortletResourceActions(String name) {
180                    return getResourceActions().getPortletResourceActions(name);
181            }
182    
183            public static List<String> getPortletResourceGroupDefaultActions(
184                    String name) {
185    
186                    return getResourceActions().getPortletResourceGroupDefaultActions(name);
187            }
188    
189            public static List<String> getPortletResourceGuestDefaultActions(
190                    String name) {
191    
192                    return getResourceActions().getPortletResourceGuestDefaultActions(name);
193            }
194    
195            public static List<String> getPortletResourceGuestUnsupportedActions(
196                    String name) {
197    
198                    return getResourceActions().getPortletResourceGuestUnsupportedActions(
199                            name);
200            }
201    
202            public static List<String> getPortletResourceLayoutManagerActions(
203                    String name) {
204    
205                    return getResourceActions().getPortletResourceLayoutManagerActions(
206                            name);
207            }
208    
209            public static ResourceActions getResourceActions() {
210                    return _resourceActions;
211            }
212    
213            public static List<String> getResourceActions(String name) {
214                    return getResourceActions().getResourceActions(name);
215            }
216    
217            public static List<String> getResourceActions(
218                    String portletResource, String modelResource) {
219    
220                    return getResourceActions().getResourceActions(
221                            portletResource, modelResource);
222            }
223    
224            public static List<String> getResourceGroupDefaultActions(String name) {
225                    return getResourceActions().getResourceGroupDefaultActions(name);
226            }
227    
228            public static List<String> getResourceGuestUnsupportedActions(
229                    String portletResource, String modelResource) {
230    
231                    return getResourceActions().getResourceGuestUnsupportedActions(
232                            portletResource, modelResource);
233            }
234    
235            /**
236             * @deprecated {@link #getRoles(long, Group, 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
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                    _resourceActions = resourceActions;
286            }
287    
288            private static ResourceActions _resourceActions;
289    
290    }