1
14
15 package com.liferay.portal.security.permission;
16
17 import com.liferay.portal.kernel.exception.SystemException;
18 import com.liferay.portal.kernel.language.LanguageUtil;
19 import com.liferay.portal.kernel.log.Log;
20 import com.liferay.portal.kernel.log.LogFactoryUtil;
21 import com.liferay.portal.kernel.util.ContentTypes;
22 import com.liferay.portal.kernel.util.ListUtil;
23 import com.liferay.portal.kernel.util.PropsKeys;
24 import com.liferay.portal.kernel.util.StringPool;
25 import com.liferay.portal.kernel.util.StringUtil;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.kernel.xml.Document;
28 import com.liferay.portal.kernel.xml.Element;
29 import com.liferay.portal.kernel.xml.SAXReaderUtil;
30 import com.liferay.portal.model.Group;
31 import com.liferay.portal.model.Organization;
32 import com.liferay.portal.model.PasswordPolicy;
33 import com.liferay.portal.model.Permission;
34 import com.liferay.portal.model.Portlet;
35 import com.liferay.portal.model.PortletConstants;
36 import com.liferay.portal.model.ResourceAction;
37 import com.liferay.portal.model.Role;
38 import com.liferay.portal.model.RoleConstants;
39 import com.liferay.portal.model.User;
40 import com.liferay.portal.model.UserGroup;
41 import com.liferay.portal.service.PortletLocalServiceUtil;
42 import com.liferay.portal.service.ResourceActionLocalServiceUtil;
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.PropsUtil;
47 import com.liferay.portlet.PortletResourceBundles;
48 import com.liferay.portlet.expando.model.ExpandoColumn;
49 import com.liferay.util.UniqueList;
50
51 import java.io.IOException;
52
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.HashMap;
56 import java.util.HashSet;
57 import java.util.Iterator;
58 import java.util.List;
59 import java.util.Locale;
60 import java.util.Map;
61 import java.util.Set;
62
63 import javax.servlet.jsp.PageContext;
64
65
70 public class ResourceActionsUtil {
71
72 public static final String ACTION_NAME_PREFIX = "action.";
73
74 public static final String MODEL_RESOURCE_NAME_PREFIX = "model.resource.";
75
76 public static final String[] ORGANIZATION_MODEL_RESOURCES = {
77 Organization.class.getName(), PasswordPolicy.class.getName(),
78 User.class.getName()
79 };
80
81 public static final String[] PORTAL_MODEL_RESOURCES = {
82 ExpandoColumn.class.getName(), Organization.class.getName(),
83 PasswordPolicy.class.getName(), Role.class.getName(),
84 User.class.getName(), UserGroup.class.getName()
85 };
86
87 public static String getAction(Locale locale, String action) {
88 String key = ACTION_NAME_PREFIX + action;
89
90 String value = LanguageUtil.get(locale, key, null);
91
92 if ((value == null) || (value.equals(key))) {
93 value = PortletResourceBundles.getString(locale, key);
94 }
95
96 if (value == null) {
97 value = key;
98 }
99
100 return value;
101 }
102
103 public static String getAction(PageContext pageContext, String action) {
104 String key = ACTION_NAME_PREFIX + action;
105
106 String value = LanguageUtil.get(pageContext, key, null);
107
108 if ((value == null) || (value.equals(key))) {
109 value = PortletResourceBundles.getString(pageContext, key);
110 }
111
112 if (value == null) {
113 value = key;
114 }
115
116 return value;
117 }
118
119 public static List<String> getActions(List<Permission> permissions) {
120 List<String> actions = new UniqueList<String>();
121
122 for (Permission permission : permissions) {
123 actions.add(permission.getActionId());
124 }
125
126 return actions;
127 }
128
129 public static List<String> getActionsNames(
130 PageContext pageContext, List<String> actions) {
131
132 List<String> uniqueList = new UniqueList<String>();
133
134 for (String action : actions) {
135 uniqueList.add(getAction(pageContext, action));
136 }
137
138 List<String> list = new ArrayList<String>();
139
140 list.addAll(uniqueList);
141
142 return list;
143 }
144
145 public static List<String> getActionsNames(
146 PageContext pageContext, String name, long actionIds) {
147
148 try {
149 List<ResourceAction> resourceActions =
150 ResourceActionLocalServiceUtil.getResourceActions(name);
151
152 List<String> actions = new ArrayList<String>();
153
154 for (ResourceAction resourceAction : resourceActions) {
155 long bitwiseValue = resourceAction.getBitwiseValue();
156
157 if ((actionIds & bitwiseValue) == bitwiseValue) {
158 actions.add(resourceAction.getActionId());
159 }
160 }
161
162 return getActionsNames(pageContext, actions);
163 }
164 catch (Exception e) {
165 _log.error(e, e);
166
167 return Collections.EMPTY_LIST;
168 }
169 }
170
171 public static List<String> getModelNames() {
172 return _instance._getModelNames();
173 }
174
175 public static List<String> getModelPortletResources(String name) {
176 return _instance._getModelPortletResources(name);
177 }
178
179 public static String getModelResource(Locale locale, String name) {
180 String key = MODEL_RESOURCE_NAME_PREFIX + name;
181
182 String value = LanguageUtil.get(locale, key, null);
183
184 if ((value == null) || (value.equals(key))) {
185 value = PortletResourceBundles.getString(locale, key);
186 }
187
188 if (value == null) {
189 value = key;
190 }
191
192 return value;
193 }
194
195 public static String getModelResource(
196 PageContext pageContext, String name) {
197
198 String key = MODEL_RESOURCE_NAME_PREFIX + name;
199
200 String value = LanguageUtil.get(pageContext, key, null);
201
202 if ((value == null) || (value.equals(key))) {
203 value = PortletResourceBundles.getString(pageContext, key);
204 }
205
206 if (value == null) {
207 value = key;
208 }
209
210 return value;
211 }
212
213 public static List<String> getModelResourceActions(String name) {
214 return _instance._getModelResourceActions(name);
215 }
216
217 public static List<String> getModelResourceCommunityDefaultActions(
218 String name) {
219
220 return _instance._getModelResourceCommunityDefaultActions(name);
221 }
222
223 public static List<String> getModelResourceGuestDefaultActions(
224 String name) {
225
226 return _instance._getModelResourceGuestDefaultActions(name);
227 }
228
229 public static List<String> getModelResourceGuestUnsupportedActions(
230 String name) {
231
232 return _instance._getModelResourceGuestUnsupportedActions(name);
233 }
234
235 public static List<String> getModelResourceOwnerDefaultActions(
236 String name) {
237
238 return _instance._getModelResourceOwnerDefaultActions(name);
239 }
240
241 public static List<String> getPortletModelResources(String portletName) {
242 return _instance._getPortletModelResources(portletName);
243 }
244
245 public static List<String> getPortletNames() {
246 return _instance._getPortletNames();
247 }
248
249 public static List<String> getPortletResourceActions(String name) {
250 return _instance._getPortletResourceActions(name);
251 }
252
253 public static List<String> getPortletResourceCommunityDefaultActions(
254 String name) {
255
256 return _instance._getPortletResourceCommunityDefaultActions(name);
257 }
258
259 public static List<String> getPortletResourceGuestDefaultActions(
260 String name) {
261
262 return _instance._getPortletResourceGuestDefaultActions(name);
263 }
264
265 public static List<String> getPortletResourceGuestUnsupportedActions(
266 String name) {
267
268 return _instance._getPortletResourceGuestUnsupportedActions(name);
269 }
270
271 public static List<String> getPortletResourceLayoutManagerActions(
272 String name) {
273
274 return _instance._getPortletResourceLayoutManagerActions(name);
275 }
276
277 public static List<String> getResourceActions(String name) {
278 if (name.contains(StringPool.PERIOD)) {
279 return getModelResourceActions(name);
280 }
281 else {
282 return getPortletResourceActions(name);
283 }
284 }
285
286 public static List<String> getResourceActions(
287 String portletResource, String modelResource) {
288
289 List<String> actions = null;
290
291 if (Validator.isNull(modelResource)) {
292 actions = getPortletResourceActions(portletResource);
293 }
294 else {
295 actions = getModelResourceActions(modelResource);
296 }
297
298 return actions;
299 }
300
301 public static List<String> getResourceCommunityDefaultActions(String name) {
302 if (name.contains(StringPool.PERIOD)) {
303 return getModelResourceCommunityDefaultActions(name);
304 }
305 else {
306 return getPortletResourceCommunityDefaultActions(name);
307 }
308 }
309
310 public static List<String> getResourceGuestUnsupportedActions(
311 String portletResource, String modelResource) {
312
313 List<String> actions = null;
314
315 if (Validator.isNull(modelResource)) {
316 actions =
317 getPortletResourceGuestUnsupportedActions(portletResource);
318 }
319 else {
320 actions = getModelResourceGuestUnsupportedActions(modelResource);
321 }
322
323 return actions;
324 }
325
326 public static List<Role> getRoles(Group group, String modelResource)
327 throws SystemException {
328
329 List<Role> allRoles = RoleLocalServiceUtil.getRoles(
330 group.getCompanyId());
331
332 int[] types = new int[] {
333 RoleConstants.TYPE_REGULAR, RoleConstants.TYPE_COMMUNITY
334 };
335
336 if (isPortalModelResource(modelResource)) {
337 if (modelResource.equals(Organization.class.getName()) ||
338 modelResource.equals(User.class.getName())) {
339
340 types = new int[] {
341 RoleConstants.TYPE_REGULAR,
342 RoleConstants.TYPE_ORGANIZATION
343 };
344 }
345 else {
346 types = new int[] {RoleConstants.TYPE_REGULAR};
347 }
348 }
349 else {
350 if (group.isOrganization()) {
351 types = new int[] {
352 RoleConstants.TYPE_REGULAR,
353 RoleConstants.TYPE_ORGANIZATION
354 };
355 }
356 else if (group.isUser()) {
357 types = new int[] {RoleConstants.TYPE_REGULAR};
358 }
359 }
360
361 List<Role> roles = new ArrayList<Role>();
362
363 for (int type : types) {
364 for (Role role : allRoles) {
365 if (role.getType() == type) {
366 roles.add(role);
367 }
368 }
369 }
370
371 return roles;
372 }
373
374 public static void init() {
375 _instance._init();
376 }
377
378 public static boolean isOrganizationModelResource(String modelResource) {
379 return _instance._isOrganizationModelResource(modelResource);
380 }
381
382 public static boolean isPortalModelResource(String modelResource) {
383 return _instance._isPortalModelResource(modelResource);
384 }
385
386 public static void read(
387 String servletContextName, ClassLoader classLoader, String source)
388 throws Exception {
389
390 _instance._read(servletContextName, classLoader, source);
391 }
392
393 private ResourceActionsUtil() {
394 _organizationModelResources = new HashSet<String>();
395
396 for (int i = 0; i < ORGANIZATION_MODEL_RESOURCES.length; i++) {
397 _organizationModelResources.add(ORGANIZATION_MODEL_RESOURCES[i]);
398 }
399
400 _portalModelResources = new HashSet<String>();
401
402 for (int i = 0; i < PORTAL_MODEL_RESOURCES.length; i++) {
403 _portalModelResources.add(PORTAL_MODEL_RESOURCES[i]);
404 }
405
406 _portletModelResources = new HashMap<String, Set<String>>();
407 _portletResourceActions = new HashMap<String, List<String>>();
408 _portletResourceCommunityDefaultActions =
409 new HashMap<String, List<String>>();
410 _portletResourceGuestDefaultActions =
411 new HashMap<String, List<String>>();
412 _portletResourceGuestUnsupportedActions =
413 new HashMap<String, List<String>>();
414 _portletResourceLayoutManagerActions =
415 new HashMap<String, List<String>>();
416 _modelPortletResources = new HashMap<String, Set<String>>();
417 _modelResourceActions = new HashMap<String, List<String>>();
418 _modelResourceCommunityDefaultActions =
419 new HashMap<String, List<String>>();
420 _modelResourceGuestDefaultActions =
421 new HashMap<String, List<String>>();
422 _modelResourceGuestUnsupportedActions =
423 new HashMap<String, List<String>>();
424 _modelResourceOwnerDefaultActions =
425 new HashMap<String, List<String>>();
426
427 try {
428 ClassLoader classLoader = getClass().getClassLoader();
429
430 String[] configs = StringUtil.split(
431 PropsUtil.get(PropsKeys.RESOURCE_ACTIONS_CONFIGS));
432
433 for (int i = 0; i < configs.length; i++) {
434 _read(null, classLoader, configs[i]);
435 }
436 }
437 catch (Exception e) {
438 _log.error(e, e);
439 }
440 }
441
442 private void _checkGuestUnsupportedActions(
443 List<String> guestUnsupportedActions,
444 List<String> guestDefaultActions) {
445
446
448 Iterator<String> itr = guestDefaultActions.iterator();
449
450 while (itr.hasNext()) {
451 String actionId = itr.next();
452
453 if (guestUnsupportedActions.contains(actionId)) {
454 itr.remove();
455 }
456 }
457 }
458
459 private void _checkPortletActions(List<String> actions) {
460 if (!actions.contains(ActionKeys.ACCESS_IN_CONTROL_PANEL) &&
461 !actions.contains(ActionKeys.ADD_TO_PAGE)) {
462
463 actions.add(ActionKeys.ADD_TO_PAGE);
464 }
465
466 if (!actions.contains(ActionKeys.CONFIGURATION)) {
467 actions.add(ActionKeys.CONFIGURATION);
468 }
469
470 if (!actions.contains(ActionKeys.VIEW)) {
471 actions.add(ActionKeys.VIEW);
472 }
473 }
474
475 private void _checkPortletCommunityDefaultActions(List<String> actions) {
476 if (actions.size() == 0) {
477 actions.add(ActionKeys.VIEW);
478 }
479 }
480
481 private void _checkPortletGuestDefaultActions(List<String> actions) {
482 if (actions.size() == 0) {
483 actions.add(ActionKeys.VIEW);
484 }
485 }
486
487 private void _checkPortletLayoutManagerActions(List<String> actions) {
488 if (!actions.contains(ActionKeys.CONFIGURATION)) {
489 actions.add(ActionKeys.CONFIGURATION);
490 }
491
492 if (!actions.contains(ActionKeys.PREFERENCES)) {
493 actions.add(ActionKeys.PREFERENCES);
494 }
495
496 if (!actions.contains(ActionKeys.VIEW)) {
497 actions.add(ActionKeys.VIEW);
498 }
499 }
500
501 private List<String> _getActions(
502 Map<String, List<String>> map, String name) {
503
504 List<String> actions = map.get(name);
505
506 if (actions == null) {
507 actions = new UniqueList<String>();
508
509 map.put(name, actions);
510 }
511
512 return actions;
513 }
514
515 private List<String> _getModelNames() {
516 return ListUtil.fromCollection(_modelPortletResources.keySet());
517 }
518
519 private List<String> _getModelPortletResources(String name) {
520 Set<String> resources = _modelPortletResources.get(name);
521
522 if (resources == null) {
523 return new UniqueList<String>();
524 }
525 else {
526 return Collections.list(Collections.enumeration(resources));
527 }
528 }
529
530 private List<String> _getModelResourceActions(String name) {
531 return _getActions(_modelResourceActions, name);
532 }
533
534 private List<String> _getModelResourceCommunityDefaultActions(
535 String name) {
536
537 return _getActions(_modelResourceCommunityDefaultActions, name);
538 }
539
540 private List<String> _getModelResourceGuestDefaultActions(String name) {
541 return _getActions(_modelResourceGuestDefaultActions, name);
542 }
543
544 private List<String> _getModelResourceGuestUnsupportedActions(String name) {
545 return _getActions(_modelResourceGuestUnsupportedActions, name);
546 }
547
548 private List<String> _getModelResourceOwnerDefaultActions(String name) {
549 return _getActions(_modelResourceOwnerDefaultActions, name);
550 }
551
552 private List<String> _getPortletMimeTypeActions(String name) {
553 List<String> actions = new UniqueList<String>();
554
555 Portlet portlet = PortletLocalServiceUtil.getPortletById(name);
556
557 if (portlet != null) {
558 Map<String, Set<String>> portletModes =
559 portlet.getPortletModes();
560
561 Set<String> mimeTypePortletModes = portletModes.get(
562 ContentTypes.TEXT_HTML);
563
564 if (mimeTypePortletModes != null) {
565 for (String actionId : mimeTypePortletModes) {
566 if (actionId.equalsIgnoreCase("edit")) {
567 actions.add(ActionKeys.PREFERENCES);
568 }
569 else if (actionId.equalsIgnoreCase("edit_guest")) {
570 actions.add(ActionKeys.GUEST_PREFERENCES);
571 }
572 else {
573 actions.add(actionId.toUpperCase());
574 }
575 }
576 }
577 }
578 else {
579 if (_log.isDebugEnabled()) {
580 _log.debug(
581 "Unable to obtain resource actions for unknown portlet " +
582 name);
583 }
584 }
585
586 return actions;
587 }
588
589 private List<String> _getPortletModelResources(String portletName) {
590 portletName = PortletConstants.getRootPortletId(portletName);
591
592 Set<String> resources = _portletModelResources.get(portletName);
593
594 if (resources == null) {
595 return new UniqueList<String>();
596 }
597 else {
598 return Collections.list(Collections.enumeration(resources));
599 }
600 }
601
602 private List<String> _getPortletNames() {
603 return ListUtil.fromCollection(_portletModelResources.keySet());
604 }
605
606 private List<String> _getPortletResourceActions(String name) {
607 name = PortletConstants.getRootPortletId(name);
608
609 List<String> actions = _getActions(_portletResourceActions, name);
610
611 if (actions.size() == 0) {
612 synchronized (this) {
613 actions = _getPortletMimeTypeActions(name);
614
615 if (!name.equals(PortletKeys.PORTAL)) {
616 _checkPortletActions(actions);
617 }
618
619 List<String> communityDefaultActions =
620 _portletResourceCommunityDefaultActions.get(name);
621
622 if (communityDefaultActions == null) {
623 communityDefaultActions = new UniqueList<String>();
624
625 _portletResourceCommunityDefaultActions.put(
626 name, communityDefaultActions);
627
628 _checkPortletCommunityDefaultActions(
629 communityDefaultActions);
630 }
631
632 List<String> guestDefaultActions =
633 _portletResourceGuestDefaultActions.get(name);
634
635 if (guestDefaultActions == null) {
636 guestDefaultActions = new UniqueList<String>();
637
638 _portletResourceGuestDefaultActions.put(
639 name, guestDefaultActions);
640
641 _checkPortletGuestDefaultActions(guestDefaultActions);
642 }
643
644 List<String> layoutManagerActions =
645 _portletResourceLayoutManagerActions.get(name);
646
647 if (layoutManagerActions == null) {
648 layoutManagerActions = new UniqueList<String>();
649
650 _portletResourceLayoutManagerActions.put(
651 name, layoutManagerActions);
652
653 _checkPortletLayoutManagerActions(layoutManagerActions);
654 }
655 }
656 }
657
658 return actions;
659 }
660
661 private List<String> _getPortletResourceCommunityDefaultActions(
662 String name) {
663
664
671 name = PortletConstants.getRootPortletId(name);
672
673 return _getActions(_portletResourceCommunityDefaultActions, name);
674 }
675
676 private List<String> _getPortletResourceGuestDefaultActions(String name) {
677 name = PortletConstants.getRootPortletId(name);
678
679 return _getActions(_portletResourceGuestDefaultActions, name);
680 }
681
682 private List<String> _getPortletResourceGuestUnsupportedActions(
683 String name) {
684
685 name = PortletConstants.getRootPortletId(name);
686
687 return _getActions(_portletResourceGuestUnsupportedActions, name);
688 }
689
690 private List<String> _getPortletResourceLayoutManagerActions(String name) {
691 name = PortletConstants.getRootPortletId(name);
692
693 List<String> actions = _getActions(
694 _portletResourceLayoutManagerActions, name);
695
696
701 if (actions.size() < 1) {
702 actions.add(ActionKeys.CONFIGURATION);
703 actions.add(ActionKeys.PREFERENCES);
704 actions.add(ActionKeys.VIEW);
705 }
706
707 return actions;
708 }
709
710 private void _init() {
711 }
712
713 private boolean _isOrganizationModelResource(String modelResource) {
714 if (_organizationModelResources.contains(modelResource)) {
715 return true;
716 }
717 else {
718 return false;
719 }
720 }
721
722 private boolean _isPortalModelResource(String modelResource) {
723 if (_portalModelResources.contains(modelResource)) {
724 return true;
725 }
726 else {
727 return false;
728 }
729 }
730
731 private void _read(
732 String servletContextName, ClassLoader classLoader, String source)
733 throws Exception {
734
735 String xml = null;
736
737 try {
738 xml = StringUtil.read(classLoader, source);
739 }
740 catch (IOException ioe) {
741 if (_log.isWarnEnabled() && !source.endsWith("-ext.xml")) {
742 _log.warn("Cannot load " + source);
743 }
744 }
745 catch (Exception e) {
746 if (_log.isWarnEnabled()) {
747 _log.warn("Error reading " + source, e);
748 }
749 }
750
751 if (xml == null) {
752 return;
753 }
754
755 if (_log.isDebugEnabled()) {
756 _log.debug("Loading " + source);
757 }
758
759 Document doc = SAXReaderUtil.read(xml);
760
761 Element root = doc.getRootElement();
762
763 Iterator<Element> itr1 = root.elements("resource").iterator();
764
765 while (itr1.hasNext()) {
766 Element resource = itr1.next();
767
768 String file = resource.attributeValue("file");
769
770 _read(servletContextName, classLoader, file);
771
772 String extFile = StringUtil.replace(file, ".xml", "-ext.xml");
773
774 _read(servletContextName, classLoader, extFile);
775 }
776
777 itr1 = root.elements("portlet-resource").iterator();
778
779 while (itr1.hasNext()) {
780 Element resource = itr1.next();
781
782 String name = resource.elementText("portlet-name");
783
784 if (servletContextName != null) {
785 name =
786 name + PortletConstants.WAR_SEPARATOR + servletContextName;
787 }
788
789 name = PortalUtil.getJsSafePortletId(name);
790
791
793 List<String> actions = _getActions(_portletResourceActions, name);
794
795 Element supports = resource.element("supports");
796
797 Iterator<Element> itr2 = supports.elements("action-key").iterator();
798
799 while (itr2.hasNext()) {
800 Element actionKey = itr2.next();
801
802 String actionKeyText = actionKey.getText();
803
804 if (Validator.isNotNull(actionKeyText)) {
805 actions.add(actionKeyText);
806 }
807 }
808
809 actions.addAll(_getPortletMimeTypeActions(name));
810
811 if (!name.equals(PortletKeys.PORTAL)) {
812 _checkPortletActions(actions);
813 }
814
815
817 List<String> communityDefaultActions = _getActions(
818 _portletResourceCommunityDefaultActions, name);
819
820 Element communityDefaults = resource.element("community-defaults");
821
822 itr2 = communityDefaults.elements("action-key").iterator();
823
824 while (itr2.hasNext()) {
825 Element actionKey = itr2.next();
826
827 String actionKeyText = actionKey.getText();
828
829 if (Validator.isNotNull(actionKeyText)) {
830 communityDefaultActions.add(actionKeyText);
831 }
832 }
833
834
836 List<String> guestDefaultActions = _getActions(
837 _portletResourceGuestDefaultActions, name);
838
839 Element guestDefaults = resource.element("guest-defaults");
840
841 itr2 = guestDefaults.elements("action-key").iterator();
842
843 while (itr2.hasNext()) {
844 Element actionKey = itr2.next();
845
846 String actionKeyText = actionKey.getText();
847
848 if (Validator.isNotNull(actionKeyText)) {
849 guestDefaultActions.add(actionKeyText);
850 }
851 }
852
853
855 List<String> guestUnsupportedActions = _getActions(
856 _portletResourceGuestUnsupportedActions, name);
857
858 Element guestUnsupported = resource.element("guest-unsupported");
859
860 if (guestUnsupported != null) {
861 itr2 = guestUnsupported.elements("action-key").iterator();
862
863 while (itr2.hasNext()) {
864 Element actionKey = itr2.next();
865
866 String actionKeyText = actionKey.getText();
867
868 if (Validator.isNotNull(actionKeyText)) {
869 guestUnsupportedActions.add(actionKeyText);
870 }
871 }
872 }
873
874 _checkGuestUnsupportedActions(
875 guestUnsupportedActions, guestDefaultActions);
876
877
879 List<String> layoutManagerActions = _getActions(
880 _portletResourceLayoutManagerActions, name);
881
882 Element layoutManager = resource.element("layout-manager");
883
884 if (layoutManager != null) {
885 itr2 = layoutManager.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 layoutManagerActions.add(actionKeyText);
894 }
895 }
896 }
897 else {
898
899
902 layoutManagerActions.addAll(actions);
903 }
904 }
905
906 itr1 = root.elements("model-resource").iterator();
907
908 while (itr1.hasNext()) {
909 Element resource = itr1.next();
910
911 String name = resource.elementText("model-name");
912
913 Element portletRef = resource.element("portlet-ref");
914
915 Iterator<Element> itr2 = portletRef.elements(
916 "portlet-name").iterator();
917
918 while (itr2.hasNext()) {
919 Element portletName = itr2.next();
920
921 String portletNameString = portletName.getText();
922
923 if (servletContextName != null) {
924 portletNameString =
925 portletNameString + PortletConstants.WAR_SEPARATOR +
926 servletContextName;
927 }
928
929 portletNameString = PortalUtil.getJsSafePortletId(
930 portletNameString);
931
932
934 Set<String> modelResources = _portletModelResources.get(
935 portletNameString);
936
937 if (modelResources == null) {
938 modelResources = new HashSet<String>();
939
940 _portletModelResources.put(
941 portletNameString, modelResources);
942 }
943
944 modelResources.add(name);
945
946
948 Set<String> portletResources = _modelPortletResources.get(name);
949
950 if (portletResources == null) {
951 portletResources = new HashSet<String>();
952
953 _modelPortletResources.put(name, portletResources);
954 }
955
956 portletResources.add(portletNameString);
957 }
958
959
961 List<String> actions = _getActions(_modelResourceActions, name);
962
963 Element supports = resource.element("supports");
964
965 itr2 = supports.elements("action-key").iterator();
966
967 while (itr2.hasNext()) {
968 Element actionKey = itr2.next();
969
970 String actionKeyText = actionKey.getText();
971
972 if (Validator.isNotNull(actionKeyText)) {
973 actions.add(actionKeyText);
974 }
975 }
976
977
979 List<String> communityDefaultActions = _getActions(
980 _modelResourceCommunityDefaultActions, name);
981
982 Element communityDefaults = resource.element("community-defaults");
983
984 itr2 = communityDefaults.elements("action-key").iterator();
985
986 while (itr2.hasNext()) {
987 Element actionKey = itr2.next();
988
989 String actionKeyText = actionKey.getText();
990
991 if (Validator.isNotNull(actionKeyText)) {
992 communityDefaultActions.add(actionKeyText);
993 }
994 }
995
996
998 List<String> guestDefaultActions = _getActions(
999 _modelResourceGuestDefaultActions, name);
1000
1001 Element guestDefaults = resource.element("guest-defaults");
1002
1003 itr2 = guestDefaults.elements("action-key").iterator();
1004
1005 while (itr2.hasNext()) {
1006 Element actionKey = itr2.next();
1007
1008 String actionKeyText = actionKey.getText();
1009
1010 if (Validator.isNotNull(actionKeyText)) {
1011 guestDefaultActions.add(actionKeyText);
1012 }
1013 }
1014
1015
1017 List<String> guestUnsupportedActions = _getActions(
1018 _modelResourceGuestUnsupportedActions, name);
1019
1020 Element guestUnsupported = resource.element("guest-unsupported");
1021
1022 itr2 = guestUnsupported.elements("action-key").iterator();
1023
1024 while (itr2.hasNext()) {
1025 Element actionKey = itr2.next();
1026
1027 String actionKeyText = actionKey.getText();
1028
1029 if (Validator.isNotNull(actionKeyText)) {
1030 guestUnsupportedActions.add(actionKeyText);
1031 }
1032 }
1033
1034 _checkGuestUnsupportedActions(
1035 guestUnsupportedActions, guestDefaultActions);
1036
1037
1039 List<String> ownerDefaultActions = _getActions(
1040 _modelResourceOwnerDefaultActions, name);
1041
1042 Element ownerDefaults = resource.element("owner-defaults");
1043
1044 if (ownerDefaults != null) {
1045 itr2 = ownerDefaults.elements("action-key").iterator();
1046
1047 while (itr2.hasNext()) {
1048 Element actionKey = itr2.next();
1049
1050 String actionKeyText = actionKey.getText();
1051
1052 if (Validator.isNotNull(actionKeyText)) {
1053 ownerDefaultActions.add(actionKeyText);
1054 }
1055 }
1056 }
1057 }
1058 }
1059
1060 private static Log _log = LogFactoryUtil.getLog(ResourceActionsUtil.class);
1061
1062 private static ResourceActionsUtil _instance = new ResourceActionsUtil();
1063
1064 private Set<String> _organizationModelResources;
1065 private Set<String> _portalModelResources;
1066 private Map<String, Set<String>> _portletModelResources;
1067 private Map<String, List<String>> _portletResourceActions;
1068 private Map<String, List<String>> _portletResourceCommunityDefaultActions;
1069 private Map<String, List<String>> _portletResourceGuestDefaultActions;
1070 private Map<String, List<String>> _portletResourceGuestUnsupportedActions;
1071 private Map<String, List<String>> _portletResourceLayoutManagerActions;
1072 private Map<String, Set<String>> _modelPortletResources;
1073 private Map<String, List<String>> _modelResourceActions;
1074 private Map<String, List<String>> _modelResourceCommunityDefaultActions;
1075 private Map<String, List<String>> _modelResourceGuestDefaultActions;
1076 private Map<String, List<String>> _modelResourceGuestUnsupportedActions;
1077 private Map<String, List<String>> _modelResourceOwnerDefaultActions;
1078
1079}