KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.services.portletcontainer.impl;
2
3 import java.io.InputStream JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Collection JavaDoc;
6 import java.util.Collections JavaDoc;
7 import java.util.Enumeration JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11 import java.util.Locale JavaDoc;
12 import java.util.Map JavaDoc;
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 /**
24  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
25  * Please look at license.txt in info directory for more license detail.
26  **/

27
28 /**
29  * Created by the Exo Development team.
30  * Author : Mestrallet Benjamin
31  * benjmestrallet@users.sourceforge.net
32  * Date: 10 nov. 2003
33  * Time: 11:38:24
34  */

35 public class PortletContainerConf {
36
37   private Map JavaDoc properties;
38   private String JavaDoc portletContainerName;
39   private int majorVersion = -1;
40   private int minorVersion = -1;
41
42   private Collection JavaDoc customModes;
43   private Collection JavaDoc customStates;
44   private Collection JavaDoc customModesWithDescriptions;
45   private Collection JavaDoc customStatesWithDescriptions;
46   private Collection JavaDoc 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 JavaDoc is = configurationService.getInputStream((String JavaDoc)param.getValue());
59       containerConfs = XMLParser.parse(is) ;
60       init();
61     } catch (Exception JavaDoc e) {
62       Log log = logService.getLog("org.exoplatform.services.portletcontainer");
63       log.error(e);
64     }
65   }
66
67   private void init() {
68     String JavaDoc 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 JavaDoc getProperties() {
90     if (properties == null) {
91       Map JavaDoc map = new HashMap JavaDoc();
92       List JavaDoc l = containerConfs.getProperties();
93       for (Iterator JavaDoc 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 JavaDoc properties) {
103     this.properties = properties;
104   }
105
106   public String JavaDoc getPortletContainerName() {
107     if(portletContainerName == null){
108       portletContainerName = containerConfs.getGlobal().getName();
109     }
110     return portletContainerName;
111   }
112
113   public void setPortletContainerName(String JavaDoc 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 JavaDoc getSupportedContent() {
140     if (supportedContents == null) {
141       supportedContents = new ArrayList JavaDoc();
142       List JavaDoc content = containerConfs.getSupportedContent();
143       for (Iterator JavaDoc 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 JavaDoc getSupportedPortletModes() {
152     if (customModes == null) {
153       Collection JavaDoc v = new ArrayList JavaDoc();
154       v.add(PortletMode.EDIT);
155       v.add(PortletMode.HELP);
156       v.add(PortletMode.VIEW);
157       List JavaDoc l = containerConfs.getCustomMode();
158       for (Iterator JavaDoc 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 JavaDoc getSupportedWindowStates() {
168     if (customStates == null) {
169       Collection JavaDoc v = new ArrayList JavaDoc();
170       v.add(WindowState.NORMAL);
171       v.add(WindowState.MINIMIZED);
172       v.add(WindowState.MAXIMIZED);
173       List JavaDoc l = containerConfs.getCustomWindowState();
174       for (Iterator JavaDoc 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 JavaDoc getSupportedPortletModesWithDescriptions() {
184     if (customModesWithDescriptions == null) {
185       Collection JavaDoc v = new ArrayList JavaDoc();
186       List JavaDoc l = containerConfs.getCustomMode();
187       for (Iterator JavaDoc iterator = l.iterator(); iterator.hasNext();) {
188         CustomMode customMode = (CustomMode) iterator.next();
189         List JavaDoc l2 = customMode.getDescription();
190         List JavaDoc toBeReturned = new ArrayList JavaDoc();
191         for (Iterator JavaDoc iter = l2.iterator(); iter.hasNext();) {
192           Description element = (Description) iter.next();
193           LocalisedDescription d =
194             new LocalisedDescription(new Locale JavaDoc(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 JavaDoc getSupportedWindowStatesWithDescriptions() {
208     if (customStatesWithDescriptions == null) {
209       Collection JavaDoc v = new ArrayList JavaDoc();
210       List JavaDoc l = containerConfs.getCustomWindowState();
211       for (Iterator JavaDoc iterator = l.iterator(); iterator.hasNext();) {
212         CustomWindowState customState = (CustomWindowState) iterator.next();
213         List JavaDoc l2 = customState.getDescription();
214         List JavaDoc toBeReturned = new ArrayList JavaDoc();
215         for (Iterator JavaDoc iter = l2.iterator(); iter.hasNext();) {
216           Description element = (Description) iter.next();
217           LocalisedDescription d =
218             new LocalisedDescription(new Locale JavaDoc(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 JavaDoc customModesWithDescriptions) {
231     this.customModesWithDescriptions = customModesWithDescriptions;
232     Collection JavaDoc temp = new ArrayList JavaDoc();
233     for (Iterator JavaDoc 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 JavaDoc customStatesWithDescriptions) {
241     this.customStatesWithDescriptions = customStatesWithDescriptions;
242     Collection JavaDoc temp = new ArrayList JavaDoc();
243     for (Iterator JavaDoc 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 JavaDoc 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 JavaDoc 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