KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > portletAPIImp > PortletConfigImp


1 /*
2 Copyright 2001-2003 The eXo Platform SARL
3 All rights reserved
4 */

5
6 /**
7  * Created by The eXo Platform SARL
8  * Date: Jul 25, 2003
9  * Time: 6:11:15 PM
10  */

11 package org.exoplatform.services.portletcontainer.impl.portletAPIImp;
12
13 import java.util.Enumeration JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Locale JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.ResourceBundle JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import javax.portlet.PortletConfig;
23 import javax.portlet.PortletContext;
24 import org.exoplatform.container.PortalContainer;
25 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.bundle.ResourceBundleManager;
26 import org.exoplatform.services.portletcontainer.pci.model.*;
27
28
29
30 /**
31  * There is one object per portlet Lifetime.
32  * It can be pooled
33  */

34 public class PortletConfigImp implements PortletConfig {
35
36   private Portlet portletDatas_;
37   private Map JavaDoc params_ = new HashMap JavaDoc();
38   private PortletContext portletContext;
39   private List JavaDoc securityContraints;
40   private List JavaDoc userAttributes_;
41   private List JavaDoc customPortletModes_;
42   private List JavaDoc customWindowStates_;
43
44   public PortletConfigImp(Portlet portletDatas,
45                           PortletContext portletContext,
46                           List JavaDoc securityContraints,
47                           List JavaDoc userAttributes,
48                           List JavaDoc customPortletModes,
49                           List JavaDoc customWindowStates) {
50     this.portletDatas_ = portletDatas;
51     this.portletContext = portletContext;
52     this.securityContraints = securityContraints;
53     this.userAttributes_ = userAttributes;
54     this. customPortletModes_ = customPortletModes;
55     this.customWindowStates_ = customWindowStates;
56
57     //optimize the accesses to init paramters with Map
58
List JavaDoc l = portletDatas.getInitParam();
59     for (Iterator JavaDoc iterator = l.iterator(); iterator.hasNext();) {
60       InitParam initParam = (InitParam) iterator.next();
61       params_.put(initParam.getName(), initParam);
62     }
63   }
64
65   public String JavaDoc getPortletName() { return portletDatas_.getPortletName();}
66
67   public PortletContext getPortletContext() {
68     return portletContext;
69   }
70
71   public ResourceBundle JavaDoc getResourceBundle(Locale JavaDoc locale) {
72     ResourceBundleManager manager = (ResourceBundleManager)PortalContainer.getInstance().
73       getComponentInstanceOfType(ResourceBundleManager.class);
74     return manager.lookupBundle(portletDatas_ , locale);
75   }
76
77   public String JavaDoc getInitParameter(String JavaDoc name) {
78     if (name == null ) {
79       throw new IllegalArgumentException JavaDoc("You cannot have null as a paramter") ;
80     }
81     InitParam initParam = (InitParam) params_.get(name);
82     if (initParam != null) return initParam.getValue();
83     return null;
84   }
85
86   public Enumeration JavaDoc getInitParameterNames() {
87     return new Vector JavaDoc(params_.keySet()).elements();
88   }
89
90   public Portlet getPortletDatas() { return portletDatas_; }
91
92   public boolean needsSecurityContraints(String JavaDoc portletName) {
93     for (Iterator JavaDoc iterator = securityContraints.iterator(); iterator.hasNext();) {
94       SecurityConstraint securityConstraint = (SecurityConstraint) iterator.next();
95       List JavaDoc l = securityConstraint.getPortletCollection().getPortletName();
96       for (Iterator JavaDoc iterator2 = l.iterator(); iterator2.hasNext();) {
97         String JavaDoc portlet = (String JavaDoc) iterator2.next();
98         if(portlet.equals(portletName)) return true;
99       }
100     }
101     return false;
102   }
103 }
Popular Tags