1 | package org.apache.pluto.driver.services.impl.resource; |
2 | |
3 | import java.util.HashMap; |
4 | import java.util.HashSet; |
5 | import java.util.Iterator; |
6 | import java.util.Map; |
7 | import java.util.Set; |
8 | |
9 | import javax.servlet.ServletContext; |
10 | |
11 | import org.apache.pluto.driver.config.DriverConfigurationException; |
12 | import org.apache.pluto.driver.services.portal.PortletApplicationConfig; |
13 | import org.apache.pluto.driver.services.portal.PortletRegistryService; |
14 | import org.apache.pluto.driver.services.portal.PortletWindowConfig; |
15 | import org.apache.pluto.driver.services.portal.admin.DriverAdministrationException; |
16 | import org.apache.pluto.driver.services.portal.admin.PortletRegistryAdminService; |
17 | |
18 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortalConfig; |
19 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletApplication; |
20 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletConfig; |
21 | import edu.iu.uis.sit.portal.portlet.admin.services.AdminService; |
22 | |
23 | public class OneStartPortletRegistryServiceImpl implements PortletRegistryService, PortletRegistryAdminService { |
24 | |
25 | private PortalConfig portalConfig; |
26 | |
27 | private ServletContext servletContext; |
28 | |
29 | private Map portletApplications; |
30 | |
31 | private AdminService adminService; |
32 | |
33 | public void init(ServletContext servletContext) throws DriverConfigurationException { |
34 | portletApplications = new HashMap(); |
35 | portalConfig = getAdminService().getPortalConfig(); |
36 | for (Iterator iter = portalConfig.getPortletApplications().iterator(); iter.hasNext();) { |
37 | PortletApplication application = (PortletApplication) iter.next(); |
38 | PortletApplicationConfig config = new PortletApplicationConfig(); |
39 | config.setContextPath(application.getContextPath()); |
40 | for (Iterator iterator = application.getPortletConfigs().iterator(); iterator.hasNext();) { |
41 | PortletConfig portletConfig = (PortletConfig) iterator.next(); |
42 | PortletWindowConfig portletWindowConfig = new PortletWindowConfig(); |
43 | portletWindowConfig.setContextPath(application.getContextPath()); |
44 | portletWindowConfig.setPortletName(portletConfig.getPortletName()); |
45 | config.addPortlet(portletWindowConfig); |
46 | } |
47 | portletApplications.put(application.getContextPath(), config); |
48 | } |
49 | } |
50 | |
51 | public void destroy() throws DriverConfigurationException {} |
52 | |
53 | |
54 | public Set getPortletApplications() { |
55 | return new HashSet(portletApplications.values()); |
56 | } |
57 | |
58 | public PortletApplicationConfig getPortletApplication(String id) { |
59 | return (PortletApplicationConfig)portletApplications.get(id); |
60 | } |
61 | |
62 | public PortletWindowConfig getPortlet(String id) { |
63 | if (id == null) { |
64 | return null; |
65 | } |
66 | |
67 | String context = PortletWindowConfig.parseContextPath(id); |
68 | String portlet = PortletWindowConfig.parsePortletName(id); |
69 | String portletId = PortletWindowConfig.parsePortletInstanceId(id); |
70 | |
71 | PortletApplicationConfig app = (PortletApplicationConfig) portletApplications.get(context); |
72 | if (app == null) { |
73 | return null; |
74 | } |
75 | |
76 | PortletWindowConfig config = app.getPortlet(portlet); |
77 | config.setPortletId(portletId); |
78 | return config; |
79 | } |
80 | |
81 | public AdminService getAdminService() { |
82 | return adminService; |
83 | } |
84 | |
85 | public void setAdminService(AdminService adminService) { |
86 | this.adminService = adminService; |
87 | } |
88 | |
89 | public void addPortletApplication(String portletContext) throws DriverAdministrationException { |
90 | throw new RuntimeException("OH CRAP! I pitty the fool that gets this exception!"); |
91 | } |
92 | |
93 | } |