Source Code Cross Referenced for ResourceActionsUtil.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » security » permission » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.security.permission 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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