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