View Javadoc

1   /*
2    * $Id: PortletServletConfig.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.portlet.servlet;
23  
24  import java.util.Enumeration;
25  
26  import javax.portlet.PortletConfig;
27  import javax.portlet.PortletContext;
28  import javax.servlet.ServletConfig;
29  import javax.servlet.ServletContext;
30  
31  /***
32   * Wrapper object exposing a {@link PortletConfig} as a {@link ServletConfig} instance.
33   * Clients accessing this config object will in fact operate on the
34   * {@link PortletConfig} object wrapped by this config object.
35   */
36  public class PortletServletConfig implements ServletConfig {
37  
38  	private PortletConfig portletConfig;
39  	
40  	public PortletServletConfig(PortletConfig portletConfig) {
41  		this.portletConfig = portletConfig;
42  	}
43  	
44  	/* (non-Javadoc)
45  	 * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
46  	 */
47  	public String getInitParameter(String name) {
48  		return portletConfig.getInitParameter(name);
49  	}
50  
51  	/* (non-Javadoc)
52  	 * @see javax.servlet.ServletConfig#getInitParameterNames()
53  	 */
54  	public Enumeration getInitParameterNames() {
55  		return portletConfig.getInitParameterNames();
56  	}
57  
58  	/***
59  	 * Get the {@link PortletContext} as a {@link PortletServletContext} instance.
60  	 * @see javax.servlet.ServletConfig#getServletContext()
61  	 */
62  	public ServletContext getServletContext() {
63  		return new PortletServletContext(portletConfig.getPortletContext());
64  	}
65  
66  	/***
67  	 * Will return the portlet name.
68  	 * @see javax.servlet.ServletConfig#getServletName()
69  	 */
70  	public String getServletName() {
71  		return portletConfig.getPortletName();
72  	}
73  	
74  	/***
75  	 * Get the wrapped {@link PortletConfig} instance.
76  	 * @return The wrapped {@link PortletConfig} instance.
77  	 */
78  	public PortletConfig getPortletConfig() {
79  		return portletConfig;
80  	}
81  
82  }