1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
45  public class LiferayServletContext implements ServletContext {
46  
47      public LiferayServletContext(ServletContext servletContext) {
48          _servletContext = servletContext;
49      }
50  
51      public Object getAttribute(String name) {
52          return _servletContext.getAttribute(name);
53      }
54  
55      public Enumeration<String> getAttributeNames() {
56          return _servletContext.getAttributeNames();
57      }
58  
59      public ServletContext getContext(String uriPath) {
60          ServletContext servletContext = _servletContext.getContext(uriPath);
61  
62          if (servletContext == _servletContext) {
63              return this;
64          }
65          else {
66              return servletContext;
67          }
68      }
69  
70      public String getInitParameter(String name) {
71          return _servletContext.getInitParameter(name);
72      }
73  
74      public Enumeration<String> getInitParameterNames() {
75          return _servletContext.getInitParameterNames();
76      }
77  
78      public int getMajorVersion() {
79          return _servletContext.getMajorVersion();
80      }
81  
82      public String getMimeType(String file) {
83          return _servletContext.getMimeType(file);
84      }
85  
86      public int getMinorVersion() {
87          return _servletContext.getMinorVersion();
88      }
89  
90      public RequestDispatcher getNamedDispatcher(String name) {
91          RequestDispatcher requestDispatcher =
92              _servletContext.getNamedDispatcher(name);
93  
94          if (requestDispatcher != null) {
95              requestDispatcher = new LiferayRequestDispatcher(
96                  requestDispatcher, name);
97          }
98  
99          return requestDispatcher;
100     }
101 
102     public String getRealPath(String path) {
103         return _servletContext.getRealPath(path);
104     }
105 
106     public RequestDispatcher getRequestDispatcher(String path) {
107         RequestDispatcher requestDispatcher =
108             _servletContext.getRequestDispatcher(path);
109 
110         if (requestDispatcher != null) {
111             requestDispatcher = new LiferayRequestDispatcher(
112                 requestDispatcher, path);
113         }
114 
115         return requestDispatcher;
116     }
117 
118     public URL getResource(String path) throws MalformedURLException {
119         return _servletContext.getResource(path);
120     }
121 
122     public InputStream getResourceAsStream(String path) {
123         return _servletContext.getResourceAsStream(path);
124     }
125 
126     public Set<String> getResourcePaths(String path) {
127         return _servletContext.getResourcePaths(path);
128     }
129 
130     public String getServerInfo() {
131         return _servletContext.getServerInfo();
132     }
133 
134     public Servlet getServlet(String name) {
135         return null;
136     }
137 
138     public String getServletContextName() {
139         return _servletContext.getServletContextName();
140     }
141 
142     public Enumeration<String> getServletNames() {
143         return Collections.enumeration(new ArrayList<String>());
144     }
145 
146     public Enumeration<Servlet> getServlets() {
147         return Collections.enumeration(new ArrayList<Servlet>());
148     }
149 
150     public void log(Exception exception, String message) {
151         _servletContext.log(message, exception);
152     }
153 
154     public void log(String message) {
155         _servletContext.log(message);
156     }
157 
158     public void log(String message, Throwable t) {
159         _servletContext.log(message, t);
160     }
161 
162     public void removeAttribute(String name) {
163         _servletContext.removeAttribute(name);
164     }
165 
166     public void setAttribute(String name, Object value) {
167         _servletContext.setAttribute(name, value);
168     }
169 
170     public String toString() {
171         return _servletContext.toString();
172     }
173 
174     private ServletContext _servletContext;
175 
176 }