View Javadoc

1   /*
2    * $Id: $
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  package org.apache.struts2.portlet.servlet;
22  
23  import java.util.Enumeration;
24  
25  import javax.portlet.PortletConfig;
26  import javax.portlet.PortletContext;
27  import javax.servlet.ServletConfig;
28  import javax.servlet.ServletContext;
29  
30  /***
31   * Wrapper object exposing a {@link PortletConfig} as a {@link ServletConfig} instance.
32   * Clients accessing this config object will in fact operate on the
33   * {@link PortletConfig} object wrapped by this config object.
34   */
35  public class PortletServletConfig implements ServletConfig {
36  
37  	private PortletConfig portletConfig;
38  	
39  	public PortletServletConfig(PortletConfig portletConfig) {
40  		this.portletConfig = portletConfig;
41  	}
42  	
43  	/* (non-Javadoc)
44  	 * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
45  	 */
46  	public String getInitParameter(String name) {
47  		return portletConfig.getInitParameter(name);
48  	}
49  
50  	/* (non-Javadoc)
51  	 * @see javax.servlet.ServletConfig#getInitParameterNames()
52  	 */
53  	public Enumeration getInitParameterNames() {
54  		return portletConfig.getInitParameterNames();
55  	}
56  
57  	/***
58  	 * Get the {@link PortletContext} as a {@link PortletServletContext} instance.
59  	 * @see javax.servlet.ServletConfig#getServletContext()
60  	 */
61  	public ServletContext getServletContext() {
62  		return new PortletServletContext(portletConfig.getPortletContext());
63  	}
64  
65  	/***
66  	 * Will return the portlet name.
67  	 * @see javax.servlet.ServletConfig#getServletName()
68  	 */
69  	public String getServletName() {
70  		return portletConfig.getPortletName();
71  	}
72  	
73  	/***
74  	 * Get the wrapped {@link PortletConfig} instance.
75  	 * @return The wrapped {@link PortletConfig} instance.
76  	 */
77  	public PortletConfig getPortletConfig() {
78  		return portletConfig;
79  	}
80  
81  }