1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.security.permission;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.language.LanguageUtil;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.kernel.util.StringUtil;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.kernel.xml.Document;
29  import com.liferay.portal.kernel.xml.Element;
30  import com.liferay.portal.kernel.xml.SAXReaderUtil;
31  import com.liferay.portal.model.Group;
32  import com.liferay.portal.model.Location;
33  import com.liferay.portal.model.Organization;
34  import com.liferay.portal.model.PasswordPolicy;
35  import com.liferay.portal.model.Permission;
36  import com.liferay.portal.model.Portlet;
37  import com.liferay.portal.model.PortletConstants;
38  import com.liferay.portal.model.Role;
39  import com.liferay.portal.model.RoleConstants;
40  import com.liferay.portal.model.User;
41  import com.liferay.portal.model.UserGroup;
42  import com.liferay.portal.service.PortletLocalServiceUtil;
43  import com.liferay.portal.service.RoleLocalServiceUtil;
44  import com.liferay.portal.util.PortalUtil;
45  import com.liferay.portal.util.PortletKeys;
46  import com.liferay.portal.util.PropsKeys;
47  import com.liferay.portal.util.PropsUtil;
48  import com.liferay.portlet.PortletResourceBundles;
49  import com.liferay.util.UniqueList;
50  
51  import java.util.ArrayList;
52  import java.util.Collections;
53  import java.util.HashMap;
54  import java.util.HashSet;
55  import java.util.Iterator;
56  import java.util.List;
57  import java.util.Locale;
58  import java.util.Map;
59  import java.util.Set;
60  
61  import javax.servlet.jsp.PageContext;
62  
63  /**
64   * <a href="ResourceActionsUtil.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class ResourceActionsUtil {
70  
71      public static final String ACTION_NAME_PREFIX = "action.";
72  
73      public static final String MODEL_RESOURCE_NAME_PREFIX = "model.resource.";
74  
75      public static final String[] ORGANIZATION_MODEL_RESOURCES = {
76          Location.class.getName(), Organization.class.getName(),
77          PasswordPolicy.class.getName(), User.class.getName()
78      };
79  
80      public static final String[] PORTAL_MODEL_RESOURCES = {
81          Location.class.getName(), Organization.class.getName(),
82          PasswordPolicy.class.getName(), Role.class.getName(),
83          User.class.getName(), UserGroup.class.getName()
84      };
85  
86      public static String getAction(
87          long companyId, Locale locale, String action) {
88  
89          String key = ACTION_NAME_PREFIX + action;
90  
91          String value = LanguageUtil.get(companyId, locale, key, null);
92  
93          if ((value == null) || (value.equals(key))) {
94              value = PortletResourceBundles.getString(locale, key);
95          }
96  
97          if (value == null) {
98              value = key;
99          }
100 
101         return value;
102     }
103 
104     public static String getAction(PageContext pageContext, String action) {
105         String key = ACTION_NAME_PREFIX + action;
106 
107         String value = LanguageUtil.get(pageContext, key, null);
108 
109         if ((value == null) || (value.equals(key))) {
110             value = PortletResourceBundles.getString(pageContext, key);
111         }
112 
113         if (value == null) {
114             value = key;
115         }
116 
117         return value;
118     }
119 
120     public static List<String> getActions(List<Permission> permissions) {
121         List<String> actions = new UniqueList<String>();
122 
123         for (Permission permission : permissions) {
124             actions.add(permission.getActionId());
125         }
126 
127         return actions;
128     }
129 
130     public static List<String> getActionsNames(
131         PageContext pageContext, List<String> actions) {
132 
133         List<String> uniqueList = new UniqueList<String>();
134 
135         for (String action : actions) {
136             uniqueList.add(getAction(pageContext, action));
137         }
138 
139         List<String> list = new ArrayList<String>();
140 
141         list.addAll(uniqueList);
142 
143         Collections.sort(list);
144 
145         return list;
146     }
147 
148     public static List<String> getModelPortletResources(String name) {
149         return _instance._getModelPortletResources(name);
150     }
151 
152     public static String getModelResource(
153         long companyId, Locale locale, String name) {
154 
155         String key = MODEL_RESOURCE_NAME_PREFIX + name;
156 
157         String value = LanguageUtil.get(companyId, locale, key, null);
158 
159         if ((value == null) || (value.equals(key))) {
160             value = PortletResourceBundles.getString(locale, key);
161         }
162 
163         if (value == null) {
164             value = key;
165         }
166 
167         return value;
168     }
169 
170     public static String getModelResource(
171         PageContext pageContext, String name) {
172 
173         String key = MODEL_RESOURCE_NAME_PREFIX + name;
174 
175         String value = LanguageUtil.get(pageContext, key, null);
176 
177         if ((value == null) || (value.equals(key))) {
178             value = PortletResourceBundles.getString(pageContext, key);
179         }
180 
181         if (value == null) {
182             value = key;
183         }
184 
185         return value;
186     }
187 
188     public static List<String> getModelResourceActions(String name) {
189         return _instance._getModelResourceActions(name);
190     }
191 
192     public static List<String> getModelResourceCommunityDefaultActions(
193         String name) {
194 
195         return _instance._getModelResourceCommunityDefaultActions(name);
196     }
197 
198     public static List<String> getModelResourceGuestDefaultActions(
199         String name) {
200 
201         return _instance._getModelResourceGuestDefaultActions(name);
202     }
203 
204     public static List<String> getModelResourceGuestUnsupportedActions(
205         String name) {
206 
207         return _instance._getModelResourceGuestUnsupportedActions(name);
208     }
209 
210     public static List<String> getPortletModelResources(String portletName) {
211         return _instance._getPortletModelResources(portletName);
212     }
213 
214     public static List<String> getPortletResourceActions(
215             long companyId, String name)
216         throws SystemException {
217 
218         return _instance._getPortletResourceActions(companyId, name);
219     }
220 
221     public static List<String> getPortletResourceCommunityDefaultActions(
222         String name) {
223 
224         return _instance._getPortletResourceCommunityDefaultActions(name);
225     }
226 
227     public static List<String> getPortletResourceGuestDefaultActions(
228         String name) {
229 
230         return _instance._getPortletResourceGuestDefaultActions(name);
231     }
232 
233     public static List<String> getPortletResourceGuestUnsupportedActions(
234         String name) {
235 
236         return _instance._getPortletResourceGuestUnsupportedActions(name);
237     }
238 
239     public static List<String> getPortletResourceLayoutManagerActions(
240         String name) {
241 
242         return _instance._getPortletResourceLayoutManagerActions(name);
243     }
244 
245     public static List<String> getResourceActions(
246             long companyId, String portletResource, String modelResource)
247         throws SystemException {
248 
249         List<String> actions = null;
250 
251         if (Validator.isNull(modelResource)) {
252             actions = getPortletResourceActions(companyId, portletResource);
253         }
254         else {
255             actions = getModelResourceActions(modelResource);
256         }
257 
258         return actions;
259     }
260 
261     public static List<String> getResourceGuestUnsupportedActions(
262         String portletResource, String modelResource) {
263 
264         List<String> actions = null;
265 
266         if (Validator.isNull(modelResource)) {
267             actions =
268                 getPortletResourceGuestUnsupportedActions(portletResource);
269         }
270         else {
271             actions = getModelResourceGuestUnsupportedActions(modelResource);
272         }
273 
274         return actions;
275     }
276 
277     public static List<Role> getRoles(Group group, String modelResource)
278         throws SystemException {
279 
280         List<Role> allRoles = RoleLocalServiceUtil.getRoles(
281             group.getCompanyId());
282 
283         int[] types = new int[] {
284             RoleConstants.TYPE_REGULAR, RoleConstants.TYPE_COMMUNITY
285         };
286 
287         if (isPortalModelResource(modelResource)) {
288             types = new int[] {RoleConstants.TYPE_REGULAR};
289         }
290         else {
291             if (group.isOrganization()) {
292                 types = new int[] {
293                     RoleConstants.TYPE_REGULAR,
294                     RoleConstants.TYPE_ORGANIZATION
295                 };
296             }
297             else if (group.isUser()) {
298                 types = new int[] {RoleConstants.TYPE_REGULAR};
299             }
300         }
301 
302         List<Role> roles = new ArrayList<Role>();
303 
304         for (int type : types) {
305             for (Role role : allRoles) {
306                 if (role.getType() == type) {
307                     roles.add(role);
308                 }
309             }
310         }
311 
312         return roles;
313     }
314 
315     public static boolean isOrganizationModelResource(String modelResource) {
316         return _instance._isOrganizationModelResource(modelResource);
317     }
318 
319     public static boolean isPortalModelResource(String modelResource) {
320         return _instance._isPortalModelResource(modelResource);
321     }
322 
323     public static void read(
324             String servletContextName, ClassLoader classLoader, String source)
325         throws Exception {
326 
327         _instance._read(servletContextName, classLoader, source);
328     }
329 
330     private ResourceActionsUtil() {
331         _organizationModelResources = new HashSet<String>();
332 
333         for (int i = 0; i < ORGANIZATION_MODEL_RESOURCES.length; i++) {
334             _organizationModelResources.add(ORGANIZATION_MODEL_RESOURCES[i]);
335         }
336 
337         _portalModelResources = new HashSet<String>();
338 
339         for (int i = 0; i < PORTAL_MODEL_RESOURCES.length; i++) {
340             _portalModelResources.add(PORTAL_MODEL_RESOURCES[i]);
341         }
342 
343         _portletModelResources = new HashMap<String, Set<String>>();
344         _portletResourceActions = new HashMap<String, List<String>>();
345         _portletResourceCommunityDefaultActions =
346             new HashMap<String, List<String>>();
347         _portletResourceGuestDefaultActions =
348             new HashMap<String, List<String>>();
349         _portletResourceGuestUnsupportedActions =
350             new HashMap<String, List<String>>();
351         _portletResourceLayoutManagerActions =
352             new HashMap<String, List<String>>();
353         _modelPortletResources = new HashMap<String, Set<String>>();
354         _modelResourceActions = new HashMap<String, List<String>>();
355         _modelResourceCommunityDefaultActions =
356             new HashMap<String, List<String>>();
357         _modelResourceGuestDefaultActions =
358             new HashMap<String, List<String>>();
359         _modelResourceGuestUnsupportedActions =
360             new HashMap<String, List<String>>();
361 
362         try {
363             ClassLoader classLoader = getClass().getClassLoader();
364 
365             String[] configs = StringUtil.split(
366                 PropsUtil.get(PropsKeys.RESOURCE_ACTIONS_CONFIGS));
367 
368             for (int i = 0; i < configs.length; i++) {
369                 _read(null, classLoader, configs[i]);
370             }
371         }
372         catch (Exception e) {
373             _log.error(e, e);
374         }
375     }
376 
377     private void _checkGuestUnsupportedActions(
378         List<String> guestUnsupportedActions,
379         List<String> guestDefaultActions) {
380 
381         // Guest default actions cannot reference guest unsupported actions
382 
383         Iterator<String> itr = guestDefaultActions.iterator();
384 
385         while (itr.hasNext()) {
386             String actionId = itr.next();
387 
388             if (guestUnsupportedActions.contains(actionId)) {
389                 itr.remove();
390             }
391         }
392     }
393 
394     private void _checkPortletActions(List<String> actions) {
395         if (!actions.contains("CONFIGURATION")) {
396             actions.add("CONFIGURATION");
397         }
398 
399         if (!actions.contains("VIEW")) {
400             actions.add("VIEW");
401         }
402     }
403 
404     private void _checkPortletCommunityDefaultActions(List<String> actions) {
405         if (actions.size() == 0) {
406             actions.add("VIEW");
407         }
408     }
409 
410     private void _checkPortletGuestDefaultActions(List<String> actions) {
411         if (actions.size() == 0) {
412             actions.add("VIEW");
413         }
414     }
415 
416     private void _checkPortletLayoutManagerActions(List<String> actions) {
417         if (!actions.contains("CONFIGURATION")) {
418             actions.add("CONFIGURATION");
419         }
420 
421         if (!actions.contains("PREFERENCES")) {
422             actions.add("PREFERENCES");
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 = LogFactoryUtil.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 }