1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.security.permission;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.language.LanguageUtil;
27  import com.liferay.portal.kernel.util.StringUtil;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portal.kernel.xml.Document;
30  import com.liferay.portal.kernel.xml.Element;
31  import com.liferay.portal.kernel.xml.SAXReaderUtil;
32  import com.liferay.portal.model.Group;
33  import com.liferay.portal.model.Location;
34  import com.liferay.portal.model.Organization;
35  import com.liferay.portal.model.PasswordPolicy;
36  import com.liferay.portal.model.Permission;
37  import com.liferay.portal.model.Portlet;
38  import com.liferay.portal.model.PortletConstants;
39  import com.liferay.portal.model.Role;
40  import com.liferay.portal.model.RoleConstants;
41  import com.liferay.portal.model.User;
42  import com.liferay.portal.model.UserGroup;
43  import com.liferay.portal.service.PortletLocalServiceUtil;
44  import com.liferay.portal.service.RoleLocalServiceUtil;
45  import com.liferay.portal.util.PortalUtil;
46  import com.liferay.portal.util.PortletKeys;
47  import com.liferay.portal.util.PropsKeys;
48  import com.liferay.portal.util.PropsUtil;
49  import com.liferay.portlet.PortletResourceBundles;
50  import com.liferay.util.UniqueList;
51  
52  import java.util.ArrayList;
53  import java.util.Collections;
54  import java.util.HashMap;
55  import java.util.HashSet;
56  import java.util.Iterator;
57  import java.util.List;
58  import java.util.Locale;
59  import java.util.Map;
60  import java.util.Set;
61  
62  import javax.servlet.jsp.PageContext;
63  
64  import org.apache.commons.logging.Log;
65  import org.apache.commons.logging.LogFactory;
66  
67  /**
68   * <a href="ResourceActionsUtil.java.html"><b><i>View Source</i></b></a>
69   *
70   * @author Brian Wing Shun Chan
71   *
72   */
73  public class ResourceActionsUtil {
74  
75      public static final String ACTION_NAME_PREFIX = "action.";
76  
77      public static final String MODEL_RESOURCE_NAME_PREFIX = "model.resource.";
78  
79      public static final String[] ORGANIZATION_MODEL_RESOURCES = {
80          Location.class.getName(), Organization.class.getName(),
81          PasswordPolicy.class.getName(), User.class.getName()
82      };
83  
84      public static final String[] PORTAL_MODEL_RESOURCES = {
85          Location.class.getName(), Organization.class.getName(),
86          PasswordPolicy.class.getName(), Role.class.getName(),
87          User.class.getName(), UserGroup.class.getName()
88      };
89  
90      public static String getAction(
91          long companyId, Locale locale, String action) {
92  
93          String key = ACTION_NAME_PREFIX + action;
94  
95          String value = LanguageUtil.get(companyId, locale, key, null);
96  
97          if ((value == null) || (value.equals(key))) {
98              value = PortletResourceBundles.getString(locale, key);
99          }
100 
101         if (value == null) {
102             value = key;
103         }
104 
105         return value;
106     }
107 
108     public static String getAction(PageContext pageContext, String action) {
109         String key = ACTION_NAME_PREFIX + action;
110 
111         String value = LanguageUtil.get(pageContext, key, null);
112 
113         if ((value == null) || (value.equals(key))) {
114             value = PortletResourceBundles.getString(pageContext, key);
115         }
116 
117         if (value == null) {
118             value = key;
119         }
120 
121         return value;
122     }
123 
124     public static List<String> getActions(List<Permission> permissions) {
125         List<String> actions = new UniqueList<String>();
126 
127         for (Permission permission : permissions) {
128             actions.add(permission.getActionId());
129         }
130 
131         return actions;
132     }
133 
134     public static List<String> getActionsNames(
135         PageContext pageContext, List<String> actions) {
136 
137         List<String> uniqueList = new UniqueList<String>();
138 
139         for (String action : actions) {
140             uniqueList.add(getAction(pageContext, action));
141         }
142 
143         List<String> list = new ArrayList<String>();
144 
145         list.addAll(uniqueList);
146 
147         Collections.sort(list);
148 
149         return list;
150     }
151 
152     public static List<String> getModelPortletResources(String name) {
153         return _instance._getModelPortletResources(name);
154     }
155 
156     public static String getModelResource(
157         long companyId, Locale locale, String name) {
158 
159         String key = MODEL_RESOURCE_NAME_PREFIX + name;
160 
161         String value = LanguageUtil.get(companyId, locale, key, null);
162 
163         if ((value == null) || (value.equals(key))) {
164             value = PortletResourceBundles.getString(locale, key);
165         }
166 
167         if (value == null) {
168             value = key;
169         }
170 
171         return value;
172     }
173 
174     public static String getModelResource(
175         PageContext pageContext, String name) {
176 
177         String key = MODEL_RESOURCE_NAME_PREFIX + name;
178 
179         String value = LanguageUtil.get(pageContext, key, null);
180 
181         if ((value == null) || (value.equals(key))) {
182             value = PortletResourceBundles.getString(pageContext, key);
183         }
184 
185         if (value == null) {
186             value = key;
187         }
188 
189         return value;
190     }
191 
192     public static List<String> getModelResourceActions(String name) {
193         return _instance._getModelResourceActions(name);
194     }
195 
196     public static List<String> getModelResourceCommunityDefaultActions(
197         String name) {
198 
199         return _instance._getModelResourceCommunityDefaultActions(name);
200     }
201 
202     public static List<String> getModelResourceGuestDefaultActions(
203         String name) {
204 
205         return _instance._getModelResourceGuestDefaultActions(name);
206     }
207 
208     public static List<String> getModelResourceGuestUnsupportedActions(
209         String name) {
210 
211         return _instance._getModelResourceGuestUnsupportedActions(name);
212     }
213 
214     public static List<String> getPortletModelResources(String portletName) {
215         return _instance._getPortletModelResources(portletName);
216     }
217 
218     public static List<String> getPortletResourceActions(
219             long companyId, String name)
220         throws SystemException {
221 
222         return _instance._getPortletResourceActions(companyId, name);
223     }
224 
225     public static List<String> getPortletResourceCommunityDefaultActions(
226         String name) {
227 
228         return _instance._getPortletResourceCommunityDefaultActions(name);
229     }
230 
231     public static List<String> getPortletResourceGuestDefaultActions(
232         String name) {
233 
234         return _instance._getPortletResourceGuestDefaultActions(name);
235     }
236 
237     public static List<String> getPortletResourceGuestUnsupportedActions(
238         String name) {
239 
240         return _instance._getPortletResourceGuestUnsupportedActions(name);
241     }
242 
243     public static List<String> getPortletResourceLayoutManagerActions(
244         String name) {
245 
246         return _instance._getPortletResourceLayoutManagerActions(name);
247     }
248 
249     public static List<String> getResourceActions(
250             long companyId, String portletResource, String modelResource)
251         throws SystemException {
252 
253         List<String> actions = null;
254 
255         if (Validator.isNull(modelResource)) {
256             actions = getPortletResourceActions(companyId, portletResource);
257         }
258         else {
259             actions = getModelResourceActions(modelResource);
260         }
261 
262         return actions;
263     }
264 
265     public static List<String> getResourceGuestUnsupportedActions(
266         String portletResource, String modelResource) {
267 
268         List<String> actions = null;
269 
270         if (Validator.isNull(modelResource)) {
271             actions =
272                 getPortletResourceGuestUnsupportedActions(portletResource);
273         }
274         else {
275             actions = getModelResourceGuestUnsupportedActions(modelResource);
276         }
277 
278         return actions;
279     }
280 
281     public static List<Role> getRoles(Group group, String modelResource)
282         throws SystemException {
283 
284         List<Role> allRoles = RoleLocalServiceUtil.getRoles(
285             group.getCompanyId());
286 
287         int[] types = new int[] {
288             RoleConstants.TYPE_REGULAR, RoleConstants.TYPE_COMMUNITY
289         };
290 
291         if (isPortalModelResource(modelResource)) {
292             types = new int[] {RoleConstants.TYPE_REGULAR};
293         }
294         else {
295             if (group.isOrganization()) {
296                 types = new int[] {
297                     RoleConstants.TYPE_REGULAR,
298                     RoleConstants.TYPE_ORGANIZATION
299                 };
300             }
301             else if (group.isUser()) {
302                 types = new int[] {RoleConstants.TYPE_REGULAR};
303             }
304         }
305 
306         List<Role> roles = new ArrayList<Role>();
307 
308         for (int type : types) {
309             for (Role role : allRoles) {
310                 if (role.getType() == type) {
311                     roles.add(role);
312                 }
313             }
314         }
315 
316         return roles;
317     }
318 
319     public static boolean isOrganizationModelResource(String modelResource) {
320         return _instance._isOrganizationModelResource(modelResource);
321     }
322 
323     public static boolean isPortalModelResource(String modelResource) {
324         return _instance._isPortalModelResource(modelResource);
325     }
326 
327     public static void read(
328             String servletContextName, ClassLoader classLoader, String source)
329         throws Exception {
330 
331         _instance._read(servletContextName, classLoader, source);
332     }
333 
334     private ResourceActionsUtil() {
335         _organizationModelResources = new HashSet<String>();
336 
337         for (int i = 0; i < ORGANIZATION_MODEL_RESOURCES.length; i++) {
338             _organizationModelResources.add(ORGANIZATION_MODEL_RESOURCES[i]);
339         }
340 
341         _portalModelResources = new HashSet<String>();
342 
343         for (int i = 0; i < PORTAL_MODEL_RESOURCES.length; i++) {
344             _portalModelResources.add(PORTAL_MODEL_RESOURCES[i]);
345         }
346 
347         _portletModelResources = new HashMap<String, Set<String>>();
348         _portletResourceActions = new HashMap<String, List<String>>();
349         _portletResourceCommunityDefaultActions =
350             new HashMap<String, List<String>>();
351         _portletResourceGuestDefaultActions =
352             new HashMap<String, List<String>>();
353         _portletResourceGuestUnsupportedActions =
354             new HashMap<String, List<String>>();
355         _portletResourceLayoutManagerActions =
356             new HashMap<String, List<String>>();
357         _modelPortletResources = new HashMap<String, Set<String>>();
358         _modelResourceActions = new HashMap<String, List<String>>();
359         _modelResourceCommunityDefaultActions =
360             new HashMap<String, List<String>>();
361         _modelResourceGuestDefaultActions =
362             new HashMap<String, List<String>>();
363         _modelResourceGuestUnsupportedActions =
364             new HashMap<String, List<String>>();
365 
366         try {
367             ClassLoader classLoader = getClass().getClassLoader();
368 
369             String[] configs = StringUtil.split(
370                 PropsUtil.get(PropsKeys.RESOURCE_ACTIONS_CONFIGS));
371 
372             for (int i = 0; i < configs.length; i++) {
373                 _read(null, classLoader, configs[i]);
374             }
375         }
376         catch (Exception e) {
377             _log.error(e, e);
378         }
379     }
380 
381     private void _checkGuestUnsupportedActions(
382         List<String> guestUnsupportedActions,
383         List<String> guestDefaultActions) {
384 
385         // Guest default actions cannot reference guest unsupported actions
386 
387         Iterator<String> itr = guestDefaultActions.iterator();
388 
389         while (itr.hasNext()) {
390             String actionId = itr.next();
391 
392             if (guestUnsupportedActions.contains(actionId)) {
393                 itr.remove();
394             }
395         }
396     }
397 
398     private void _checkPortletActions(List<String> actions) {
399         if (!actions.contains("CONFIGURATION")) {
400             actions.add("CONFIGURATION");
401         }
402 
403         if (!actions.contains("VIEW")) {
404             actions.add("VIEW");
405         }
406     }
407 
408     private void _checkPortletCommunityDefaultActions(List<String> actions) {
409         if (actions.size() == 0) {
410             actions.add("VIEW");
411         }
412     }
413 
414     private void _checkPortletGuestDefaultActions(List<String> actions) {
415         if (actions.size() == 0) {
416             actions.add("VIEW");
417         }
418     }
419 
420     private void _checkPortletLayoutManagerActions(List<String> actions) {
421         if (!actions.contains("CONFIGURATION")) {
422             actions.add("CONFIGURATION");
423         }
424 
425         if (!actions.contains("VIEW")) {
426             actions.add("VIEW");
427         }
428     }
429 
430     private List<String> _getActions(
431         Map<String, List<String>> map, String name) {
432 
433         List<String> actions = map.get(name);
434 
435         if (actions == null) {
436             actions = new UniqueList<String>();
437 
438             map.put(name, actions);
439         }
440 
441         return actions;
442     }
443 
444     private List<String> _getModelPortletResources(String name) {
445         Set<String> resources = _modelPortletResources.get(name);
446 
447         if (resources == null) {
448             return new UniqueList<String>();
449         }
450         else {
451             return Collections.list(Collections.enumeration(resources));
452         }
453     }
454 
455     private List<String> _getModelResourceActions(String name) {
456         return _getActions(_modelResourceActions, name);
457     }
458 
459     private List<String> _getModelResourceCommunityDefaultActions(
460         String name) {
461 
462         return _getActions(_modelResourceCommunityDefaultActions, name);
463     }
464 
465     private List<String> _getModelResourceGuestDefaultActions(String name) {
466         return _getActions(_modelResourceGuestDefaultActions, name);
467     }
468 
469     private List<String> _getModelResourceGuestUnsupportedActions(String name) {
470         return _getActions(_modelResourceGuestUnsupportedActions, name);
471     }
472 
473     private List<String> _getPortletModelResources(String portletName) {
474         portletName = PortletConstants.getRootPortletId(portletName);
475 
476         Set<String> resources = _portletModelResources.get(portletName);
477 
478         if (resources == null) {
479             return new UniqueList<String>();
480         }
481         else {
482             return Collections.list(Collections.enumeration(resources));
483         }
484     }
485 
486     private List<String> _getPortletResourceActions(long companyId, String name)
487         throws SystemException {
488 
489         name = PortletConstants.getRootPortletId(name);
490 
491         List<String> actions = _getActions(_portletResourceActions, name);
492 
493         if (actions.size() == 0) {
494             synchronized (this) {
495                 Portlet portlet = PortletLocalServiceUtil.getPortletById(
496                     companyId, name);
497 
498                 Map<String, Set<String>> portletModes =
499                     portlet.getPortletModes();
500 
501                 Set<String> mimeTypeModes = portletModes.get("text/html");
502 
503                 if (mimeTypeModes != null) {
504                     for (String actionId : mimeTypeModes) {
505                         if (actionId.equalsIgnoreCase("edit")) {
506                             actions.add(ActionKeys.PREFERENCES);
507                         }
508                         else if (actionId.equalsIgnoreCase("edit_guest")) {
509                             actions.add(ActionKeys.GUEST_PREFERENCES);
510                         }
511                         else {
512                             actions.add(actionId.toUpperCase());
513                         }
514                     }
515                 }
516 
517                 _checkPortletActions(actions);
518 
519                 List<String> communityDefaultActions =
520                     _portletResourceCommunityDefaultActions.get(name);
521 
522                 if (communityDefaultActions == null) {
523                     communityDefaultActions = new UniqueList<String>();
524 
525                     _portletResourceCommunityDefaultActions.put(
526                         name, communityDefaultActions);
527 
528                     _checkPortletCommunityDefaultActions(
529                         communityDefaultActions);
530                 }
531 
532                 List<String> guestDefaultActions =
533                     _portletResourceGuestDefaultActions.get(name);
534 
535                 if (guestDefaultActions == null) {
536                     guestDefaultActions = new UniqueList<String>();
537 
538                     _portletResourceGuestDefaultActions.put(
539                         name, guestDefaultActions);
540 
541                     _checkPortletGuestDefaultActions(guestDefaultActions);
542                 }
543 
544                 List<String> layoutManagerActions =
545                     _portletResourceLayoutManagerActions.get(name);
546 
547                 if (layoutManagerActions == null) {
548                     layoutManagerActions = new UniqueList<String>();
549 
550                     _portletResourceLayoutManagerActions.put(
551                         name, layoutManagerActions);
552 
553                     _checkPortletLayoutManagerActions(layoutManagerActions);
554                 }
555             }
556         }
557 
558         return actions;
559     }
560 
561     private List<String> _getPortletResourceCommunityDefaultActions(
562         String name) {
563 
564         // This method should always be called only after
565         // _getPortletResourceActions has been called at least once to
566         // populate the default community actions. Check to make sure this is
567         // the case. However, if it is not, that means the methods
568         // _getPortletResourceGuestDefaultActions and
569         // _getPortletResourceGuestDefaultActions may not work either.
570 
571         name = PortletConstants.getRootPortletId(name);
572 
573         return _getActions(_portletResourceCommunityDefaultActions, name);
574     }
575 
576     private List<String> _getPortletResourceGuestDefaultActions(String name) {
577         name = PortletConstants.getRootPortletId(name);
578 
579         return _getActions(_portletResourceGuestDefaultActions, name);
580     }
581 
582     private List<String> _getPortletResourceGuestUnsupportedActions(
583         String name) {
584 
585         name = PortletConstants.getRootPortletId(name);
586 
587         return _getActions(_portletResourceGuestUnsupportedActions, name);
588     }
589 
590     private List<String> _getPortletResourceLayoutManagerActions(String name) {
591         name = PortletConstants.getRootPortletId(name);
592 
593         List<String> actions = _getActions(
594             _portletResourceLayoutManagerActions, name);
595 
596         // This check can never return an empty list. If the list is empty, it
597         // means that the portlet does not have an explicit resource-actions
598         // configuration file and should therefore be handled as if it has
599         // defaults of CONFIGURATION, PREFERENCES, and VIEW.
600 
601         if (actions.size() < 1) {
602             actions.add("CONFIGURATION");
603             actions.add("PREFERENCES");
604             actions.add("VIEW");
605         }
606 
607         return actions;
608     }
609 
610     private boolean _isOrganizationModelResource(String modelResource) {
611         if (_organizationModelResources.contains(modelResource)) {
612             return true;
613         }
614         else {
615             return false;
616         }
617     }
618 
619     private boolean _isPortalModelResource(String modelResource) {
620         if (_portalModelResources.contains(modelResource)) {
621             return true;
622         }
623         else {
624             return false;
625         }
626     }
627 
628     private void _read(
629             String servletContextName, ClassLoader classLoader, String source)
630         throws Exception {
631 
632         String xml = null;
633 
634         try {
635             xml = StringUtil.read(classLoader, source);
636         }
637         catch (Exception e) {
638             _log.warn("Cannot load " + source);
639         }
640 
641         if (xml == null) {
642             return;
643         }
644 
645         if (_log.isDebugEnabled()) {
646             _log.debug("Loading " + source);
647         }
648 
649         Document doc = SAXReaderUtil.read(xml);
650 
651         Element root = doc.getRootElement();
652 
653         Iterator<Element> itr1 = root.elements("resource").iterator();
654 
655         while (itr1.hasNext()) {
656             Element resource = itr1.next();
657 
658             String file = resource.attributeValue("file");
659 
660             _read(servletContextName, classLoader, file);
661         }
662 
663         itr1 = root.elements("portlet-resource").iterator();
664 
665         while (itr1.hasNext()) {
666             Element resource = itr1.next();
667 
668             String name = resource.elementText("portlet-name");
669 
670             if (servletContextName != null) {
671                 name =
672                     name + PortletConstants.WAR_SEPARATOR + servletContextName;
673             }
674 
675             name = PortalUtil.getJsSafePortletId(name);
676 
677             // Actions
678 
679             List<String> actions = _getActions(_portletResourceActions, name);
680 
681             Element supports = resource.element("supports");
682 
683             Iterator<Element> itr2 = supports.elements("action-key").iterator();
684 
685             while (itr2.hasNext()) {
686                 Element actionKey = itr2.next();
687 
688                 String actionKeyText = actionKey.getText();
689 
690                 if (Validator.isNotNull(actionKeyText)) {
691                     actions.add(actionKeyText);
692                 }
693             }
694 
695             if (!name.equals(PortletKeys.PORTAL)) {
696                 _checkPortletActions(actions);
697             }
698 
699             // Community default actions
700 
701             List<String> communityDefaultActions =
702                 _getActions(_portletResourceCommunityDefaultActions, name);
703 
704             Element communityDefaults = resource.element("community-defaults");
705 
706             itr2 = communityDefaults.elements("action-key").iterator();
707 
708             while (itr2.hasNext()) {
709                 Element actionKey = itr2.next();
710 
711                 String actionKeyText = actionKey.getText();
712 
713                 if (Validator.isNotNull(actionKeyText)) {
714                     communityDefaultActions.add(actionKeyText);
715                 }
716             }
717 
718             // Guest default actions
719 
720             List<String> guestDefaultActions =
721                 _getActions(_portletResourceGuestDefaultActions, name);
722 
723             Element guestDefaults = resource.element("guest-defaults");
724 
725             itr2 = guestDefaults.elements("action-key").iterator();
726 
727             while (itr2.hasNext()) {
728                 Element actionKey = itr2.next();
729 
730                 String actionKeyText = actionKey.getText();
731 
732                 if (Validator.isNotNull(actionKeyText)) {
733                     guestDefaultActions.add(actionKeyText);
734                 }
735             }
736 
737             // Guest unsupported actions
738 
739             List<String> guestUnsupportedActions =
740                 _getActions(_portletResourceGuestUnsupportedActions, name);
741 
742             Element guestUnsupported = resource.element("guest-unsupported");
743 
744             itr2 = guestUnsupported.elements("action-key").iterator();
745 
746             while (itr2.hasNext()) {
747                 Element actionKey = itr2.next();
748 
749                 String actionKeyText = actionKey.getText();
750 
751                 if (Validator.isNotNull(actionKeyText)) {
752                     guestUnsupportedActions.add(actionKeyText);
753                 }
754             }
755 
756             _checkGuestUnsupportedActions(
757                 guestUnsupportedActions, guestDefaultActions);
758 
759             // Layout manager actions
760 
761             List<String> layoutManagerActions = _getActions(
762                 _portletResourceLayoutManagerActions, name);
763 
764             Element layoutManager = resource.element("layout-manager");
765 
766             if (layoutManager != null) {
767                 itr2 = layoutManager.elements("action-key").iterator();
768 
769                 while (itr2.hasNext()) {
770                     Element actionKey = itr2.next();
771 
772                     String actionKeyText = actionKey.getText();
773 
774                     if (Validator.isNotNull(actionKeyText)) {
775                         layoutManagerActions.add(actionKeyText);
776                     }
777                 }
778             }
779             else {
780 
781                 // Set the layout manager actions to contain all the portlet
782                 // resource actions if the element is not specified
783 
784                 layoutManagerActions.addAll(actions);
785             }
786         }
787 
788         itr1 = root.elements("model-resource").iterator();
789 
790         while (itr1.hasNext()) {
791             Element resource = itr1.next();
792 
793             String name = resource.elementText("model-name");
794 
795             Element portletRef = resource.element("portlet-ref");
796 
797             Iterator<Element> itr2 = portletRef.elements(
798                 "portlet-name").iterator();
799 
800             while (itr2.hasNext()) {
801                 Element portletName = itr2.next();
802 
803                 String portletNameString = portletName.getText();
804 
805                 if (servletContextName != null) {
806                     portletNameString =
807                         portletNameString + PortletConstants.WAR_SEPARATOR +
808                             servletContextName;
809                 }
810 
811                 portletNameString = PortalUtil.getJsSafePortletId(
812                     portletNameString);
813 
814                 // Reference for a portlet to child models
815 
816                 Set<String> modelResources = _portletModelResources.get(
817                     portletNameString);
818 
819                 if (modelResources == null) {
820                     modelResources = new HashSet<String>();
821 
822                     _portletModelResources.put(
823                         portletNameString, modelResources);
824                 }
825 
826                 modelResources.add(name);
827 
828                 // Reference for a model to parent portlets
829 
830                 Set<String> portletResources = _modelPortletResources.get(name);
831 
832                 if (portletResources == null) {
833                     portletResources = new HashSet<String>();
834 
835                     _modelPortletResources.put(name, portletResources);
836                 }
837 
838                 portletResources.add(portletNameString);
839             }
840 
841             // Actions
842 
843             List<String> actions = _getActions(_modelResourceActions, name);
844 
845             Element supports = resource.element("supports");
846 
847             itr2 = supports.elements("action-key").iterator();
848 
849             while (itr2.hasNext()) {
850                 Element actionKey = itr2.next();
851 
852                 String actionKeyText = actionKey.getText();
853 
854                 if (Validator.isNotNull(actionKeyText)) {
855                     actions.add(actionKeyText);
856                 }
857             }
858 
859             // Community default actions
860 
861             List<String> communityDefaultActions =
862                 _getActions(_modelResourceCommunityDefaultActions, name);
863 
864             Element communityDefaults = resource.element("community-defaults");
865 
866             itr2 = communityDefaults.elements("action-key").iterator();
867 
868             while (itr2.hasNext()) {
869                 Element actionKey = itr2.next();
870 
871                 String actionKeyText = actionKey.getText();
872 
873                 if (Validator.isNotNull(actionKeyText)) {
874                     communityDefaultActions.add(actionKeyText);
875                 }
876             }
877 
878             // Guest default actions
879 
880             List<String> guestDefaultActions =
881                 _getActions(_modelResourceGuestDefaultActions, name);
882 
883             Element guestDefaults = resource.element("guest-defaults");
884 
885             itr2 = guestDefaults.elements("action-key").iterator();
886 
887             while (itr2.hasNext()) {
888                 Element actionKey = itr2.next();
889 
890                 String actionKeyText = actionKey.getText();
891 
892                 if (Validator.isNotNull(actionKeyText)) {
893                     guestDefaultActions.add(actionKeyText);
894                 }
895             }
896 
897             // Guest unsupported actions
898 
899             List<String> guestUnsupportedActions =
900                 _getActions(_modelResourceGuestUnsupportedActions, name);
901 
902             Element guestUnsupported = resource.element("guest-unsupported");
903 
904             itr2 = guestUnsupported.elements("action-key").iterator();
905 
906             while (itr2.hasNext()) {
907                 Element actionKey = itr2.next();
908 
909                 String actionKeyText = actionKey.getText();
910 
911                 if (Validator.isNotNull(actionKeyText)) {
912                     guestUnsupportedActions.add(actionKeyText);
913                 }
914             }
915 
916             _checkGuestUnsupportedActions(
917                 guestUnsupportedActions, guestDefaultActions);
918         }
919     }
920 
921     private static Log _log = LogFactory.getLog(ResourceActionsUtil.class);
922 
923     private static ResourceActionsUtil _instance = new ResourceActionsUtil();
924 
925     private Set<String> _organizationModelResources;
926     private Set<String> _portalModelResources;
927     private Map<String, Set<String>> _portletModelResources;
928     private Map<String, List<String>> _portletResourceActions;
929     private Map<String, List<String>> _portletResourceCommunityDefaultActions;
930     private Map<String, List<String>> _portletResourceGuestDefaultActions;
931     private Map<String, List<String>> _portletResourceGuestUnsupportedActions;
932     private Map<String, List<String>> _portletResourceLayoutManagerActions;
933     private Map<String, Set<String>> _modelPortletResources;
934     private Map<String, List<String>> _modelResourceActions;
935     private Map<String, List<String>> _modelResourceCommunityDefaultActions;
936     private Map<String, List<String>> _modelResourceGuestDefaultActions;
937     private Map<String, List<String>> _modelResourceGuestUnsupportedActions;
938 
939 }