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