KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > core > impl > PortletConfigImpl


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17
18  */

19
20 package org.apache.pluto.core.impl;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25
26 import javax.portlet.PortletConfig;
27 import javax.portlet.PortletContext;
28
29 import org.apache.pluto.core.InternalPortletConfig;
30 import org.apache.pluto.om.common.Language;
31 import org.apache.pluto.om.common.LanguageSet;
32 import org.apache.pluto.om.common.Parameter;
33 import org.apache.pluto.om.portlet.PortletDefinition;
34
35 public class PortletConfigImpl implements PortletConfig, InternalPortletConfig
36 {
37     private javax.servlet.ServletConfig JavaDoc servletConfig;
38     private PortletContext portletContext;
39     private PortletDefinition portletDefinition;
40
41     public PortletConfigImpl(javax.servlet.ServletConfig JavaDoc servletConfig,
42                              PortletContext portletContext,
43                              PortletDefinition portletDefinition)
44     {
45         this.servletConfig = servletConfig;
46         this.portletContext = portletContext;
47         this.portletDefinition = portletDefinition;
48     }
49
50     // javax.portlet.PortletConfig implementation -------------------------------------------------
51
public String JavaDoc getPortletName()
52     {
53         return portletDefinition.getName();
54     }
55
56     public PortletContext getPortletContext()
57     {
58         return portletContext;
59     }
60
61     public ResourceBundle JavaDoc getResourceBundle(java.util.Locale JavaDoc locale)
62     {
63         LanguageSet languageSet = portletDefinition.getLanguageSet();
64         Language lang = languageSet.get(locale);
65
66         if (lang == null)
67         {
68             Locale JavaDoc defaultLocale = languageSet.getDefaultLocale();
69             lang = languageSet.get(defaultLocale);
70         }
71
72         return lang.getResourceBundle();
73     }
74
75     public String JavaDoc getInitParameter(String JavaDoc name)
76     {
77         Parameter parm = null;
78         if (name == null)
79         {
80             throw new IllegalArgumentException JavaDoc("Parameter name == null");
81         }
82         parm = portletDefinition.getInitParameterSet().get(name);
83         return (parm == null ? null : parm.getValue());
84     }
85
86     public java.util.Enumeration JavaDoc getInitParameterNames()
87     {
88         return new java.util.Enumeration JavaDoc()
89         {
90             private Iterator JavaDoc iterator = portletDefinition.getInitParameterSet().iterator();
91
92             public boolean hasMoreElements()
93             {
94                 return iterator.hasNext();
95             }
96
97             public Object JavaDoc nextElement()
98             {
99                 if (iterator.hasNext())
100                 {
101                     return((Parameter)iterator.next()).getName();
102                 }
103                 else
104                 {
105                     return null;
106                 }
107             }
108         };
109     }
110     // --------------------------------------------------------------------------------------------
111

112     // org.apache.pluto.core.InternalPortletConfig implementation ---------------------------------
113
public javax.servlet.ServletConfig JavaDoc getServletConfig()
114     {
115         return servletConfig;
116     }
117
118     public PortletDefinition getInternalPortletDefinition()
119     {
120         return portletDefinition;
121     }
122     // --------------------------------------------------------------------------------------------
123
}
124
Popular Tags