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.pluto.internal.impl;
018:
019: import org.apache.pluto.internal.InternalPortletConfig;
020: import org.apache.pluto.descriptors.common.InitParamDD;
021: import org.apache.pluto.descriptors.portlet.PortletDD;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import javax.portlet.PortletConfig;
026: import javax.portlet.PortletContext;
027: import javax.servlet.ServletConfig;
028: import java.util.*;
029:
030: public class PortletConfigImpl implements PortletConfig,
031: InternalPortletConfig {
032:
033: private static final Log LOG = LogFactory
034: .getLog(PortletConfigImpl.class);
035:
036: /**
037: * The servlet config for which we exist.
038: */
039: private ServletConfig servletConfig;
040:
041: /**
042: * The Portlet Application Context within which we exist.
043: */
044: private PortletContext portletContext;
045:
046: /**
047: * The portlet descriptor.
048: */
049: protected PortletDD portletDD;
050:
051: private ResourceBundleFactory bundles;
052:
053: public PortletConfigImpl(ServletConfig servletConfig,
054: PortletContext portletContext, PortletDD portletDD) {
055: this .servletConfig = servletConfig;
056: this .portletContext = portletContext;
057: this .portletDD = portletDD;
058: }
059:
060: public String getPortletName() {
061: return portletDD.getPortletName();
062: }
063:
064: public PortletContext getPortletContext() {
065: return portletContext;
066: }
067:
068: public ResourceBundle getResourceBundle(Locale locale) {
069: if (LOG.isDebugEnabled()) {
070: LOG.debug("Resource Bundle requested: " + locale);
071: }
072: if (bundles == null) {
073: bundles = new ResourceBundleFactory(portletDD);
074: }
075: return bundles.getResourceBundle(locale);
076: }
077:
078: public String getInitParameter(String name) {
079: if (name == null) {
080: throw new IllegalArgumentException("Parameter name == null");
081: }
082:
083: Iterator parms = portletDD.getInitParams().iterator();
084: while (parms.hasNext()) {
085: InitParamDD param = (InitParamDD) parms.next();
086: if (param.getParamName().equals(name)) {
087: return param.getParamValue();
088: }
089: }
090: return null;
091: }
092:
093: public Enumeration getInitParameterNames() {
094: return new java.util.Enumeration() {
095: private Iterator iterator = new ArrayList(portletDD
096: .getInitParams()).iterator();
097:
098: public boolean hasMoreElements() {
099: return iterator.hasNext();
100: }
101:
102: public Object nextElement() {
103: if (iterator.hasNext()) {
104: return ((InitParamDD) iterator.next())
105: .getParamName();
106: } else {
107: return null;
108: }
109: }
110: };
111: }
112:
113: public javax.servlet.ServletConfig getServletConfig() {
114: return servletConfig;
115: }
116:
117: public PortletDD getPortletDefinition() {
118: return portletDD;
119: }
120:
121: }
|