001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container;
018:
019: import java.util.Enumeration;
020: import java.util.Iterator;
021: import java.util.Locale;
022: import java.util.ResourceBundle;
023:
024: import javax.portlet.PortletConfig;
025: import javax.portlet.PortletContext;
026:
027: import org.apache.pluto.om.common.Language;
028: import org.apache.pluto.om.common.LanguageSet;
029: import org.apache.pluto.om.common.Parameter;
030: import org.apache.pluto.om.common.ParameterSet;
031: import org.apache.pluto.om.portlet.PortletDefinition;
032:
033: /**
034: * Implements the Portlet API Portlet Config class
035: *
036: * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
037: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
038: * @version $Id: JetspeedPortletConfig.java 516448 2007-03-09 16:25:47Z ate $
039: */
040: public class JetspeedPortletConfig implements PortletConfig,
041: InternalPortletConfig {
042: // private static final Log log = LogFactory.getLog(JetspeedPortletConfig.class);
043:
044: private PortletContext portletContext;
045: private PortletDefinition portletDefinition;
046:
047: public JetspeedPortletConfig(PortletContext portletContext,
048: PortletDefinition portletEntity) {
049: this .portletContext = portletContext;
050: this .portletDefinition = portletEntity;
051: }
052:
053: public String getPortletName() {
054: return portletDefinition.getName();
055: }
056:
057: public PortletContext getPortletContext() {
058: return portletContext;
059: }
060:
061: public ResourceBundle getResourceBundle(Locale locale) {
062: LanguageSet languageSet = portletDefinition.getLanguageSet();
063:
064: Language lang = languageSet.get(locale);
065:
066: if (lang == null) {
067: Locale defaultLocale = languageSet.getDefaultLocale();
068: lang = languageSet.get(defaultLocale);
069: }
070:
071: return lang.getResourceBundle();
072: }
073:
074: public String getInitParameter(java.lang.String name) {
075: if (name == null) {
076: throw new IllegalArgumentException(
077: "Required parameter name is null");
078: }
079: //if (log.isDebugEnabled()) log.debug("Getting init parameter for: " + name);
080: ParameterSet parameters = portletDefinition
081: .getInitParameterSet();
082: Parameter param = parameters.get(name);
083:
084: if (param != null) {
085: // if (log.isDebugEnabled()) log.debug("Param: [[name," + name + "], [value, " + param.getValue() + "]]");
086: return param.getValue();
087: }
088:
089: return null;
090: }
091:
092: public Enumeration getInitParameterNames() {
093: return new java.util.Enumeration() {
094: private ParameterSet parameters = portletDefinition
095: .getInitParameterSet();
096: private Iterator iterator = parameters.iterator();
097:
098: public boolean hasMoreElements() {
099: return iterator.hasNext();
100: }
101:
102: public Object nextElement() {
103: if (iterator.hasNext())
104: return ((Parameter) iterator.next()).getName();
105: else
106: return null;
107: }
108: };
109:
110: }
111:
112: public void setPortletDefinition(PortletDefinition pd) {
113: this .portletDefinition = pd;
114: }
115:
116: // internal portlet config implementation
117: public PortletDefinition getPortletDefinition() {
118: return portletDefinition;
119: }
120:
121: }
|