KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > PortletApplicationsHolder


1 package org.exoplatform.services.portletcontainer.impl;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import javax.portlet.PortletMode;
11 import javax.portlet.WindowState;
12
13 import org.apache.commons.logging.Log;
14 import org.exoplatform.Constants;
15 import org.exoplatform.services.log.LogService;
16 import org.exoplatform.services.portletcontainer.pci.model.*;
17
18
19 /**
20  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
21  * Please look at license.txt in info directory for more license detail.
22  **/

23
24 /**
25  * Created by the Exo Development team.
26  * Author : Mestrallet Benjamin
27  * benjmestrallet@users.sourceforge.net
28  * Date: 11 nov. 2003
29  * Time: 14:47:22
30  */

31 public class PortletApplicationsHolder {
32
33   private Map JavaDoc portletApps;
34   private Log log;
35
36   public PortletApplicationsHolder(LogService logService) {
37     this.portletApps = new HashMap JavaDoc();
38     this.log = logService.getLog("org.exoplatform.services.portletcontainer");
39   }
40   
41   public void start() {
42   
43   }
44   
45   public void stop() {
46     
47   }
48   
49   public PortletApp getPortletApplication(String JavaDoc portletAppName) {
50     PortletApplicationHelper helper = (PortletApplicationHelper) portletApps.get(portletAppName);
51     if(helper == null) {
52       log.debug("Portlet application : " + portletAppName + " does not exist");
53       return null;
54     }
55     return helper.getPortletApp();
56   }
57
58   public Collection JavaDoc getRoles(String JavaDoc portletAppName) {
59     log.debug("getRoles() entered");
60     PortletApplicationHelper helper = (PortletApplicationHelper) portletApps.get(portletAppName);
61     return helper.getRoles();
62   }
63
64   public Map JavaDoc getAllPortletMetaData() {
65     log.debug("getAllPortletMetaData() entered");
66     HashMap JavaDoc all = new HashMap JavaDoc(20);
67     Collection JavaDoc applicationsKeys = portletApps.keySet();
68     Iterator JavaDoc iterator = applicationsKeys.iterator();
69     while (iterator.hasNext()) {
70       String JavaDoc key = (String JavaDoc) iterator.next();
71       PortletApplicationHelper helper = (PortletApplicationHelper) portletApps.get(key);
72       PortletApp pA = helper.getPortletApp();
73       List JavaDoc securityContraints = pA.getSecurityConstraint();
74       List JavaDoc portlets = pA.getPortlet();
75       UserDataConstraint userDataConstraintType = null;
76       for (int i = 0; i < portlets.size(); i++) {
77         Portlet portlet = (Portlet) portlets.get(i);
78         for (Iterator JavaDoc iter = securityContraints.iterator(); iter.hasNext();) {
79           SecurityConstraint element = (SecurityConstraint) iter.next();
80           List JavaDoc portletsList = element.getPortletCollection().getPortletName();
81           for (Iterator JavaDoc iterator2 = portletsList.iterator(); iterator2.hasNext();) {
82             String JavaDoc name = (String JavaDoc) iterator2.next();
83             if (name.equals(portlet.getPortletName())) {
84               userDataConstraintType = element.getUserDataConstraint();
85               break;
86             }
87           }
88         }
89         all.put(key + Constants.PORTLET_META_DATA_ENCODER + portlet.getPortletName(),
90                 new PortletDataImp(portlet, userDataConstraintType, pA.getUserAttribute()));
91       }
92     }
93     return all;
94   }
95
96   public Collection JavaDoc getPortletModes(String JavaDoc portletAppName, String JavaDoc portletName, String JavaDoc markup) {
97     log.debug("getPortletModes() entered");
98     Collection JavaDoc modes = new ArrayList JavaDoc();
99     modes.add(PortletMode.VIEW);
100     List JavaDoc portlets = getPortletApplication(portletAppName).getPortlet();
101     for (Iterator JavaDoc iterator = portlets.iterator(); iterator.hasNext();) {
102       Portlet portlet = (Portlet) iterator.next();
103       if (portlet.getPortletName().equals(portletName)) {
104         List JavaDoc l = portlet.getSupports();
105         PortletMode tmpMode = null;
106         for (Iterator JavaDoc iterator2 = l.iterator(); iterator2.hasNext();) {
107           Supports supports = (Supports) iterator2.next();
108           String JavaDoc mimeType = supports.getMimeType();
109           if (mimeType.equals(markup)) {
110             List JavaDoc modesR = supports.getPortletMode();
111             for (Iterator JavaDoc iterator1 = modesR.iterator(); iterator1.hasNext();) {
112               String JavaDoc s = (String JavaDoc) iterator1.next();
113               modes.add(new PortletMode(s));
114             }
115           }
116         }
117       }
118     }
119     return modes;
120   }
121
122   public boolean isModeSuported(String JavaDoc portletAppName, String JavaDoc portletName,
123                                 String JavaDoc markup, PortletMode mode) {
124     log.debug("isModeSuported() entered");
125     if (PortletMode.VIEW == mode)
126       return true;
127     Collection JavaDoc modesSupported = getPortletModes(portletAppName, portletName, markup);
128     for (Iterator JavaDoc iterator = modesSupported.iterator(); iterator.hasNext();) {
129       PortletMode portletMode = (PortletMode) iterator.next();
130       if (portletMode.toString().equals(mode.toString()))
131         return true;
132     }
133     return false;
134   }
135
136   public Collection JavaDoc getWindowStates(String JavaDoc portletAppName) {
137     log.debug("getWindowStates() entered");
138     Collection JavaDoc states = new ArrayList JavaDoc();
139     states.add(WindowState.MINIMIZED);
140     states.add(WindowState.NORMAL);
141     states.add(WindowState.MAXIMIZED);
142     List JavaDoc customStates = getPortletApplication(portletAppName).getCustomWindowState();
143     for (Iterator JavaDoc iterator = customStates.iterator(); iterator.hasNext();) {
144       CustomWindowState customWindowState = (CustomWindowState) iterator.next();
145       WindowState state = new WindowState(customWindowState.getWindowState());
146       states.add(state);
147     }
148     return states;
149   }
150
151   public boolean isStateSupported(WindowState state, String JavaDoc portletApplication) {
152     log.debug("isStateSupported() entered");
153     Collection JavaDoc c = getWindowStates(portletApplication);
154     for (Iterator JavaDoc iterator = c.iterator(); iterator.hasNext();) {
155       WindowState windowState = (WindowState) iterator.next();
156       if (windowState.toString().equals(state.toString()))
157         return true;
158     }
159     return false;
160   }
161
162   public void registerPortletApplication(String JavaDoc portletAppName, PortletApp portletApp,
163                                          Collection JavaDoc roles) {
164     PortletApplicationHelper helper = new PortletApplicationHelper(portletAppName, portletApp, roles);
165     synchronized (portletApps) {
166       portletApps.put(portletAppName, helper);
167     }
168   }
169
170   public void removePortletApplication(String JavaDoc portletAppName) {
171     synchronized (portletApps) {
172       portletApps.remove(portletAppName);
173     }
174   }
175
176   public Portlet getPortletMetaData(String JavaDoc portletApplication, String JavaDoc portlet) {
177     log.debug("getPortletMetaData() entered");
178     PortletApp portletApp = getPortletApplication(portletApplication);
179     if(portletApp == null) return null;
180     List JavaDoc l = portletApp.getPortlet();
181     for (Iterator JavaDoc iterator = l.iterator(); iterator.hasNext();) {
182       Portlet portlet1 = (Portlet) iterator.next();
183       if (portlet1.getPortletName().equals(portlet))
184         return portlet1;
185     }
186     return null;
187   }
188
189
190  private class PortletApplicationHelper {
191     private PortletApp portletApp;
192     private Collection JavaDoc roles;
193     private String JavaDoc portletAppName;
194
195     public PortletApplicationHelper(String JavaDoc portletAppName,
196                                     PortletApp portletApp,
197                                     Collection JavaDoc roles) {
198       this.portletApp = portletApp;
199       this.roles = roles;
200       this.portletAppName = portletAppName;
201     }
202
203     public PortletApp getPortletApp() {
204       return portletApp;
205     }
206
207     public Collection JavaDoc getRoles() {
208       return roles;
209     }
210   }
211 }
212
Popular Tags