1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.apache.bridges.struts;
24  
25  import java.io.InputStream;
26  
27  import java.net.MalformedURLException;
28  import java.net.URL;
29  
30  import java.util.ArrayList;
31  import java.util.Collections;
32  import java.util.Enumeration;
33  import java.util.Set;
34  
35  import javax.servlet.RequestDispatcher;
36  import javax.servlet.Servlet;
37  import javax.servlet.ServletContext;
38  
39  /**
40   * <a href="LiferayServletContext.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Michael Young
43   */
44  public class LiferayServletContext implements ServletContext {
45  
46      public LiferayServletContext(ServletContext servletContext) {
47          _servletContext = servletContext;
48      }
49  
50      public Object getAttribute(String name) {
51          return _servletContext.getAttribute(name);
52      }
53  
54      public Enumeration<String> getAttributeNames() {
55          return _servletContext.getAttributeNames();
56      }
57  
58      public ServletContext getContext(String uriPath) {
59          ServletContext servletContext = _servletContext.getContext(uriPath);
60  
61          if (servletContext == _servletContext) {
62              return this;
63          }
64          else {
65              return servletContext;
66          }
67      }
68  
69      public String getInitParameter(String name) {
70          return _servletContext.getInitParameter(name);
71      }
72  
73      public Enumeration<String> getInitParameterNames() {
74          return _servletContext.getInitParameterNames();
75      }
76  
77      public int getMajorVersion() {
78          return _servletContext.getMajorVersion();
79      }
80  
81      public String getMimeType(String file) {
82          return _servletContext.getMimeType(file);
83      }
84  
85      public int getMinorVersion() {
86          return _servletContext.getMinorVersion();
87      }
88  
89      public RequestDispatcher getNamedDispatcher(String name) {
90          RequestDispatcher requestDispatcher =
91              _servletContext.getNamedDispatcher(name);
92  
93          if (requestDispatcher != null) {
94              requestDispatcher = new LiferayRequestDispatcher(
95                  requestDispatcher, name);
96          }
97  
98          return requestDispatcher;
99      }
100 
101     public String getRealPath(String path) {
102         return _servletContext.getRealPath(path);
103     }
104 
105     public RequestDispatcher getRequestDispatcher(String path) {
106         RequestDispatcher requestDispatcher =
107             _servletContext.getRequestDispatcher(path);
108 
109         if (requestDispatcher != null) {
110             requestDispatcher = new LiferayRequestDispatcher(
111                 requestDispatcher, path);
112         }
113 
114         return requestDispatcher;
115     }
116 
117     public URL getResource(String path) throws MalformedURLException {
118         return _servletContext.getResource(path);
119     }
120 
121     public InputStream getResourceAsStream(String path) {
122         return _servletContext.getResourceAsStream(path);
123     }
124 
125     public Set<String> getResourcePaths(String path) {
126         return _servletContext.getResourcePaths(path);
127     }
128 
129     public String getServerInfo() {
130         return _servletContext.getServerInfo();
131     }
132 
133     public Servlet getServlet(String name) {
134         return null;
135     }
136 
137     public String getServletContextName() {
138         return _servletContext.getServletContextName();
139     }
140 
141     public Enumeration<String> getServletNames() {
142         return Collections.enumeration(new ArrayList<String>());
143     }
144 
145     public Enumeration<Servlet> getServlets() {
146         return Collections.enumeration(new ArrayList<Servlet>());
147     }
148 
149     public void log(Exception exception, String message) {
150         _servletContext.log(message, exception);
151     }
152 
153     public void log(String message) {
154         _servletContext.log(message);
155     }
156 
157     public void log(String message, Throwable t) {
158         _servletContext.log(message, t);
159     }
160 
161     public void removeAttribute(String name) {
162         _servletContext.removeAttribute(name);
163     }
164 
165     public void setAttribute(String name, Object value) {
166         _servletContext.setAttribute(name, value);
167     }
168 
169     public String toString() {
170         return _servletContext.toString();
171     }
172 
173     private ServletContext _servletContext;
174 
175 }