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.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.model.Organization;
022    import com.liferay.portal.model.PasswordPolicy;
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> getActionsNames(
088                    PageContext pageContext, List<String> actions) {
089    
090                    return getResourceActions().getActionsNames(pageContext, actions);
091            }
092    
093            public static List<String> getActionsNames(
094                    PageContext pageContext, String name, long actionIds) {
095    
096                    return getResourceActions().getActionsNames(
097                            pageContext, name, actionIds);
098            }
099    
100            public static List<String> getModelNames() {
101                    return getResourceActions().getModelNames();
102            }
103    
104            public static List<String> getModelPortletResources(String name) {
105                    return getResourceActions().getModelPortletResources(name);
106            }
107    
108            public static String getModelResource(Locale locale, String name) {
109                    return getResourceActions().getModelResource(locale, name);
110            }
111    
112            public static String getModelResource(
113                    PageContext pageContext, String name) {
114    
115                    return getResourceActions().getModelResource(pageContext, name);
116            }
117    
118            public static List<String> getModelResourceActions(String name) {
119                    return getResourceActions().getModelResourceActions(name);
120            }
121    
122            public static List<String> getModelResourceGroupDefaultActions(
123                    String name) {
124    
125                    return getResourceActions().getModelResourceGroupDefaultActions(name);
126            }
127    
128            public static List<String> getModelResourceGuestDefaultActions(
129                    String name) {
130    
131                    return getResourceActions().getModelResourceGuestDefaultActions(name);
132            }
133    
134            public static List<String> getModelResourceGuestUnsupportedActions(
135                    String name) {
136    
137                    return getResourceActions().getModelResourceGuestUnsupportedActions(
138                            name);
139            }
140    
141            public static String getModelResourceNamePrefix() {
142                    return getResourceActions().getModelResourceNamePrefix();
143            }
144    
145            public static List<String> getModelResourceOwnerDefaultActions(
146                    String name) {
147    
148                    return getResourceActions().getModelResourceOwnerDefaultActions(name);
149            }
150    
151            public static String[] getOrganizationModelResources() {
152                    return getResourceActions().getOrganizationModelResources();
153            }
154    
155            public static String[] getPortalModelResources() {
156                    return getResourceActions().getPortalModelResources();
157            }
158    
159            public static String getPortletBaseResource(String portletName) {
160                    return getResourceActions().getPortletBaseResource(portletName);
161            }
162    
163            public static List<String> getPortletModelResources(String portletName) {
164                    return getResourceActions().getPortletModelResources(portletName);
165            }
166    
167            public static List<String> getPortletNames() {
168                    return getResourceActions().getPortletNames();
169            }
170    
171            public static List<String> getPortletResourceActions(Portlet portlet) {
172                    return getResourceActions().getPortletResourceActions(portlet);
173            }
174    
175            public static List<String> getPortletResourceActions(String name) {
176                    return getResourceActions().getPortletResourceActions(name);
177            }
178    
179            public static List<String> getPortletResourceGroupDefaultActions(
180                    String name) {
181    
182                    return getResourceActions().getPortletResourceGroupDefaultActions(name);
183            }
184    
185            public static List<String> getPortletResourceGuestDefaultActions(
186                    String name) {
187    
188                    return getResourceActions().getPortletResourceGuestDefaultActions(name);
189            }
190    
191            public static List<String> getPortletResourceGuestUnsupportedActions(
192                    String name) {
193    
194                    return getResourceActions().getPortletResourceGuestUnsupportedActions(
195                            name);
196            }
197    
198            public static List<String> getPortletResourceLayoutManagerActions(
199                    String name) {
200    
201                    return getResourceActions().getPortletResourceLayoutManagerActions(
202                            name);
203            }
204    
205            public static ResourceActions getResourceActions() {
206                    PortalRuntimePermission.checkGetBeanProperty(ResourceActionsUtil.class);
207    
208                    return _resourceActions;
209            }
210    
211            public static List<String> getResourceActions(String name) {
212                    return getResourceActions().getResourceActions(name);
213            }
214    
215            public static List<String> getResourceActions(
216                    String portletResource, String modelResource) {
217    
218                    return getResourceActions().getResourceActions(
219                            portletResource, modelResource);
220            }
221    
222            public static List<String> getResourceGroupDefaultActions(String name) {
223                    return getResourceActions().getResourceGroupDefaultActions(name);
224            }
225    
226            public static List<String> getResourceGuestUnsupportedActions(
227                    String portletResource, String modelResource) {
228    
229                    return getResourceActions().getResourceGuestUnsupportedActions(
230                            portletResource, modelResource);
231            }
232    
233            /**
234             * @deprecated {@link #getRoles(long, Group, String, int[])}
235             */
236            public static List<Role> getRoles(
237                            long companyId, Group group, String modelResource)
238                    throws SystemException {
239    
240                    return getResourceActions().getRoles(companyId, group, modelResource);
241            }
242    
243            public static List<Role> getRoles(
244                            long companyId, Group group, String modelResource, int[] roleTypes)
245                    throws SystemException {
246    
247                    return getResourceActions().getRoles(
248                            companyId, group, modelResource, roleTypes);
249            }
250    
251            public static boolean hasModelResourceActions(String name) {
252                    return getResourceActions().hasModelResourceActions(name);
253            }
254    
255            /**
256             * @deprecated
257             */
258            public static void init() {
259            }
260    
261            public static boolean isOrganizationModelResource(String modelResource) {
262                    return getResourceActions().isOrganizationModelResource(modelResource);
263            }
264    
265            public static boolean isPortalModelResource(String modelResource) {
266                    return getResourceActions().isPortalModelResource(modelResource);
267            }
268    
269            public static void read(
270                            String servletContextName, ClassLoader classLoader, String source)
271                    throws Exception {
272    
273                    getResourceActions().read(servletContextName, classLoader, source);
274            }
275    
276            public static void read(String servletContextName, InputStream inputStream)
277                    throws Exception {
278    
279                    getResourceActions().read(servletContextName, inputStream);
280            }
281    
282            public void setResourceActions(ResourceActions resourceActions) {
283                    PortalRuntimePermission.checkSetBeanProperty(getClass());
284    
285                    _resourceActions = resourceActions;
286            }
287    
288            private static ResourceActions _resourceActions;
289    
290    }