1 package org.exoplatform.services.portletcontainer.impl; 2 3 import java.io.InputStream ; 4 import java.util.ArrayList ; 5 import java.util.Collection ; 6 import java.util.Collections ; 7 import java.util.Enumeration ; 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 import java.util.Locale ; 12 import java.util.Map ; 13 14 import javax.portlet.PortletMode; 15 import javax.portlet.WindowState; 16 17 import org.apache.commons.logging.Log; 18 import org.exoplatform.services.log.LogService; 19 import org.exoplatform.services.portletcontainer.impl.config.*; 20 import org.exoplatform.services.portletcontainer.impl.config.XMLParser; 21 import org.exoplatform.services.portletcontainer.pci.*; 22 import org.exoplatform.container.configuration.*; 23 27 28 35 public class PortletContainerConf { 36 37 private Map properties; 38 private String portletContainerName; 39 private int majorVersion = -1; 40 private int minorVersion = -1; 41 42 private Collection customModes; 43 private Collection customStates; 44 private Collection customModesWithDescriptions; 45 private Collection customStatesWithDescriptions; 46 private Collection supportedContents; 47 48 private boolean isCacheEnable; 49 private boolean isSharedSessionEnable; 50 private PortletContainer containerConfs; 51 52 private boolean isBundleLookupDelegated; 53 54 public PortletContainerConf(ConfigurationManager configurationService, LogService logService) { 55 try { 56 ServiceConfiguration conf = configurationService.getServiceConfiguration(PortletContainerConf.class); 57 ValueParam param = conf.getValueParam("conf-path"); 58 InputStream is = configurationService.getInputStream((String )param.getValue()); 59 containerConfs = XMLParser.parse(is) ; 60 init(); 61 } catch (Exception e) { 62 Log log = logService.getLog("org.exoplatform.services.portletcontainer"); 63 log.error(e); 64 } 65 } 66 67 private void init() { 68 String c = containerConfs.getCache().getEnable(); 69 if ("true".equals(c)) 70 isCacheEnable = true; 71 72 SharedSession sharedSession = containerConfs.getSharedSession(); 73 if (sharedSession != null) { 74 c = sharedSession.getEnable(); 75 if ("true".equals(c)) 76 isSharedSessionEnable = true; 77 } 78 79 c = containerConfs.getDelegatedBundle().getEnable(); 80 if ("true".equals(c)) isBundleLookupDelegated = true; 81 } 82 83 84 85 public int getNbOfInstancesInPool() { 86 return containerConfs.getObjectPool().getInstancesInPool(); 87 } 88 89 public Map getProperties() { 90 if (properties == null) { 91 Map map = new HashMap (); 92 List l = containerConfs.getProperties(); 93 for (Iterator iterator = l.iterator(); iterator.hasNext();) { 94 Properties props = (Properties) iterator.next(); 95 map.put(props.getName(), props.getValue()); 96 } 97 properties = map; 98 } 99 return properties; 100 } 101 102 public void setProperties(Map properties) { 103 this.properties = properties; 104 } 105 106 public String getPortletContainerName() { 107 if(portletContainerName == null){ 108 portletContainerName = containerConfs.getGlobal().getName(); 109 } 110 return portletContainerName; 111 } 112 113 public void setPortletContainerName(String name){ 114 this.portletContainerName = name; 115 } 116 117 public int getMajorVersion() { 118 if(majorVersion < 0){ 119 majorVersion = containerConfs.getGlobal().getMajorVersion(); 120 } 121 return majorVersion; 122 } 123 124 public void setMajorVersion(int version){ 125 majorVersion = version; 126 } 127 128 public int getMinorVersion() { 129 if(minorVersion < 0){ 130 minorVersion = containerConfs.getGlobal().getMinorVersion(); 131 } 132 return minorVersion; 133 } 134 135 public void setMinorVersion(int version){ 136 minorVersion = version; 137 } 138 139 public Collection getSupportedContent() { 140 if (supportedContents == null) { 141 supportedContents = new ArrayList (); 142 List content = containerConfs.getSupportedContent(); 143 for (Iterator iter = content.iterator(); iter.hasNext();) { 144 SupportedContent element = (SupportedContent) iter.next(); 145 supportedContents.add(element.getName()); 146 } 147 } 148 return supportedContents; 149 } 150 151 public Enumeration getSupportedPortletModes() { 152 if (customModes == null) { 153 Collection v = new ArrayList (); 154 v.add(PortletMode.EDIT); 155 v.add(PortletMode.HELP); 156 v.add(PortletMode.VIEW); 157 List l = containerConfs.getCustomMode(); 158 for (Iterator iterator = l.iterator(); iterator.hasNext();) { 159 CustomMode customMode = (CustomMode) iterator.next(); 160 v.add(new PortletMode(customMode.getName())); 161 } 162 customModes = v; 163 } 164 return Collections.enumeration(customModes); 165 } 166 167 public Enumeration getSupportedWindowStates() { 168 if (customStates == null) { 169 Collection v = new ArrayList (); 170 v.add(WindowState.NORMAL); 171 v.add(WindowState.MINIMIZED); 172 v.add(WindowState.MAXIMIZED); 173 List l = containerConfs.getCustomWindowState(); 174 for (Iterator iterator = l.iterator(); iterator.hasNext();) { 175 CustomWindowState customState = (CustomWindowState) iterator.next(); 176 v.add(new WindowState(customState.getName())); 177 } 178 customStates = v; 179 } 180 return Collections.enumeration(customStates); 181 } 182 183 public Collection getSupportedPortletModesWithDescriptions() { 184 if (customModesWithDescriptions == null) { 185 Collection v = new ArrayList (); 186 List l = containerConfs.getCustomMode(); 187 for (Iterator iterator = l.iterator(); iterator.hasNext();) { 188 CustomMode customMode = (CustomMode) iterator.next(); 189 List l2 = customMode.getDescription(); 190 List toBeReturned = new ArrayList (); 191 for (Iterator iter = l2.iterator(); iter.hasNext();) { 192 Description element = (Description) iter.next(); 193 LocalisedDescription d = 194 new LocalisedDescription(new Locale (element.getLang()), element.getDescription()); 195 toBeReturned.add(d); 196 } 197 CustomModeWithDescription cMWD = 198 new CustomModeWithDescription(new PortletMode(customMode.getName()),toBeReturned); 199 200 v.add(cMWD); 201 } 202 customModesWithDescriptions = v; 203 } 204 return customModesWithDescriptions; 205 } 206 207 public Collection getSupportedWindowStatesWithDescriptions() { 208 if (customStatesWithDescriptions == null) { 209 Collection v = new ArrayList (); 210 List l = containerConfs.getCustomWindowState(); 211 for (Iterator iterator = l.iterator(); iterator.hasNext();) { 212 CustomWindowState customState = (CustomWindowState) iterator.next(); 213 List l2 = customState.getDescription(); 214 List toBeReturned = new ArrayList (); 215 for (Iterator iter = l2.iterator(); iter.hasNext();) { 216 Description element = (Description) iter.next(); 217 LocalisedDescription d = 218 new LocalisedDescription(new Locale (element.getLang()), element.getDescription()); 219 toBeReturned.add(d); 220 } 221 CustomWindowStateWithDescription cMWD = 222 new CustomWindowStateWithDescription(new WindowState(customState.getName()), toBeReturned); 223 v.add(cMWD); 224 } 225 customStatesWithDescriptions = v; 226 } 227 return customStatesWithDescriptions; 228 } 229 230 public synchronized void setCustomModesWithDescriptions(Collection customModesWithDescriptions) { 231 this.customModesWithDescriptions = customModesWithDescriptions; 232 Collection temp = new ArrayList (); 233 for (Iterator iter = customModesWithDescriptions.iterator(); iter.hasNext();) { 234 CustomModeWithDescription element = (CustomModeWithDescription) iter.next(); 235 temp.add(element.getPortletMode()); 236 } 237 this.customModes = temp; 238 } 239 240 public synchronized void setCustomStatesWithDescriptions(Collection customStatesWithDescriptions) { 241 this.customStatesWithDescriptions = customStatesWithDescriptions; 242 Collection temp = new ArrayList (); 243 for (Iterator iter = customStatesWithDescriptions.iterator(); iter.hasNext();) { 244 CustomWindowStateWithDescription element = (CustomWindowStateWithDescription) iter.next(); 245 temp.add(element.getWindowState()); 246 } 247 this.customStates = temp; 248 } 249 250 public boolean isModeSupported(PortletMode mode) { 251 Enumeration e = getSupportedPortletModes(); 252 while (e.hasMoreElements()) { 253 PortletMode portletMode = (PortletMode) e.nextElement(); 254 if (portletMode.toString().equals(mode.toString())) 255 return true; 256 } 257 return false; 258 } 259 260 public boolean isStateSupported(WindowState state) { 261 Enumeration e = getSupportedWindowStates(); 262 while (e.hasMoreElements()) { 263 WindowState windowState = (WindowState) e.nextElement(); 264 if (windowState.toString().equals(state.toString())) 265 return true; 266 } 267 return false; 268 269 } 270 271 public boolean isCacheEnable() { 272 return isCacheEnable; 273 } 274 275 public boolean isSharedSessionEnable() { 276 return isSharedSessionEnable; 277 } 278 279 public boolean isBundleLookupDelegated() { 280 return isBundleLookupDelegated; 281 } 282 } | Popular Tags |