1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 getInitParameter(String name) {
62          return _servletContext.getInitParameter(name);
63      }
64  
65      public Enumeration<String> getInitParameterNames() {
66          return _servletContext.getInitParameterNames();
67      }
68  
69      public int getMajorVersion() {
70          return _servletContext.getMajorVersion();
71      }
72  
73      public String getMimeType(String file) {
74          return _servletContext.getMimeType(file);
75      }
76  
77      public int getMinorVersion() {
78          return _servletContext.getMinorVersion();
79      }
80  
81      public RequestDispatcher getNamedDispatcher(String name) {
82          RequestDispatcher requestDispatcher =
83              _servletContext.getNamedDispatcher(name);
84  
85          if (requestDispatcher != null) {
86              requestDispatcher = new LiferayRequestDispatcher(
87                  requestDispatcher, name);
88          }
89  
90          return requestDispatcher;
91      }
92  
93      public String getRealPath(String path) {
94          return _servletContext.getRealPath(path);
95      }
96  
97      public RequestDispatcher getRequestDispatcher(String path) {
98          RequestDispatcher requestDispatcher =
99              _servletContext.getRequestDispatcher(path);
100 
101         if (requestDispatcher != null) {
102             requestDispatcher = new LiferayRequestDispatcher(
103                 requestDispatcher, path);
104         }
105 
106         return requestDispatcher;
107     }
108 
109     public URL getResource(String path) throws MalformedURLException {
110         return _servletContext.getResource(path);
111     }
112 
113     public InputStream getResourceAsStream(String path) {
114         return _servletContext.getResourceAsStream(path);
115     }
116 
117     public Set<String> getResourcePaths(String path) {
118         return _servletContext.getResourcePaths(path);
119     }
120 
121     public String getServerInfo() {
122         return _servletContext.getServerInfo();
123     }
124 
125     public Servlet getServlet(String name) {
126         return null;
127     }
128 
129     public String getServletContextName() {
130         return _servletContext.getServletContextName();
131     }
132 
133     public Enumeration<String> getServletNames() {
134         return Collections.enumeration(new ArrayList<String>());
135     }
136 
137     public Enumeration<Servlet> getServlets() {
138         return Collections.enumeration(new ArrayList<Servlet>());
139     }
140 
141     public void log(Exception exception, String message) {
142         _servletContext.log(message, exception);
143     }
144 
145     public void log(String message) {
146         _servletContext.log(message);
147     }
148 
149     public void log(String message, Throwable t) {
150         _servletContext.log(message, t);
151     }
152 
153     public void removeAttribute(String name) {
154         _servletContext.removeAttribute(name);
155     }
156 
157     public void setAttribute(String name, Object value) {
158         _servletContext.setAttribute(name, value);
159     }
160 
161     public String toString() {
162         return _servletContext.toString();
163     }
164 
165     private ServletContext _servletContext;
166 
167 }