1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.apache.bridges.struts;
16  
17  import java.io.InputStream;
18  
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.Enumeration;
25  import java.util.Set;
26  
27  import javax.servlet.RequestDispatcher;
28  import javax.servlet.Servlet;
29  import javax.servlet.ServletContext;
30  
31  /**
32   * <a href="LiferayServletContext.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Michael Young
35   */
36  public class LiferayServletContext implements ServletContext {
37  
38      public LiferayServletContext(ServletContext servletContext) {
39          _servletContext = servletContext;
40      }
41  
42      public Object getAttribute(String name) {
43          return _servletContext.getAttribute(name);
44      }
45  
46      public Enumeration<String> getAttributeNames() {
47          return _servletContext.getAttributeNames();
48      }
49  
50      public ServletContext getContext(String uriPath) {
51          ServletContext servletContext = _servletContext.getContext(uriPath);
52  
53          if (servletContext == _servletContext) {
54              return this;
55          }
56          else {
57              return servletContext;
58          }
59      }
60  
61      public String getContextPath() {
62          return _servletContext.getContextPath();
63      }
64  
65      public String getInitParameter(String name) {
66          return _servletContext.getInitParameter(name);
67      }
68  
69      public Enumeration<String> getInitParameterNames() {
70          return _servletContext.getInitParameterNames();
71      }
72  
73      public int getMajorVersion() {
74          return _servletContext.getMajorVersion();
75      }
76  
77      public String getMimeType(String file) {
78          return _servletContext.getMimeType(file);
79      }
80  
81      public int getMinorVersion() {
82          return _servletContext.getMinorVersion();
83      }
84  
85      public RequestDispatcher getNamedDispatcher(String name) {
86          RequestDispatcher requestDispatcher =
87              _servletContext.getNamedDispatcher(name);
88  
89          if (requestDispatcher != null) {
90              requestDispatcher = new LiferayRequestDispatcher(
91                  requestDispatcher, name);
92          }
93  
94          return requestDispatcher;
95      }
96  
97      public String getRealPath(String path) {
98          return _servletContext.getRealPath(path);
99      }
100 
101     public RequestDispatcher getRequestDispatcher(String path) {
102         RequestDispatcher requestDispatcher =
103             _servletContext.getRequestDispatcher(path);
104 
105         if (requestDispatcher != null) {
106             requestDispatcher = new LiferayRequestDispatcher(
107                 requestDispatcher, path);
108         }
109 
110         return requestDispatcher;
111     }
112 
113     public URL getResource(String path) throws MalformedURLException {
114         return _servletContext.getResource(path);
115     }
116 
117     public InputStream getResourceAsStream(String path) {
118         return _servletContext.getResourceAsStream(path);
119     }
120 
121     public Set<String> getResourcePaths(String path) {
122         return _servletContext.getResourcePaths(path);
123     }
124 
125     public String getServerInfo() {
126         return _servletContext.getServerInfo();
127     }
128 
129     public Servlet getServlet(String name) {
130         return null;
131     }
132 
133     public String getServletContextName() {
134         return _servletContext.getServletContextName();
135     }
136 
137     public Enumeration<String> getServletNames() {
138         return Collections.enumeration(new ArrayList<String>());
139     }
140 
141     public Enumeration<Servlet> getServlets() {
142         return Collections.enumeration(new ArrayList<Servlet>());
143     }
144 
145     public void log(Exception exception, String message) {
146         _servletContext.log(message, exception);
147     }
148 
149     public void log(String message) {
150         _servletContext.log(message);
151     }
152 
153     public void log(String message, Throwable t) {
154         _servletContext.log(message, t);
155     }
156 
157     public void removeAttribute(String name) {
158         _servletContext.removeAttribute(name);
159     }
160 
161     public void setAttribute(String name, Object value) {
162         _servletContext.setAttribute(name, value);
163     }
164 
165     public String toString() {
166         return _servletContext.toString();
167     }
168 
169     private ServletContext _servletContext;
170 
171 }