1 package org.exoplatform.services.portletcontainer.impl; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import java.util.Map ; 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 23 24 31 public class PortletApplicationsHolder { 32 33 private Map portletApps; 34 private Log log; 35 36 public PortletApplicationsHolder(LogService logService) { 37 this.portletApps = new HashMap (); 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 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 getRoles(String portletAppName) { 59 log.debug("getRoles() entered"); 60 PortletApplicationHelper helper = (PortletApplicationHelper) portletApps.get(portletAppName); 61 return helper.getRoles(); 62 } 63 64 public Map getAllPortletMetaData() { 65 log.debug("getAllPortletMetaData() entered"); 66 HashMap all = new HashMap (20); 67 Collection applicationsKeys = portletApps.keySet(); 68 Iterator iterator = applicationsKeys.iterator(); 69 while (iterator.hasNext()) { 70 String key = (String ) iterator.next(); 71 PortletApplicationHelper helper = (PortletApplicationHelper) portletApps.get(key); 72 PortletApp pA = helper.getPortletApp(); 73 List securityContraints = pA.getSecurityConstraint(); 74 List 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 iter = securityContraints.iterator(); iter.hasNext();) { 79 SecurityConstraint element = (SecurityConstraint) iter.next(); 80 List portletsList = element.getPortletCollection().getPortletName(); 81 for (Iterator iterator2 = portletsList.iterator(); iterator2.hasNext();) { 82 String name = (String ) 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 getPortletModes(String portletAppName, String portletName, String markup) { 97 log.debug("getPortletModes() entered"); 98 Collection modes = new ArrayList (); 99 modes.add(PortletMode.VIEW); 100 List portlets = getPortletApplication(portletAppName).getPortlet(); 101 for (Iterator iterator = portlets.iterator(); iterator.hasNext();) { 102 Portlet portlet = (Portlet) iterator.next(); 103 if (portlet.getPortletName().equals(portletName)) { 104 List l = portlet.getSupports(); 105 PortletMode tmpMode = null; 106 for (Iterator iterator2 = l.iterator(); iterator2.hasNext();) { 107 Supports supports = (Supports) iterator2.next(); 108 String mimeType = supports.getMimeType(); 109 if (mimeType.equals(markup)) { 110 List modesR = supports.getPortletMode(); 111 for (Iterator iterator1 = modesR.iterator(); iterator1.hasNext();) { 112 String s = (String ) iterator1.next(); 113 modes.add(new PortletMode(s)); 114 } 115 } 116 } 117 } 118 } 119 return modes; 120 } 121 122 public boolean isModeSuported(String portletAppName, String portletName, 123 String markup, PortletMode mode) { 124 log.debug("isModeSuported() entered"); 125 if (PortletMode.VIEW == mode) 126 return true; 127 Collection modesSupported = getPortletModes(portletAppName, portletName, markup); 128 for (Iterator 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 getWindowStates(String portletAppName) { 137 log.debug("getWindowStates() entered"); 138 Collection states = new ArrayList (); 139 states.add(WindowState.MINIMIZED); 140 states.add(WindowState.NORMAL); 141 states.add(WindowState.MAXIMIZED); 142 List customStates = getPortletApplication(portletAppName).getCustomWindowState(); 143 for (Iterator 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 portletApplication) { 152 log.debug("isStateSupported() entered"); 153 Collection c = getWindowStates(portletApplication); 154 for (Iterator 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 portletAppName, PortletApp portletApp, 163 Collection 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 portletAppName) { 171 synchronized (portletApps) { 172 portletApps.remove(portletAppName); 173 } 174 } 175 176 public Portlet getPortletMetaData(String portletApplication, String portlet) { 177 log.debug("getPortletMetaData() entered"); 178 PortletApp portletApp = getPortletApplication(portletApplication); 179 if(portletApp == null) return null; 180 List l = portletApp.getPortlet(); 181 for (Iterator 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 roles; 193 private String portletAppName; 194 195 public PortletApplicationHelper(String portletAppName, 196 PortletApp portletApp, 197 Collection 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 getRoles() { 208 return roles; 209 } 210 } 211 } 212 | Popular Tags |