1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container;
18
19 import java.util.Enumeration;
20 import java.util.Iterator;
21 import java.util.Locale;
22 import java.util.ResourceBundle;
23
24 import javax.portlet.PortletConfig;
25 import javax.portlet.PortletContext;
26
27 import org.apache.pluto.om.common.Language;
28 import org.apache.pluto.om.common.LanguageSet;
29 import org.apache.pluto.om.common.Parameter;
30 import org.apache.pluto.om.common.ParameterSet;
31 import org.apache.pluto.om.portlet.PortletDefinition;
32
33 /***
34 * Implements the Portlet API Portlet Config class
35 *
36 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
37 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
38 * @version $Id: JetspeedPortletConfig.java 516448 2007-03-09 16:25:47Z ate $
39 */
40 public class JetspeedPortletConfig implements PortletConfig, InternalPortletConfig
41 {
42
43
44 private PortletContext portletContext;
45 private PortletDefinition portletDefinition;
46
47 public JetspeedPortletConfig(PortletContext portletContext, PortletDefinition portletEntity)
48 {
49 this.portletContext = portletContext;
50 this.portletDefinition = portletEntity;
51 }
52
53 public String getPortletName()
54 {
55 return portletDefinition.getName();
56 }
57
58 public PortletContext getPortletContext()
59 {
60 return portletContext;
61 }
62
63 public ResourceBundle getResourceBundle(Locale locale)
64 {
65 LanguageSet languageSet = portletDefinition.getLanguageSet();
66
67 Language lang = languageSet.get(locale);
68
69 if (lang == null)
70 {
71 Locale defaultLocale = languageSet.getDefaultLocale();
72 lang = languageSet.get(defaultLocale);
73 }
74
75 return lang.getResourceBundle();
76 }
77
78 public String getInitParameter(java.lang.String name)
79 {
80 if ( name == null )
81 {
82 throw new IllegalArgumentException("Required parameter name is null");
83 }
84
85 ParameterSet parameters = portletDefinition.getInitParameterSet();
86 Parameter param = parameters.get(name);
87
88 if (param != null)
89 {
90
91 return param.getValue();
92 }
93
94 return null;
95 }
96
97 public Enumeration getInitParameterNames()
98 {
99 return new java.util.Enumeration()
100 {
101 private ParameterSet parameters = portletDefinition.getInitParameterSet();
102 private Iterator iterator = parameters.iterator();
103
104 public boolean hasMoreElements()
105 {
106 return iterator.hasNext();
107 }
108
109 public Object nextElement()
110 {
111 if (iterator.hasNext())
112 return ((Parameter) iterator.next()).getName();
113 else
114 return null;
115 }
116 };
117
118 }
119
120 public void setPortletDefinition(PortletDefinition pd)
121 {
122 this.portletDefinition = pd;
123 }
124
125
126 public PortletDefinition getPortletDefinition()
127 {
128 return portletDefinition;
129 }
130
131 }