Source Code Cross Referenced for GetPortletsAction.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » layout » impl » 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 » jetspeed 2.1.3 » org.apache.jetspeed.layout.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.layout.impl;
018:
019:        import java.util.ArrayList;
020:        import java.util.Collection;
021:        import java.util.Collections;
022:        import java.util.Comparator;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Locale;
026:        import java.util.Map;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.apache.jetspeed.JetspeedActions;
031:        import org.apache.jetspeed.ajax.AjaxAction;
032:        import org.apache.jetspeed.ajax.AjaxBuilder;
033:        import org.apache.jetspeed.components.portletregistry.PortletRegistry;
034:        import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
035:        import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
036:        import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
037:        import org.apache.jetspeed.page.PageManager;
038:        import org.apache.jetspeed.request.RequestContext;
039:        import org.apache.jetspeed.search.ParsedObject;
040:        import org.apache.jetspeed.search.SearchEngine;
041:        import org.apache.jetspeed.security.SecurityAccessController;
042:        import org.apache.pluto.om.common.Parameter;
043:
044:        /**
045:         * Get Portlets retrieves the portlet list available to the current subject
046:         *
047:         * AJAX Parameters: 
048:         *    filter = (optional)filter to lookup portlets using fulltext search
049:         *    
050:         * @author <a>David Gurney</a>
051:         * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
052:         * @version $Id: $
053:         */
054:        public class GetPortletsAction extends BasePortletAction implements 
055:                AjaxAction, AjaxBuilder, Constants, Comparator {
056:            protected static final Log log = LogFactory
057:                    .getLog(GetPortletsAction.class);
058:            private PortletRegistry registry = null;
059:            private SearchEngine searchEngine = null;
060:            private SecurityAccessController securityAccessController;
061:
062:            public final static String PORTLET_ICON = "portlet-icon";
063:
064:            public GetPortletsAction(String template, String errorTemplate) {
065:                this (template, errorTemplate, null, null, null, null, null);
066:            }
067:
068:            public GetPortletsAction(String template, String errorTemplate,
069:                    PageManager pageManager, PortletRegistry registry,
070:                    SearchEngine searchEngine,
071:                    SecurityAccessController securityAccessController,
072:                    PortletActionSecurityBehavior securityBehavior) {
073:                super (template, errorTemplate, pageManager, securityBehavior);
074:                this .registry = registry;
075:                this .searchEngine = searchEngine;
076:                this .securityAccessController = securityAccessController;
077:            }
078:
079:            public boolean run(RequestContext requestContext, Map resultMap) {
080:                boolean success = true;
081:                String status = "success";
082:                try {
083:                    resultMap.put(ACTION, "getportlets");
084:                    if (false == checkAccess(requestContext,
085:                            JetspeedActions.VIEW)) {
086:                        //                if (!createNewPageOnEdit(requestContext))
087:                        //                {
088:                        success = false;
089:                        resultMap.put(REASON,
090:                                "Insufficient access to edit page");
091:                        return success;
092:                        //                }
093:                        //                status = "refresh";
094:                    }
095:                    String filter = getActionParameter(requestContext, FILTER);
096:                    List portlets = retrievePortlets(requestContext, filter);
097:                    resultMap.put(STATUS, status);
098:                    resultMap.put(PORTLETS, portlets);
099:                } catch (Exception e) {
100:                    // Log the exception
101:                    log.error("exception while getting portlet info", e);
102:
103:                    // Return a failure indicator
104:                    success = false;
105:                }
106:
107:                return success;
108:            }
109:
110:            public List retrievePortlets(RequestContext requestContext,
111:                    String filter) {
112:                Iterator portlets = null;
113:                List list = new ArrayList();
114:                Locale locale = requestContext.getLocale();
115:
116:                if (filter == null)
117:                    portlets = registry.getAllPortletDefinitions().iterator();
118:                else
119:                    portlets = searchEngine.search(filter).getResults()
120:                            .iterator();
121:
122:                while (portlets.hasNext()) {
123:                    PortletDefinitionComposite portlet = null;
124:                    if (filter == null)
125:                        portlet = (PortletDefinitionComposite) portlets.next();
126:                    else
127:                        portlet = this 
128:                                .getPortletFromParsedObject((ParsedObject) portlets
129:                                        .next());
130:
131:                    if (portlet == null)
132:                        continue;
133:
134:                    // Do not display Jetspeed Layout Applications
135:                    MutablePortletApplication pa = (MutablePortletApplication) portlet
136:                            .getPortletApplicationDefinition();
137:                    if (pa.isLayoutApplication())
138:                        continue;
139:
140:                    // SECURITY filtering
141:                    String uniqueName = pa.getName() + "::" + portlet.getName();
142:                    if (securityAccessController.checkPortletAccess(portlet,
143:                            JetspeedActions.MASK_VIEW)) {
144:                        Parameter param = portlet.getInitParameterSet().get(
145:                                PORTLET_ICON);
146:                        String image;
147:                        if (param != null) {
148:                            //String relativeImagePath = param.getValue();
149:                            //String context = muta.getWebApplicationDefinition().getContextRoot();
150:                            // Have to use a supported icon in jetspeed, otherwise image can be out of skew
151:                            image = "images/portlets/" + param.getValue();
152:                        } else {
153:                            image = "images/portlets/applications-internet.png";
154:                        }
155:                        list.add(new PortletInfo(uniqueName, portlet
156:                                .getDisplayNameText(locale), portlet
157:                                .getDescriptionText(locale), image));
158:                    }
159:                }
160:                Collections.sort(list, this );
161:                return list;
162:            }
163:
164:            protected PortletDefinitionComposite getPortletFromParsedObject(
165:                    ParsedObject po) {
166:                boolean found = false;
167:                String name = "";
168:                Map fields = po.getFields();
169:                if (fields != null) {
170:                    Object id = fields.get("ID");
171:
172:                    if (id != null) {
173:                        if (id instanceof  Collection) {
174:                            Collection coll = (Collection) id;
175:                            name = (String) coll.iterator().next();
176:                        } else {
177:                            name = (String) id;
178:                        }
179:                    }
180:
181:                    if (po.getType().equals("portlet")) {
182:                        Object pa = fields.get("portlet_application");
183:                        String paName = "";
184:                        if (pa != null) {
185:                            if (id instanceof  Collection) {
186:                                Collection coll = (Collection) pa;
187:                                paName = (String) coll.iterator().next();
188:                            } else {
189:                                paName = (String) pa;
190:                            }
191:                        }
192:                        name = paName + "::" + name;
193:                        found = true;
194:                    }
195:                }
196:                if (found == false)
197:                    return null;
198:
199:                return registry.getPortletDefinitionByUniqueName(name);
200:            }
201:
202:            public int compare(Object obj1, Object obj2) {
203:                PortletInfo portlet1 = (PortletInfo) obj1;
204:                PortletInfo portlet2 = (PortletInfo) obj2;
205:                String name1 = portlet1.getName();
206:                String name2 = portlet2.getName();
207:                name1 = (name1 == null) ? "unknown" : name1;
208:                name2 = (name2 == null) ? "unknown" : name2;
209:                return name1.compareTo(name2);
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.